T
- The type being created.public final class ValidatedResult<T>
extends java.lang.Object
ValidationEvent
s
that occurred.Constructor and 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.
|
Modifier and Type | Method and 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 of
ValidationEvent s. |
static <T> ValidatedResult<T> |
fromValue(T value)
Creates a new ValidatedResult with a value and no
ValidationEvent s. |
java.util.Optional<T> |
getResult()
Get the optional result.
|
java.util.List<ValidationEvent> |
getValidationEvents()
Get the list of
ValidationEvent s associated with the result. |
java.util.List<ValidationEvent> |
getValidationEvents(Severity severity)
Get validation events of a particular severity.
|
boolean |
isBroken()
Checks if the result has any error or danger events..
|
T |
unwrap()
Get the result, but throw if there are any ERROR events or if the
result is empty.
|
java.util.Optional<T> |
validate()
Get the optional result, and throw if there are any ERROR events.
|
public ValidatedResult(T result, java.util.List<ValidationEvent> events)
result
- Value to set.events
- Events to set.@Deprecated public ValidatedResult(T result, java.util.Collection<ValidationEvent> events)
public static <T> ValidatedResult<T> fromErrors(java.util.List<ValidationEvent> events)
ValidationEvent
s.T
- The type of value in the result.events
- Validation events on the result.@Deprecated public static <T> ValidatedResult<T> fromErrors(java.util.Collection<ValidationEvent> events)
public static <T> ValidatedResult<T> fromValue(T value)
ValidationEvent
s.T
- The type of value in the result.value
- Result value,public static <T> ValidatedResult<T> empty()
T
- The type of value in the result.public java.util.List<ValidationEvent> getValidationEvents()
ValidationEvent
s associated with the result.public java.util.List<ValidationEvent> getValidationEvents(Severity severity)
severity
- Severity to get.public java.util.Optional<T> getResult()
public T unwrap()
ValidatedResultException
- if there are any ERROR events.java.lang.IllegalStateException
- if there is no result.public java.util.Optional<T> validate()
ValidatedResultException
- if there are any ERROR events.public boolean isBroken()