Interface Validator<T>

Type Parameters:
T - Value type.
All Known Implementing Classes:
ValidatorImpl

public interface Validator<T>
Validator of values.
Author:
Damien Carbonne
  • Method Details

    • getValueClass

      Class<T> getValueClass()
      Returns:
      The class of values validated by this validator.
    • explainError

      String explainError(String name)
      Returns an explanation of the rule that must be respected to avoid errors.
      Parameters:
      name - The name that must be given to value in messages.
      Returns:
      An explanation of the rule that must be respected to avoid errors.
    • explainWarning

      String explainWarning(String name)
      Returns an explanation of the rule that must be respected to avoid warnings.
      Parameters:
      name - The name that must be given to value in messages.
      Returns:
      An explanation of the rule that must be respected to avoid warnings.
    • validate

      void validate(T value, String name, ValidationHandler handler)
      Validates a value.
      Parameters:
      value - The value.
      name - The name that must be given to value in messages.
      handler - The validation messages handler.
    • validate

      default void validate(T value, String name, List<ValidationRecord> records)
      Validates a value and adds validation records to a list.
      Parameters:
      value - The value.
      name - The name that must be given to value in messages.
      records - The list of validation records that must be filled.
      Throws:
      IllegalArgumentException - When records is null.
    • validate

      default List<ValidationRecord> validate(T value, String name)
      Validates a value and returns a list of validation records.
      Parameters:
      value - The value.
      name - The name that must be given to value in messages.
      Returns:
      A list of validation records, possibly empty.
    • validateRaw

      default void validateRaw(Object value, String name, ValidationHandler handler)
      Validates a raw value.
      Parameters:
      value - The value.
      name - The name that must be given to value in messages.
      handler - The validation messages handler.
      Throws:
      ClassCastException - If value is not null and cannot be assigned to value type T.
    • validateRaw

      default void validateRaw(Object value, String name, List<ValidationRecord> records)
      Validates a raw value and adds validation records to a list.
      Parameters:
      value - The value.
      name - The name that must be given to value in messages.
      records - The list of validation records that must be filled.
      Throws:
      IllegalArgumentException - When records is null.
      ClassCastException - If value is not null and cannot be assigned to value type T.
    • validateRaw

      default List<ValidationRecord> validateRaw(Object value, String name)
      Validates a raw value and returns a list of validation records.
      Parameters:
      value - The value.
      name - The name that must be given to value in messages.
      Returns:
      A list of validation records, possibly empty.
      Throws:
      ClassCastException - If value is not null and cannot be assigned to value type T.
    • getValidity

      default Validity getValidity(T value)
      Returns the validity of a value.
      Parameters:
      value - The value.
      Returns:
      The validity of value.
    • getValidityRaw

      default Validity getValidityRaw(Object value)
      Returns the validity of a raw value.
      Parameters:
      value - The value.
      Returns:
      The validity of value.
      Throws:
      ClassCastException - If value is not null and cannot be assigned to value type T.
    • after

      default <S> Validator<S> after(Converter<S,? extends T> converter)
      Creates a validator composed of this one applied after a converter.
      Type Parameters:
      S - The source type.
      Parameters:
      converter - The converter from source type S to T.
      Returns:
      A new validator composed of this one applied after converter.
      Throws:
      IllegalArgumentException - When converter is null.
    • afterRaw

      default Validator<?> afterRaw(Converter<?,?> converter)
      Parameters:
      converter - The converter.
      Returns:
      A new validator composed of this one applied after converter.
      Throws:
      IllegalArgumentException - When converter is null.
    • after

      default <S> Validator<S> after(Function<S,? extends T> function, Class<S> sourceClass)
      Creates a validator composed of this one applied after a conversion function.
      Type Parameters:
      S - The source type.
      Parameters:
      function - The function that converts values from source type S to T.
      sourceClass - The source class.
      Returns:
      A new validator composed of this one applied conversion function.
      Throws:
      IllegalArgumentException - When function or sourceClass is null.