public class Validation<T> extends Object implements Serializable
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 #success(T s)
and
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.
Modifier and Type | Method and Description |
---|---|
<A> Validation<A> |
applyValidation(Function<T,Validation<A>> f)
|
io.atlassian.fugue.Either<ValidationResult,T> |
asEither()
Returns an either projection of this validation.
|
ValidationResult |
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.
|
ValidationResult |
getValidationResult() |
boolean |
isFail()
Returns
true if this validation is a fail, false otherwise. |
boolean |
isSuccess()
Returns
true if this validation is a success, false otherwise. |
T |
success() |
static <T> Validation<T> |
success(T success) |
com.atlassian.fugue.Either<ValidationResult,T> |
toEither()
Deprecated.
since 7.0.1. Use
asEither() |
public static <T> Validation<T> success(T success)
T
- the success typesuccess
- the success value to be storedpublic static <T> Validation<T> fail(ValidationResult fail)
T
- the success typefail
- the fail value to be storedpublic T success()
NoSuchElementException
- thrown if called on failed validationpublic ValidationResult fail()
NoSuchElementException
- thrown if called on successful validationpublic boolean isFail()
true
if this validation is a fail, false
otherwise.true
if this validation is a fail, false
otherwise.public boolean isSuccess()
true
if this validation is a success, false
otherwise.true
if this validation is a success, false
otherwise.@Deprecated public com.atlassian.fugue.Either<ValidationResult,T> toEither()
asEither()
public io.atlassian.fugue.Either<ValidationResult,T> asEither()
public <A> Validation<A> flatMap(Function<T,Validation<A>> f)
A
- the success typef
- The function to bind across this validation.public <A> Validation<A> applyValidation(Function<T,Validation<A>> f)
A
- the success typef
- The function to bind across this validation.public ValidationResult getValidationResult()
Copyright © 2003–2020 Atlassian. All rights reserved.