java.lang.Object
com.erudika.para.core.validation.Constraint
-
Method Summary
Modifier and TypeMethodDescriptionstatic Constraint
Builds a new constraint from a given name and payload.static Constraint
static Constraint
email()
The 'email' constraint - field must contain a valid email.static Constraint
falsy()
The 'falsy' constraint - field value must not be equal to 'true'.static Constraint
fromAnnotation
(Annotation anno) Builds a new constraint from the annotation data.static Constraint
future()
The 'future' constraint - field value must be aDate
or a timestamp in the future.getName()
The constraint name.The payload (a map).abstract boolean
Validates the given value against the this constraint.static boolean
isValidConstraintName
(String name) Returns true if that validator is the list of known validators.static boolean
isValidConstraintType
(Class<? extends Annotation> type) Returns true if that validator is the list of known validators.static boolean
matches
(Class<? extends Annotation> anno, String consName) Verifies that the given annotation type corresponds to a known constraint.static Constraint
The 'max' constraint - field must contain a number smaller than or equal to max.static Constraint
The 'min' constraint - field must contain a number larger than or equal to min.static Constraint
past()
The 'past' constraint - field value must be aDate
or a timestamp in the past.static Constraint
The 'pattern' constraint - field must contain a value matching a regular expression.static Constraint
required()
The 'required' constraint - marks a field as required.void
Sets the name of the constraint.void
setPayload
(Map<String, Object> payload) Sets the payload.static Constraint
The 'size' constraint - field must be aString
,Map
,Collection
or array with a given minimum and maximum length.static Constraint
truthy()
The 'truthy' constraint - field value must be equal to 'true'.static Constraint
url()
The 'url' constraint - field value must be a valid URL.
-
Method Details
-
isValid
Validates the given value against the this constraint.- Parameters:
actualValue
- a value / property of an object- Returns:
- true if the value satisfies the constraint
-
getName
-
setName
-
getPayload
-
setPayload
-
matches
Verifies that the given annotation type corresponds to a known constraint.- Parameters:
anno
- annotation typeconsName
- constraint name- Returns:
- true if known
-
fromAnnotation
Builds a new constraint from the annotation data.- Parameters:
anno
- JSR-303 annotation instance- Returns:
- a new constraint
-
isValidConstraintName
Returns true if that validator is the list of known validators.- Parameters:
name
- a name- Returns:
- true if validator is known
-
isValidConstraintType
Returns true if that validator is the list of known validators.- Parameters:
type
- annotation class type- Returns:
- true if validator is known
-
required
The 'required' constraint - marks a field as required.- Returns:
- constraint
-
min
The 'min' constraint - field must contain a number larger than or equal to min.- Parameters:
min
- the minimum value- Returns:
- constraint
-
max
The 'max' constraint - field must contain a number smaller than or equal to max.- Parameters:
max
- the maximum value- Returns:
- constraint
-
size
The 'size' constraint - field must be aString
,Map
,Collection
or array with a given minimum and maximum length.- Parameters:
min
- the minimum lengthmax
- the maximum length- Returns:
- constraint
-
digits
The 'digits' constraint - field must be aNumber
orString
containing digits where the number of digits in the integral part is limited by 'integer', and the number of digits for the fractional part is limited by 'fraction'.- Parameters:
integer
- the max number of digits for the integral partfraction
- the max number of digits for the fractional part- Returns:
- constraint
-
pattern
The 'pattern' constraint - field must contain a value matching a regular expression.- Parameters:
regex
- a regular expression- Returns:
- constraint
-
email
The 'email' constraint - field must contain a valid email.- Returns:
- constraint
-
falsy
The 'falsy' constraint - field value must not be equal to 'true'.- Returns:
- constraint
-
truthy
The 'truthy' constraint - field value must be equal to 'true'.- Returns:
- constraint
-
future
The 'future' constraint - field value must be aDate
or a timestamp in the future.- Returns:
- constraint
-
past
The 'past' constraint - field value must be aDate
or a timestamp in the past.- Returns:
- constraint
-
url
The 'url' constraint - field value must be a valid URL.- Returns:
- constraint
-
build
Builds a new constraint from a given name and payload.- Parameters:
cname
- the constraint namepayload
- the payload- Returns:
- constraint
-