T - The data type the validator can validate.public interface Validator<T>
| Modifier and Type | Method and Description |
|---|---|
String |
getInvalidMessage(T value)
A user message explaining why the value is not valid if it fails this validation rule.
|
String |
getInvalidSpecificationMessage()
If the specification itself is invalid (such as a bad regex string), this
will build a message describing the problem to the user.
|
String |
getTheValueMustDescription()
Get a description of the validation rule.
|
boolean |
isSpecificationValid()
Returns true if the validation criteria itself is valid.
|
boolean |
isValid(T value)
Determines if the non-null value is valid according to the rule this validator enforces.
|
boolean isValid(T value) throws IllegalArgumentException
Implementations should check for null and throw an IllegalArgumentException, since some
types of validation operations may fail to detect a null and simply return false.
Loaders (which call Validators) is a probable user extension point, so consistent
handling and rejection of null values is important for custom Loaders to detect logic
issues.
value - A non-null value of type 'T'.IllegalArgumentException - If the value is null.String getInvalidMessage(T value)
The message should only refer to the value and rule criteria, and assume it is presented in a context that has already indicated an error and the Property. No leading or trailing punctuation should not be included.
Example: The value '999999999' is larger than the max value of 9999
value - The value which failed validation. Not null.String getInvalidSpecificationMessage()
This method may return a message regardless of if the validation is invalid or not - use isSpecificationValid() to determine if the Validator is configured correctly or not.
boolean isSpecificationValid()
For things like regex expressions, this would check to see if the regex expression is a valid expression.
String getTheValueMustDescription()
Assume that the text returned is prefixed with 'The value must...'
As an example for a regex rule with the pattern 'ABC.*', the return could be: "match the regex pattern 'ABC.*'"
Copyright © 2022. All rights reserved.