Interface Validated<T>

Type Parameters:
T - the type of value being validated
All Superinterfaces:
Iterable<Validated<T>>
All Known Implementing Classes:
Validated.Both, Validated.Either, Validated.Invalid, Validated.Missing, Validated.None, Validated.Secret, Validated.Valid

public interface Validated<T> extends Iterable<Validated<T>>
A container object which may or may not contain a valid value. If a value is valid, isValid() returns true. If the value is invalid, the object is considered invalid and isValid() returns false.
  • Method Details

    • isValid

      boolean isValid()
    • isInvalid

      default boolean isInvalid()
    • failures

      default List<Validated.Invalid<T>> failures()
    • validSecret

      static Validated.Secret validSecret(String property, String value)
    • none

      static <T> Validated.None<T> none()
    • valid

      static <T> Validated.Valid<T> valid(String property, @Nullable T value)
    • test

      static <T> Validated<T> test(String property, String message, @Nullable T value, Predicate<T> test)
      Validate that the Predicate will evaluate to 'true' on the supplied value. When the Predicate evaluates to 'false' the error message will be of the form:

      "[property] was '[value]' but it [message]"

      Type Parameters:
      T - The property value type.
      Parameters:
      property - The property name to test
      message - The failure message if the test doesn't pass
      value - The value of the property
      test - The test predicate
      Returns:
      A validation result
    • testNone

      static <T, V> Validated<T> testNone(String property, String message, @Nullable V value, Predicate<V> test)
      Validate that the Predicate will evaluate to 'true' on the supplied value. Will return a Validated.None if the value is valid.

      This allows validation of a value that is not the intended return value.

      When the Predicate evaluates to 'false' the error message will be of the form:

      "[property] was '[value]' but it [message]"

      Type Parameters:
      T - The property value type.
      Parameters:
      property - The property name to test
      message - The failure message if the test doesn't pass
      value - The value of the property
      test - The test predicate
      Returns:
      A validation result
    • required

      static <T> Validated<T> required(String property, @Nullable T value)
    • notBlank

      static Validated<String> notBlank(String property, @Nullable String value)
    • missing

      static <T> Validated.Missing<T> missing(String property, @Nullable T value, String message)
    • invalid

      static <T> Validated.Invalid<T> invalid(String property, @Nullable Object value, String message)
    • invalid

      static <T> Validated.Invalid<T> invalid(String property, @Nullable Object value, String message, @Nullable Throwable exception)
    • and

      default Validated<T> and(Validated<? extends T> validated)
    • or

      default Validated<T> or(Validated<? extends T> validated)
    • getValue

      @Nullable T getValue()