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) io.atlassian.fugue.Either
<ValidationResult, T> asEither()
Returns an either projection of this validation.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.boolean
isFail()
Returnstrue
if this validation is a fail,false
otherwise.boolean
Returnstrue
if this validation is a success,false
otherwise.success()
static <T> Validation
<T> success
(T success) com.atlassian.fugue.Either
<ValidationResult, T> toEither()
Deprecated.since 7.0.1.
-
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()Returnstrue
if this validation is a fail,false
otherwise.- Returns:
true
if this validation is a fail,false
otherwise.
-
isSuccess
public boolean isSuccess()Returnstrue
if this validation is a success,false
otherwise.- Returns:
true
if this validation is a success,false
otherwise.
-
toEither
Deprecated.since 7.0.1. UseasEither()
Returns an either projection of this validation.- Returns:
- An either projection of this validation.
-
asEither
Returns an either projection of this validation.- Returns:
- An either projection of this validation.
- Since:
- 7.0.1
-
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
-