Package play.data.validation
Class Constraints
- Object
-
- play.data.validation.Constraints
-
public class Constraints extends Object
Defines a set of built-in validation constraints.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceConstraints.EmailDefines a email constraint for a string field.static classConstraints.EmailValidatorValidator for@Emailfields.static interfaceConstraints.MaxDefines a maximum value for a numeric field.static interfaceConstraints.MaxLengthDefines a maximum length for a string field.static classConstraints.MaxLengthValidatorValidator for@MaxLengthfields.static classConstraints.MaxValidatorValidator for@Maxfields.static interfaceConstraints.MinDefines a minimum value for a numeric field.static interfaceConstraints.MinLengthDefines a minimum length for a string field.static classConstraints.MinLengthValidatorValidator for@MinLengthfields.static classConstraints.MinValidatorValidator for@Minfields.static interfaceConstraints.PatternDefines a pattern constraint for a string field.static classConstraints.PatternValidatorValidator for@Patternfields.static interfaceConstraints.PlayConstraintValidator<A extends Annotation,T>static interfaceConstraints.PlayConstraintValidatorWithPayload<A extends Annotation,T>static interfaceConstraints.RequiredDefines a field as required.static classConstraints.RequiredValidatorValidator for@Requiredfields.static interfaceConstraints.Validatable<T>static interfaceConstraints.ValidatableWithPayload<T>static interfaceConstraints.Validatestatic interfaceConstraints.ValidatePayloadWithDefines a custom validator.static classConstraints.ValidatePayloadWithValidatorValidator for@ValidatePayloadWithfields.static classConstraints.ValidateValidatorstatic classConstraints.ValidateValidatorWithPayloadstatic interfaceConstraints.ValidateWithDefines a custom validator.static interfaceConstraints.ValidateWithPayloadstatic classConstraints.ValidateWithValidatorValidator for@ValidateWithfields.static classConstraints.ValidationPayloadstatic classConstraints.Validator<T>Super-type for validators.static classConstraints.ValidatorWithPayload<T>Super-type for validators with a payload.
-
Constructor Summary
Constructors Constructor Description Constraints()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<F.Tuple<String,List<Object>>>displayableConstraint(Set<javax.validation.metadata.ConstraintDescriptor<?>> constraints)Converts a set of constraints to human-readable values.static List<F.Tuple<String,List<Object>>>displayableConstraint(Set<javax.validation.metadata.ConstraintDescriptor<?>> constraints, Annotation[] orderedAnnotations)Converts a set of constraints to human-readable values in guaranteed order.static F.Tuple<String,List<Object>>displayableConstraint(javax.validation.metadata.ConstraintDescriptor<?> constraint)Converts a constraint to a human-readable value.static Constraints.Validator<String>email()Constructs a 'email' validator.static Constraints.Validator<Number>max(long value)Constructs a 'max' validator.static Constraints.Validator<String>maxLength(long value)Constructs a 'maxLength' validator.static Constraints.Validator<Number>min(long value)Constructs a 'min' validator.static Constraints.Validator<String>minLength(long value)Constructs a 'minLength' validator.static Constraints.Validator<String>pattern(String regex)Constructs a 'pattern' validator.static Constraints.Validator<Object>required()Constructs a 'required' validator.
-
-
-
Method Detail
-
displayableConstraint
public static List<F.Tuple<String,List<Object>>> displayableConstraint(Set<javax.validation.metadata.ConstraintDescriptor<?>> constraints)
Converts a set of constraints to human-readable values. Does not guarantee the order of the returned constraints.This method calls
displayableConstraintunder the hood.- Parameters:
constraints- the set of constraint descriptors.- Returns:
- a list of pairs of tuples assembled from displayableConstraint.
-
displayableConstraint
public static List<F.Tuple<String,List<Object>>> displayableConstraint(Set<javax.validation.metadata.ConstraintDescriptor<?>> constraints, Annotation[] orderedAnnotations)
Converts a set of constraints to human-readable values in guaranteed order. Only constraints that have an annotation that intersect with theorderedAnnotationsparameter will be considered. The order of the returned constraints corresponds to the order of theorderedAnnotations parameter.- Parameters:
constraints- the set of constraint descriptors.orderedAnnotations- the array of annotations- Returns:
- a list of tuples showing readable constraints.
-
displayableConstraint
public static F.Tuple<String,List<Object>> displayableConstraint(javax.validation.metadata.ConstraintDescriptor<?> constraint)
Converts a constraint to a human-readable value.- Parameters:
constraint- the constraint descriptor.- Returns:
- A tuple containing the constraint's display name and the constraint attributes.
-
required
public static Constraints.Validator<Object> required()
Constructs a 'required' validator.- Returns:
- the RequiredValidator
-
min
public static Constraints.Validator<Number> min(long value)
Constructs a 'min' validator.- Parameters:
value- the minimum value- Returns:
- a validator for number.
-
max
public static Constraints.Validator<Number> max(long value)
Constructs a 'max' validator.- Parameters:
value- maximum value- Returns:
- a validator using MaxValidator.
-
minLength
public static Constraints.Validator<String> minLength(long value)
Constructs a 'minLength' validator.- Parameters:
value- the minimum length value.- Returns:
- the MinLengthValidator
-
maxLength
public static Constraints.Validator<String> maxLength(long value)
Constructs a 'maxLength' validator.- Parameters:
value- the max length- Returns:
- the MaxLengthValidator
-
email
public static Constraints.Validator<String> email()
Constructs a 'email' validator.- Returns:
- the EmailValidator
-
pattern
public static Constraints.Validator<String> pattern(String regex)
Constructs a 'pattern' validator.- Parameters:
regex- the regular expression to match.- Returns:
- the PatternValidator.
-
-