Class Constraint
java.lang.Object
com.erudika.para.core.validation.Constraint
Represents a validation constraint.
- Author:
- Alex Bogdanovski [[email protected]]
-
Method Summary
Modifier and TypeMethodDescriptionstatic ConstraintBuilds a new constraint from a given name and payload.static Constraintstatic Constraintemail()The 'email' constraint - field must contain a valid email.static Constraintfalsy()The 'falsy' constraint - field value must not be equal to 'true'.static ConstraintfromAnnotation(Annotation anno) Builds a new constraint from the annotation data.static Constraintfuture()The 'future' constraint - field value must be aDateor a timestamp in the future.getName()The constraint name.The payload (a map).abstract booleanValidates the given value against the this constraint.static booleanisValidConstraintName(String name) Returns true if that validator is the list of known validators.static booleanisValidConstraintType(Class<? extends Annotation> type) Returns true if that validator is the list of known validators.static booleanmatches(Class<? extends Annotation> anno, String consName) Verifies that the given annotation type corresponds to a known constraint.static ConstraintThe 'max' constraint - field must contain a number smaller than or equal to max.static ConstraintThe 'min' constraint - field must contain a number larger than or equal to min.static Constraintpast()The 'past' constraint - field value must be aDateor a timestamp in the past.static ConstraintThe 'pattern' constraint - field must contain a value matching a regular expression.static Constraintrequired()The 'required' constraint - marks a field as required.voidSets the name of the constraint.voidsetPayload(Map<String, Object> payload) Sets the payload.static ConstraintThe 'size' constraint - field must be aString,Map,Collectionor array with a given minimum and maximum length.static Constrainttruthy()The 'truthy' constraint - field value must be equal to 'true'.static Constrainturl()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,Collectionor 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 aNumberorStringcontaining 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 aDateor a timestamp in the future.- Returns:
- constraint
-
past
The 'past' constraint - field value must be aDateor 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
-