-
- Type Parameters:
T- type of the controls value
- All Superinterfaces:
BiFunction<Control,T,ValidationResult>
public interface Validator<T> extends BiFunction<Control,T,ValidationResult>
Interface defining the contract for validation of specific component This interface is aBiFunctionwhich when given the control and its current value computes the validation result
-
-
Method Summary
Static Methods Modifier and Type Method Description static <T> Validator<T>combine(Validator<T>... validators)Combines the given validators into a single Validator instance.static <T> Validator<T>createEmptyValidator(String message)Factory method to create a validator, which checks if value exists.static <T> Validator<T>createEmptyValidator(String message, Severity severity)Factory method to create a validator, which checks if value exists.static <T> Validator<T>createEqualsValidator(String message, Collection<T> values)Factory method to create a validator, which checks if value exists in the provided collection.static <T> Validator<T>createEqualsValidator(String message, Severity severity, Collection<T> values)Factory method to create a validator, which if value exists in the provided collection.static <T> Validator<T>createPredicateValidator(Predicate<T> predicate, String message)Factory method to create a validator, which evaluates the value validity with a given predicate.static <T> Validator<T>createPredicateValidator(Predicate<T> predicate, String message, Severity severity)Factory method to create a validator, which evaluates the value validity with a given predicate.static Validator<String>createRegexValidator(String message, String regex, Severity severity)Factory method to create a validator, which checks the value against a given regular expression.static Validator<String>createRegexValidator(String message, Pattern regex, Severity severity)Factory method to create a validator, which checks the value against a given regular expression.-
Methods inherited from interface java.util.function.BiFunction
andThen, apply
-
-
-
-
Method Detail
-
combine
@SafeVarargs static <T> Validator<T> combine(Validator<T>... validators)
Combines the given validators into a single Validator instance.- Parameters:
validators- the validators to combine- Returns:
- a Validator instance
-
createEmptyValidator
static <T> Validator<T> createEmptyValidator(String message, Severity severity)
Factory method to create a validator, which checks if value exists.- Parameters:
message- text of a message to be created if value is invalidseverity- severity of a message to be created if value is invalid- Returns:
- new validator
-
createEmptyValidator
static <T> Validator<T> createEmptyValidator(String message)
Factory method to create a validator, which checks if value exists. Error is created if not if value does not exist- Parameters:
message- of a error to be created if value is invalid- Returns:
- new validator
-
createEqualsValidator
static <T> Validator<T> createEqualsValidator(String message, Severity severity, Collection<T> values)
Factory method to create a validator, which if value exists in the provided collection.- Parameters:
values- text of a message to be created if value is not foundseverity- severity of a message to be created if value is found- Returns:
- new validator
-
createEqualsValidator
static <T> Validator<T> createEqualsValidator(String message, Collection<T> values)
Factory method to create a validator, which checks if value exists in the provided collection. Error is created if not found- Parameters:
message- text of a error to be created if value is not foundvalues-- Returns:
- new validator
-
createPredicateValidator
static <T> Validator<T> createPredicateValidator(Predicate<T> predicate, String message)
Factory method to create a validator, which evaluates the value validity with a given predicate. Error is created if the evaluation isfalse.- Parameters:
message- text of a message to be created if value is invalidpredicate- the predicate to be used for the value validity evaluation.- Returns:
- new validator
-
createPredicateValidator
static <T> Validator<T> createPredicateValidator(Predicate<T> predicate, String message, Severity severity)
Factory method to create a validator, which evaluates the value validity with a given predicate. Error is created if the evaluation isfalse.- Parameters:
message- text of a message to be created if value is invalidpredicate- the predicate to be used for the value validity evaluation.severity- severity of a message to be created if value is invalid- Returns:
- new validator
-
createRegexValidator
static Validator<String> createRegexValidator(String message, String regex, Severity severity)
Factory method to create a validator, which checks the value against a given regular expression. Error is created if the value isnullor the value does not match the pattern.- Parameters:
message- text of a message to be created if value is invalidregex- the regular expression the value has to matchseverity- severity of a message to be created if value is invalid- Returns:
- new validator
-
createRegexValidator
static Validator<String> createRegexValidator(String message, Pattern regex, Severity severity)
Factory method to create a validator, which checks the value against a given regular expression. Error is created if the value isnullor the value does not match the pattern.- Parameters:
message- text of a message to be created if value is invalidregex- the regular expression the value has to matchseverity- severity of a message to be created if value is invalid- Returns:
- new validator
-
-