Class ValidatedResult<T>

  • Type Parameters:
    T - The type being created.

    public final class ValidatedResult<T>
    extends java.lang.Object
    Represents the result of an operation and the ValidationEvents that occurred.
    • Constructor Detail

      • ValidatedResult

        public ValidatedResult​(T result,
                               java.util.List<ValidationEvent> events)
        Creates a result with a value and events.
        Parameters:
        result - Value to set.
        events - Events to set.
      • ValidatedResult

        @Deprecated
        public ValidatedResult​(T result,
                               java.util.Collection<ValidationEvent> events)
        Deprecated.
    • Method Detail

      • fromErrors

        public static <T> ValidatedResult<T> fromErrors​(java.util.List<ValidationEvent> events)
        Creates a new ValidatedResult with no values and a list of ValidationEvents.
        Type Parameters:
        T - The type of value in the result.
        Parameters:
        events - Validation events on the result.
        Returns:
        Returns the created ValidatedResult.
      • fromValue

        public static <T> ValidatedResult<T> fromValue​(T value)
        Creates a new ValidatedResult with a value and no ValidationEvents.
        Type Parameters:
        T - The type of value in the result.
        Parameters:
        value - Result value,
        Returns:
        Returns the created ValidatedResult.
      • empty

        public static <T> ValidatedResult<T> empty()
        Creates an empty ValidatedResult with no value and no events.
        Type Parameters:
        T - The type of value in the result.
        Returns:
        Returns the created ValidatedResult.
      • getValidationEvents

        public java.util.List<ValidationEvent> getValidationEvents()
        Get the list of ValidationEvents associated with the result.
        Returns:
        Returns the validation events.
      • getValidationEvents

        public java.util.List<ValidationEvent> getValidationEvents​(Severity severity)
        Get validation events of a particular severity.
        Parameters:
        severity - Severity to get.
        Returns:
        Returns a list of events with the given severity.
      • getResult

        public java.util.Optional<T> getResult()
        Get the optional result.
        Returns:
        Returns the optional result.
      • unwrap

        public T unwrap()
        Get the result, but throw if there are any ERROR or DANGER events or if the result is empty.
        Returns:
        Returns the result.
        Throws:
        ValidatedResultException - if there are any ERROR or DANGER events.
        java.lang.IllegalStateException - if there is no result.
      • validate

        public java.util.Optional<T> validate()
        Get the optional result, and throw if there are any ERROR events.
        Returns:
        Returns the optional result.
        Throws:
        ValidatedResultException - if there are any ERROR events.
      • isBroken

        public boolean isBroken()
        Checks if the result has any error or danger events..
        Returns:
        Returns true if there are errors or unsuppressed dangers.