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 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:
  • Method Details

    • 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()
      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.
    • 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()