Class Validation<T>

  • All Implemented Interfaces:
    Serializable

    public class Validation<T>
    extends Object
    implements 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 #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.

    Since:
    5.9
    See Also:
    Serialized Form
    • 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
      • isFail

        public boolean isFail()
        Returns true if this validation is a fail, false otherwise.
        Returns:
        true if this validation is a fail, false otherwise.
      • isSuccess

        public boolean isSuccess()
        Returns true if this validation is a success, false otherwise.
        Returns:
        true if this validation is a success, false otherwise.
      • toEither

        @Deprecated
        public com.atlassian.fugue.Either<ValidationResult,​T> toEither()
        Deprecated.
        since 7.0.1. Use asEither()
        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.