public abstract class Constraint extends Object
| Modifier and Type | Method and Description |
|---|---|
static Constraint |
build(String cname,
Map<String,Object> payload)
Builds a new constraint from a given name and payload
|
static Constraint |
digits(Object integer,
Object fraction)
|
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 a
Date or a timestamp in the future. |
String |
getName()
The constraint name.
|
Map<String,Object> |
getPayload()
The payload (a map)
|
abstract boolean |
isValid(Object actualValue)
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 |
max(Object max)
The 'max' constraint - field must contain a number smaller than or equal to max.
|
static Constraint |
min(Object min)
The 'min' constraint - field must contain a number larger than or equal to min.
|
static Constraint |
past()
The 'past' constraint - field value must be a
Date or a timestamp in the past. |
static Constraint |
pattern(Object regex)
The 'pattern' constraint - field must contain a value matching a regular expression.
|
static Constraint |
required()
The 'required' constraint - marks a field as required.
|
void |
setName(String name)
Sets the name of the constraint.
|
void |
setPayload(Map<String,Object> payload)
Sets the payload.
|
static Constraint |
size(Object min,
Object max)
The 'size' constraint - field must be a
String, 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.
|
public abstract boolean isValid(Object actualValue)
actualValue - a value / property of an objectpublic String getName()
public void setName(String name)
name - a namepublic void setPayload(Map<String,Object> payload)
payload - a mappublic static boolean matches(Class<? extends Annotation> anno, String consName)
anno - annotation typeconsName - constraint namepublic static Constraint fromAnnotation(Annotation anno)
anno - JSR-303 annotation instancepublic static boolean isValidConstraintName(String name)
name - a namepublic static boolean isValidConstraintType(Class<? extends Annotation> type)
type - annotation class typepublic static Constraint required()
public static Constraint min(Object min)
min - the minimum valuepublic static Constraint max(Object max)
max - the maximum valuepublic static Constraint size(Object min, Object max)
String, Map, Collection or array
with a given minimum and maximum length.min - the minimum lengthmax - the maximum lengthpublic static Constraint digits(Object integer, Object fraction)
Number or String 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'.integer - the max number of digits for the integral partfraction - the max number of digits for the fractional partpublic static Constraint pattern(Object regex)
regex - a regular expressionpublic static Constraint email()
public static Constraint falsy()
public static Constraint truthy()
public static Constraint future()
Date or a timestamp in the future.public static Constraint past()
Date or a timestamp in the past.public static Constraint url()
public static Constraint build(String cname, Map<String,Object> payload)
cname - the constraint namepayload - the payloadCopyright © 2016 Erudika. All rights reserved.