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 java.lang.ObjectRepresents the result of an operation and theValidationEvents that occurred.
-
-
Constructor Summary
Constructors Constructor Description ValidatedResult(T result, java.util.Collection<ValidationEvent> events)Deprecated.ValidatedResult(T result, java.util.List<ValidationEvent> events)Creates a result with a value and events.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> ValidatedResult<T>empty()Creates an empty ValidatedResult with no value and no events.static <T> ValidatedResult<T>fromErrors(java.util.Collection<ValidationEvent> events)Deprecated.static <T> ValidatedResult<T>fromErrors(java.util.List<ValidationEvent> events)Creates a new ValidatedResult with no values and a list ofValidationEvents.static <T> ValidatedResult<T>fromValue(T value)Creates a new ValidatedResult with a value and noValidationEvents.java.util.Optional<T>getResult()Get the optional result.java.util.List<ValidationEvent>getValidationEvents()Get the list ofValidationEvents associated with the result.java.util.List<ValidationEvent>getValidationEvents(Severity severity)Get validation events of a particular severity.booleanisBroken()Checks if the result has any error or danger events..Tunwrap()Get the result, but throw if there are any ERROR or DANGER events or if the result is empty.java.util.Optional<T>validate()Get the optional result, and throw if there are any ERROR events.
-
-
-
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 ofValidationEvents.- 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(java.util.Collection<ValidationEvent> events)
Deprecated.
-
fromValue
public static <T> ValidatedResult<T> fromValue(T value)
Creates a new ValidatedResult with a value and noValidationEvents.- 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 ofValidationEvents 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.
-
-