Interface Checker<T>

Type Parameters:
T - The value type.
All Superinterfaces:
Predicate<T>
All Known Implementing Classes:
AbstractStringChecker, HasNoDoubleSpaces, HasNoInnerSpaces, HasNoOuterSpaces, HasNoOuterWhiteSpaces, HasNoSpaces, IsConvertibleUsing, IsExistingDirectory, IsExistingFile, IsGreaterOrEqual, IsGreaterThan, IsInRange, IsInstanceOf, IsLessOrEqual, IsLessThan, IsNotNull, IsNull, IsNullOrEmpty, IsPattern, IsXml10String, LengthIsInRange, MatchesPattern, RawRefChecker, RefChecker

public interface Checker<T> extends Predicate<T>
Extension of Predicate that explains results.
Author:
Damien Carbonne
  • Method Details

    • getValueClass

      Class<T> getValueClass()
      Returns:
      The class of tested values.
    • test

      boolean test(T value)
      Specified by:
      test in interface Predicate<T>
    • testRaw

      default boolean testRaw(Object value)
    • explain

      String explain(boolean result, String arg)
      Explains the conditions at which a positive or negative result is obtained.
      Parameters:
      result - The result to explain.
      arg - The argument name to use in explanations.
      Returns:
      A string explaining the conditions leading to result.
    • explain

      default String explain(String arg)
    • explain

      default String explain()
    • testAndExplain

      default String testAndExplain(T value, String arg)
      Tests a value and explains the result.
      Parameters:
      value - The tested value.
      arg - The argument name to use in explanations.
      Returns:
      A string explaining why value passes or fails the test. value is represented by arg.
    • testAndExplainRaw

      default String testAndExplainRaw(Object value, String arg)
    • testAndExplain

      default String testAndExplain(T value)
      Tests a value and explains the result.
      Parameters:
      value - The tested value.
      Returns:
      A string explaining why value passes or fails the test. value is represented by its default string representation.
    • testAndExplainRaw

      default String testAndExplainRaw(Object value)
    • negate

      default Checker<T> negate()
      Specified by:
      negate in interface Predicate<T>
      Returns:
      A checker that is the logical negation of this checker.
    • and

      default Checker<T> and(Checker<? super T> other)
      Returns a checker that is the logical AND composition of this checker with another one.

      This checker is evaluated before other.
      If this checker evaluates to false, other is not evaluated.

      Parameters:
      other - The other checker.
      Returns:
      A checker that is the logical AND composition of this checker with other.
    • cast

      default <V> Checker<V> cast(Class<V> cls)
    • cast

      default Checker<T> cast(Checker<?> other)
    • andRaw

      default Checker<T> andRaw(Checker<?> other)
    • orRaw

      default Checker<T> orRaw(Checker<?> other)
    • or

      default Checker<T> or(Checker<? super T> other)
      Returns a checker that is the logical OR composition of this checker with another one.

      This checker is evaluated before other.
      If this checker evaluates to true, other is not evaluated.

      Parameters:
      other - The other checker.
      Returns:
      A checker that is the logical OR composition of this checker with other.
    • after

      default <S> Checker<S> after(Converter<S,? extends T> converter)
      Creates a checkers that checks that a value is convertible from a source type to a target type, then matches a checker of the target type.
      Type Parameters:
      S - The source type.
      Parameters:
      converter - A converter from a source type to a type that is compliant with this checker.
      Returns:
      A new checker that first applies the converter, then this checker.
    • afterRaw

      default Checker<?> afterRaw(Converter<?,?> converter)
    • after

      default <S> Checker<S> after(Function<S,? extends T> function, Class<S> sourceClass)
      Creates a checkers that checks that a value is convertible from a source type to a target type, then matches a checker of the target type.
      Type Parameters:
      S - The source type.
      Parameters:
      function - A function from a source type to a type that is compliant with this checker.
      sourceClass - The source class.
      Returns:
      A new checker that first applies the function, then this checker.
    • wrap

      default String wrap(String s)
    • fromConverter

      static <S> Checker<S> fromConverter(Converter<S,?> converter)
      Creates a checker from a converter.

      The checker checks that the argument is convertible.

      Type Parameters:
      S - The source type.
      Parameters:
      converter - The converter.
      Returns:
      A checker from converter.
    • fromFunction

      static <S, T> Checker<S> fromFunction(Function<S,?> function, Class<S> sourceClass, Class<T> targetClass)
      Creates a checker from a function.

      The checker checks that the argument is accepted (convertible) by the function.

      Type Parameters:
      S - The source type.
      T - The target type.
      Parameters:
      function - The function.
      sourceClass - The source class.
      targetClass - The target class.
      Returns:
      A checker from function.