Class Validation<T>
java.lang.Object
com.atlassian.confluence.validation.Validation<T>
- All Implemented Interfaces:
Serializable
This class is basically an
Either where left represents fail and right represents success.
While this class is public and abstract it does not expose a constructor as only the static
and
invalid reference
#success(T s)fail(ValidationResult f) methods are meant to be used.
Like Either, Validation is immutable, but does not force immutability on contained objects; if the contained
objects are mutable then equals and hashcode methods should not be relied on.
- Since:
- 5.9
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<A> Validation<A> applyValidation(Function<T, Validation<A>> f) fail()static <T> Validation<T> fail(ValidationResult fail) <A> Validation<A> flatMap(Function<T, Validation<A>> f) Binds the given function across this validation's success value if it has one.booleanisFail()Returnstrueif this validation is a fail,falseotherwise.booleanReturnstrueif this validation is a success,falseotherwise.success()static <T> Validation<T> success(T success)
-
Method Details
-
success
- Type Parameters:
T- the success type- Parameters:
success- the success value to be stored- Returns:
- a successful Validation containing the supplied value
-
fail
- Type Parameters:
T- the success type- Parameters:
fail- the fail value to be stored- Returns:
- a failed Validation containing the supplied value
-
success
- Returns:
- T the success value
- Throws:
NoSuchElementException- thrown if called on failed validation
-
fail
- Returns:
- ValidationResult of the failed values
- Throws:
NoSuchElementException- thrown if called on successful validation
-
isFail
public boolean isFail()Returnstrueif this validation is a fail,falseotherwise.- Returns:
trueif this validation is a fail,falseotherwise.
-
isSuccess
public boolean isSuccess()Returnstrueif this validation is a success,falseotherwise.- Returns:
trueif this validation is a success,falseotherwise.
-
flatMap
Binds the given function across this validation's success value if it has one.- Type Parameters:
A- the success type- Parameters:
f- The function to bind across this validation.- Returns:
- A new validation value after binding.
-
applyValidation
- Type Parameters:
A- the success type- Parameters:
f- The function to bind across this validation.- Returns:
- A new validation value after binding.
-
getValidationResult
-