Class Validation<T>
- java.lang.Object
-
- com.atlassian.confluence.validation.Validation<T>
-
- All Implemented Interfaces:
Serializable
public class Validation<T> extends Object implements Serializable
This class is basically anEitherwhere 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)andfail(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:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <A> Validation<A>applyValidation(Function<T,Validation<A>> f)io.atlassian.fugue.Either<ValidationResult,T>asEither()Returns an either projection of this validation.ValidationResultfail()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.ValidationResultgetValidationResult()booleanisFail()Returnstrueif this validation is a fail,falseotherwise.booleanisSuccess()Returnstrueif this validation is a success,falseotherwise.Tsuccess()static <T> Validation<T>success(T success)com.atlassian.fugue.Either<ValidationResult,T>toEither()Deprecated.since 7.0.1.
-
-
-
Method Detail
-
success
public static <T> Validation<T> success(T success)
- Type Parameters:
T- the success type- Parameters:
success- the success value to be stored- Returns:
- a successful Validation containing the supplied value
-
fail
public static <T> Validation<T> fail(ValidationResult fail)
- Type Parameters:
T- the success type- Parameters:
fail- the fail value to be stored- Returns:
- a failed Validation containing the supplied value
-
success
public T success()
- Returns:
- T the success value
- Throws:
NoSuchElementException- thrown if called on failed validation
-
fail
public ValidationResult 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.
-
toEither
@Deprecated public com.atlassian.fugue.Either<ValidationResult,T> toEither()
Deprecated.since 7.0.1. UseasEither()Returns an either projection of this validation.- Returns:
- An either projection of this validation.
-
asEither
public io.atlassian.fugue.Either<ValidationResult,T> asEither()
Returns an either projection of this validation.- Returns:
- An either projection of this validation.
- Since:
- 7.0.1
-
flatMap
public <A> Validation<A> flatMap(Function<T,Validation<A>> f)
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
public <A> Validation<A> applyValidation(Function<T,Validation<A>> f)
- Type Parameters:
A- the success type- Parameters:
f- The function to bind across this validation.- Returns:
- A new validation value after binding.
-
getValidationResult
public ValidationResult getValidationResult()
-
-