Interface Checker<T>

    • Method Detail

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