public class ValidatorBuilder extends Object
Validator v = vb.range(50, 100);
p = new JSONParser("55");
json = p.nextValue();
v.validate(json);
| Constructor and Description |
|---|
ValidatorBuilder() |
| Modifier and Type | Method and Description |
|---|---|
Validator |
and(String ruleName,
Validator... validators)
Create a named and-combination
Andof a series of validators. |
Validator |
and(Validator... validators)
Create an anonymous and-combination
And of a series of validators. |
Validator |
array()
Create an anonymous
Array validator. |
Validator |
array(String ruleName)
Create a named
Array validator. |
Validator |
bool()
Create an anonymous
Bool validator. |
Validator |
bool(String ruleName)
Create a named
Bool validator. |
Validator |
complex()
Create an anonymus
Complex validator to check if a value is
an array or an object. |
Validator |
complex(String ruleName)
Create a named
Complex validator to check if a value is
an array or an object. |
Validator |
content(String ruleName,
Validator rule)
Create a named
Content validator that puts constraints on
the contents of an array or an object. |
Validator |
content(Validator rule)
Create an anonymous
Content validator that puts constraints on
the contents of an array or an object. |
Validator |
decimal()
Create an anonymous
Decimal validator to check if a value contains a decimal. |
Validator |
decimal(String ruleName)
Create a named
Decimal validator to check if a value is a decimal. |
Validator |
enumeration(JSONValue... values)
Create an anonymous
Enumeration validation rule. |
Validator |
enumeration(String... values)
A convenience method to create a named
Enumeration validation using a set of String values. |
Validator |
enumeration(String ruleName,
JSONValue... values)
Create a named
Enumeration validation rule. |
Validator |
enumeration(String ruleName,
String... values)
A convenience method to create a named
Enumeration validation using a set of String values. |
Validator |
falsep()
Create an anonymous
False validatioin rule that always fails. |
Validator |
falsep(String ruleName)
Create a named
False validation rule that always fails. |
Validator |
getRule(String ruleName)
Get a named validator that was previously built using this builder.
|
Validator |
intp()
Create an anonymous
Int validation rule. |
Validator |
intp(String ruleName)
Create a named
Int validation rule. |
Validator |
length(Integer min,
Integer max)
Create an anonymous
Length validation rule to check the length of an array or a string. |
Validator |
length(String ruleName,
Integer min,
Integer max)
Create a named
Length validator to check the length of an array or a string. |
Validator |
not(String ruleName,
Validator rule)
Create a named logical
Not validation which flips the result of an inner validation. |
Validator |
not(Validator rule)
Create an anonymous logical
Not validation which reverses the result of an inner validation. |
Validator |
nr()
Create an anonymous
Nr validator to see if a value is a number. |
Validator |
nr(String ruleName)
Create a named
Nr validator to see if a value is a number. |
Validator |
nullp()
Create an anonymous
Null checking validator. |
Validator |
nullp(String ruleName)
Create a named
Null checking validator. |
Validator |
object()
Create an anonymous
Object validator to check if a value
is an object |
Validator |
object(String ruleName)
Create a named
Object validator to check if a value
is an object. |
Validator |
or(String ruleName,
Validator... validators)
Create a named composite
Or validation. |
Validator |
or(Validator... validators)
Create an anonymous
Or validation rule. |
Validator |
properties(Properties.PropRule... rules)
Create an anonymous
Properties validator to check the key/value pairs of an object. |
Validator |
properties(String ruleName,
Properties.PropRule... rules)
Create a named
Properties validator to check the key/value pairs of an object. |
static Properties.PropRule |
propRule(String propName,
Validator rule,
boolean optional)
Create a
Properties.PropRule that is used to build a Properties validator for objects. |
Validator |
range(Integer min,
Integer max)
An anonymous
Range validator. |
Validator |
range(String ruleName,
Integer min,
Integer max)
Create a named
Range validator. |
Validator |
ref(String ref)
Create an anonymous
Ref validator. |
Validator |
ref(String ruleName,
String ref)
Create a named
Ref validator. |
Validator |
regexp(String pattern)
Create an anonymous
Regexp validator to validate strings against regular expressions. |
Validator |
regexp(String ruleName,
String pattern)
Create a named
Regexp validator to validate strings against regular expressions. |
Validator |
simple()
Create an anonymous
Simple validator to check that a value is atomic. |
Validator |
simple(String ruleName)
Create a named
Simple validator to check that a value is atomic. |
Validator |
string()
Create an anonymous
Str validator to check if a value is a string. |
Validator |
string(String ruleName)
Create a named
Str validator to check if a value is a string. |
static Switch.SwitchCase |
switchcase(Validator rule,
JSONValue... values)
Create a
Switch.SwitchCase that can be used to build a Switch validator. |
Validator |
switchrule(String ruleName,
String discriminator,
Switch.SwitchCase... cases)
Create a named
Switch validator. |
Validator |
switchrule(String discriminator,
Switch.SwitchCase... cases)
Create an anonymous
Switch validator. |
Validator |
truep()
Create an anonymous
True validation rule that always succeeds. |
Validator |
truep(String ruleName)
Create a named
True validation rule that always succeeds. |
public Validator getRule(String ruleName)
ruleName - The name of the validator rule.public Validator bool()
Bool validator.public Validator bool(String ruleName)
Bool validator.ruleName - The name of the rule you are building.public Validator range(Integer min, Integer max)
Range validator.min - The lower bound (inclusive). Value null means that there is no
lower boundary.max - The upper bound (inclusive). Value null means that there is no
upper boundary.public Validator range(String ruleName, Integer min, Integer max)
Range validator.ruleName - The name of the rule being created.min - The lower boundary (inclusive). Value null means that there is no lower boundary.max - The upper bound (inclusive). Value null means that there is no upper boundary.public Validator and(String ruleName, Validator... validators)
Andof a series of validators.
The validation process halts when the first failure is encountered.ruleName - The name of the rule under construction.validators - The array of validators that will be combined using the and operator.public Validator and(Validator... validators)
And of a series of validators.
The validation process halts when the first failure is encountered.validators - The array of validators that will be combined using the and operator.public Validator ref(String ruleName, String ref)
Ref validator. It creates an alias for another
named rule.
It is useful to refer to another rule inside a composite validator.ruleName - The name of the validator under construction.ref - The name of the rule you are referring to.public Validator ref(String ref)
Ref validator.
It is useful to refer to another rule inside a composite validator.ref - The name of the rule you are referring to.public Validator array(String ruleName)
Array validator.ruleName - The name of the rule under construction.public Validator array()
Array validator.public Validator complex(String ruleName)
Complex validator to check if a value is
an array or an object.ruleName - The name of the validation rule.public Validator complex()
Complex validator to check if a value is
an array or an object.public Validator content(String ruleName, Validator rule)
Content validator that puts constraints on
the contents of an array or an object.ruleName - The name of the content validation rule.rule - The validation rule that applies to the elements of the array or object.public Validator content(Validator rule)
Content validator that puts constraints on
the contents of an array or an object.rule - The validation rule that applies to the elements of the array or object.public Validator decimal(String ruleName)
Decimal validator to check if a value is a decimal.ruleName - The name of the validation rule.public Validator decimal()
Decimal validator to check if a value contains a decimal.public Validator enumeration(String ruleName, JSONValue... values)
Enumeration validation rule. Check if a value belongs
to a predefined set of values.ruleName - The name of the validation rule.values - The values of the enumeration.public Validator enumeration(JSONValue... values)
Enumeration validation rule. Check if a value belongs
to a predefined set of values.values - public Validator enumeration(String ruleName, String... values)
Enumeration validation using a set of String values.
The elements of the enumeration are JSONValue instances, but this method lets you
construct the enumeration using plain Strings.ruleName - The name of the validation rule.values - The elements of the enumeration set, they will be converted to JSONString values.public Validator enumeration(String... values)
Enumeration validation using a set of String values.
The elements of the enumeration are JSONValue instances, but this method lets you
construct the enumeration using plain Strings.values - The String values of the enumeration, they will be converted to JSONStrings.public Validator truep(String ruleName)
True validation rule that always succeeds.
We need to include this for the logic system to be complete.ruleName - The name of the validation.public Validator truep()
True validation rule that always succeeds.
We need to include this for the logic system to be complete.public Validator falsep(String ruleName)
False validation rule that always fails.
We need to include this for the logic system to be complete.ruleName - The name of our validation rule.public Validator falsep()
False validatioin rule that always fails.
We need to include this for the logic system to be complete.public Validator intp(String ruleName)
Int validation rule.ruleName - The name for our new rule.public Validator intp()
Int validation rule.public Validator length(Integer min, Integer max)
Length validation rule to check the length of an array or a string.min - The minimum length for the value (string or array).max - The maximum length the value can have (string or array).public Validator length(String ruleName, Integer min, Integer max)
Length validator to check the length of an array or a string.ruleName - The name of the validation rule.min - The minimum length for the value (string or array).max - The maximum length for the value (string or array).public Validator not(String ruleName, Validator rule)
Not validation which flips the result of an inner validation.ruleName - The name of our validation rule.rule - The inner validation, the result will be reversed.public Validator not(Validator rule)
Not validation which reverses the result of an inner validation.rule - The inner validation, the result of it will be reversed.public Validator nr(String ruleName)
Nr validator to see if a value is a number.ruleName - The name of the validation rule.public Validator nr()
Nr validator to see if a value is a number.public Validator nullp(String ruleName)
Null checking validator.ruleName - A name for the validation rule.public Validator nullp()
Null checking validator.public Validator object(String ruleName)
Object validator to check if a value
is an object.ruleName - The name of the rule.public Validator object()
Object validator to check if a value
is an objectpublic Validator or(String ruleName, Validator... validators)
Or validation. The value must match against one of the inner rules.ruleName - The name for our rule.validators - The inner validators, one of it must succeed on the value for the complete matcher to succeed.public Validator or(Validator... validators)
Or validation rule. The value must match against one of the inner rules.validators - The inner validators, one of it must succeed on the value for the complete matcher to succeed.public Validator regexp(String ruleName, String pattern)
Regexp validator to validate strings against regular expressions.ruleName - The name of the regular expression rule.pattern - The regular expression itself.public Validator regexp(String pattern)
Regexp validator to validate strings against regular expressions.pattern - The regular expression.public Validator simple(String ruleName)
Simple validator to check that a value is atomic.ruleName - The name of the new validator.public Validator simple()
Simple validator to check that a value is atomic.public Validator string(String ruleName)
Str validator to check if a value is a string.ruleName - The name of the validator.public Validator string()
Str validator to check if a value is a string.public Validator properties(String ruleName, Properties.PropRule... rules)
Properties validator to check the key/value pairs of an object.ruleName - The name of the validator.rules - An array of Properties.PropRule, each rule can validate a specific property of the object.
You can use the propRule(String, Validator, boolean) method to
quickly create the property rules.public Validator properties(Properties.PropRule... rules)
Properties validator to check the key/value pairs of an object.rules - An array of Properties.PropRule, each rule can validate a specific property of the object.
You can use the propRule(String, Validator, boolean) method to
quickly create the property rules.public Validator switchrule(String ruleName, String discriminator, Switch.SwitchCase... cases)
Switch validator.ruleName - The name of the rule.discriminator - The name of the field that will be used to select a Switch.SwitchCase.cases - An array of Switch.SwitchCase elements.
You can use the switchcase(Validator, JSONValue...) method to quickly create a case.public Validator switchrule(String discriminator, Switch.SwitchCase... cases)
Switch validator.discriminator - The name of the field that will be used to select a Switch.SwitchCase.cases - An array of Switch.SwitchCase elements.
You can use the switchcase(Validator, JSONValue...) method to quickly create a case.public static Switch.SwitchCase switchcase(Validator rule, JSONValue... values)
Switch.SwitchCase that can be used to build a Switch validator.rule - The internal validator.values - The discriminating values. If the discriminator is one of these values, the rule
will be applied to the complete object.public static Properties.PropRule propRule(String propName, Validator rule, boolean optional)
Properties.PropRule that is used to build a Properties validator for objects.propName - The name of the object property to which this rule applies.rule - The validator for this property.optional - A flag to indicate if the property is optional or not. If it is not optional, a validation
error will occur if the object does not have a property with that name.Copyright © 2012. All Rights Reserved.