Interface Validator<T,E>

Type Parameters:
T - type to validate
E - validation error type
All Known Implementing Classes:
Validator.ValidatorImpl

public interface Validator<T,E>
Simple validator that can collect validation errors.
  • Method Details

    • validate

      Validator<T,E> validate(Predicate<T> predicate, Supplier<E> errorSupplier)
      Validates validator's object of type T.
      Parameters:
      predicate - predicate to validate validator's object
      errorSupplier - error supplier if predicate returns false.
      Returns:
      this validator
    • validate

      <R> Validator<T,E> validate(Function<T,R> mapper, Predicate<R> predicate, Supplier<E> errorSupplier)
      Validates some internal state (class members, etc.) of validator's object.
      Type Parameters:
      R -
      Parameters:
      mapper -
      predicate -
      errorSupplier -
      Returns:
    • validate

      <R> Validator<T,E> validate(Function<T,R> mapper, Predicate<R> predicate, Function<R,E> errorMapper)
    • validate

      Validator<T,E> validate(Function<T,Optional<E>> errorChecker)
    • notNull

      <R> Validator<T,E> notNull(Function<T,R> mapper, Supplier<E> errorSupplier)
    • hasErrors

      boolean hasErrors()
      Checks if object is valid
      Returns:
      true if no validation errors were found
    • getErrors

      List<E> getErrors()
      Returns validation errors.
      Returns:
      empty list if no errors were found.
    • validate

      default Validator<T,E> validate(Predicate<T> predicate, E error)
    • validate

      default <R> Validator<T,E> validate(Function<T,R> mapper, Predicate<R> predicate, E error)
    • notNull

      default <R> Validator<T,E> notNull(Function<T,R> member, E error)
    • of

      static <T, E> Validator<T,E> of(T t)
      Factory method to create validator of type T and errors type E
      Type Parameters:
      T - type to validate
      E - validation error type
      Parameters:
      t - object to validate
      Returns:
      validator