Class ValidatedResult<T>

java.lang.Object
software.amazon.smithy.model.validation.ValidatedResult<T>
Type Parameters:
T - The type being created.

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

    • ValidatedResult

      public ValidatedResult(T result, 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, Collection<ValidationEvent> events)
      Deprecated.
  • Method Details

    • fromErrors

      public static <T> ValidatedResult<T> fromErrors(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.
    • fromErrors

      @Deprecated public static <T> ValidatedResult<T> fromErrors(Collection<ValidationEvent> events)
      Deprecated.
    • 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 List<ValidationEvent> getValidationEvents()
      Get the list of ValidationEvents associated with the result.
      Returns:
      Returns the validation events.
    • getValidationEvents

      public 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 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 events or if the result is empty.
      Returns:
      Returns the result.
      Throws:
      ValidatedResultException - if there are any ERROR events.
      IllegalStateException - if there is no result.
    • validate

      public 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.