Interface Validator<T>
-
- Type Parameters:
T- the class of the input value
- All Known Implementing Classes:
NotNullValidator,NumberValidator,PositiveNumberValidator,RequiredValidator
public interface Validator<T>An interface for providing validation of an input value.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Validator<T>add(Validator<T> other)Apply another validation after this validation.default Validator<T>add(Validator<T> other, java.lang.String separator)Apply another validation after this validation.static <T> Validator<T>empty()default Validator<T>then(Validator<T> other)Apply another validation if this validation passes.java.lang.Stringvalidate(T value)Validate a value.default Validator<T>when(java.util.function.Supplier<java.lang.Boolean> condition)default Validator<T>whenNot(java.util.function.Supplier<java.lang.Boolean> condition)
-
-
-
Method Detail
-
empty
static <T> Validator<T> empty()
-
validate
java.lang.String validate(T value)
Validate a value.- Parameters:
value- the value to validate- Returns:
- a description of the validation errors or
null
-
when
default Validator<T> when(java.util.function.Supplier<java.lang.Boolean> condition)
- Returns:
- a new
Validatorthat only reports errors when the condition is true
-
whenNot
default Validator<T> whenNot(java.util.function.Supplier<java.lang.Boolean> condition)
- Returns:
- a new
Validatorthat only reports errors when the condition is false
-
then
default Validator<T> then(Validator<T> other)
Apply another validation if this validation passes.- Parameters:
other- the other validator- Returns:
- a new
Validatorthat returns the error fromthisorother
-
add
default Validator<T> add(Validator<T> other)
Apply another validation after this validation. UsesSystem.lineSeparator()as the message separator.- Parameters:
other- the other validator- Returns:
- a new
Validatorthat returns the combined messages ofthisandother
-
add
default Validator<T> add(Validator<T> other, java.lang.String separator)
Apply another validation after this validation.- Parameters:
other- the other validatorseparator- the separator to use when joining the error messages- Returns:
- a new
Validatorthat returns the combined messages ofthisandother
-
-