Package cdc.validation.checkers
Interface Checker<T>
-
- Type Parameters:
T- The value type.
- All Superinterfaces:
Predicate<T>
- All Known Implementing Classes:
AbstractStringChecker,HasNoDoubleSpaces,HasNoInnerSpaces,HasNoOuterSpaces,HasNoSpaces,IsConvertibleUsing,IsExistingDirectory,IsExistingFile,IsGreaterOrEqual,IsGreaterThan,IsInRange,IsInstanceOf,IsLessOrEqual,IsLessThan,IsNotNull,IsPattern,IsXml10String,LengthIsInRange,MatchesPattern,RawRefChecker,RefChecker
public interface Checker<T> extends Predicate<T>
Extension of Predicate that explains results.- Author:
- Damien Carbonne
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description 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.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.default Checker<?>afterRaw(Converter<?,?> converter)default Checker<T>and(Checker<? super T> other)Returns a checker that is the logical AND composition of this checker with another one.default Checker<T>andRaw(Checker<?> other)default Checker<T>cast(Checker<?> other)default <V> Checker<V>cast(Class<V> cls)default Stringexplain()Stringexplain(boolean result, String arg)Explains the conditions at which a positive or negative result is obtained.default Stringexplain(String arg)static <S> Checker<S>fromConverter(Converter<S,?> converter)Creates a checker from a converter.static <S,T>
Checker<S>fromFunction(Function<S,?> function, Class<S> sourceClass, Class<T> targetClass)Creates a checker from a function.Class<T>getValueClass()default Checker<T>negate()default Checker<T>or(Checker<? super T> other)Returns a checker that is the logical OR composition of this checker with another one.default Checker<T>orRaw(Checker<?> other)booleantest(T value)default StringtestAndExplain(T value)Tests a value and explains the result.default StringtestAndExplain(T value, String arg)Tests a value and explains the result.default StringtestAndExplainRaw(Object value)default StringtestAndExplainRaw(Object value, String arg)default booleantestRaw(Object value)default Stringwrap(String s)
-
-
-
Method Detail
-
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
valuepasses or fails the test.valueis represented byarg.
-
testAndExplain
default String testAndExplain(T value)
Tests a value and explains the result.- Parameters:
value- The tested value.- Returns:
- A string explaining why
valuepasses or fails the test.valueis represented by its default string representation.
-
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 tofalse,otheris 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 totrue,otheris 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.
-
-