public class BaseGrammar extends Object
| Constructor and Description |
|---|
BaseGrammar() |
| Modifier and Type | Method and Description |
|---|---|
AllOfRule |
allOf(Rule... rules)
Matches if all the specified rules matches
|
AnyValueRule |
any()
Matches any value
|
AnyOfRule |
anyOf(List<Rule> rules)
Matches if any rule matches and suggests all the possibilities.
|
AnyOfRule |
anyOf(Rule... rules)
Matches if any rule matches and suggests all the possibilities.
|
ArrayRule |
array(Rule of)
Matches an array value
|
BooleanTypeRule |
booleanType()
Matches any Boolean type value
|
ExclusiveKeys |
exclusiveKeys(String... keys)
Creates a new set of exclusive rules
|
KeyValueRule |
field(Rule keyRule,
Rule valueRule)
Matches a field that the key matches the key rule and the value the value rule
|
KeyValueRule |
field(String keyName,
Rule valueRule)
Matches a field that the key is of string type and matches the specified key name and the value matches the value rule or null value
|
KeyValueRule |
fieldWithRequiredValue(Rule keyRule,
Rule valueRule)
Matches a field that the key is of string type and matches the specified key name and the value matches the value rule.
|
AnyOfRule |
firstOf(Rule... rules)
Accepts if any rule matches and delegates the suggestion to the first one that matches.
|
<T extends Rule> |
inNewContext(Callable<T> callable)
Returns rule created by the callable that runs a new separate context.
|
IntegerValueRule |
integer(Integer value)
Matches a number that is Integer and its value it the specified
|
IntegerTypeRule |
integerType()
Matches a number that is Integer
|
ConditionalRule |
is(Rule rule)
Conditional rule that will accept if the rule matches
|
MinLengthRule |
minLength(int length)
Matches a string that its length is bigger or equals to the specified
|
<T extends Rule> |
named(String name,
RuleFactory<T> ruleFactory)
Registers a rule with the specified name.
|
NegativeRule |
not(Rule rule)
Matches if the specified rule does not match
|
protected NullValueRule |
nullValue()
Matches a null value.
|
Rule |
numberType()
Matches any type of number
|
ObjectRule |
objectType()
Matches an object type
|
AnyOfRule |
optional(Rule rule)
Matches if the rule matches or the value is null
|
DefaultValue |
parentKey()
Returns a default value that is the parent key
|
IntegerTypeRule |
range(com.google.common.collect.Range<Integer> range)
Matches a number that is Integer and is included in the range
|
RegexValueRule |
regex(Pattern pattern)
Matches any value that is accepted by the regex pattern
|
RegexValueRule |
regex(String pattern)
Matches any value that is accepted by the regex pattern
|
KeyValueRule |
requiredField(Rule keyRule,
Rule valueRule)
Matches a field that the key is of string type and matches the specified key name and the value matches the value rule.
|
Rule |
scalarType()
Matches any scalar value e.g Number String boolean etc
|
StringValueRule |
string(String value)
Matches any value of type string with the specified value
|
StringTypeRule |
stringType()
Matches any String type value
|
ConditionalRules |
when(List<String> expr,
ConditionalRule... cases)
It will dispatch the to the conditional rule that matches the selected value.
|
ConditionalRules |
when(String expr,
ConditionalRule... cases)
It will dispatch the to the conditional rule that matches the selected value.
|
ChildBasedConditionalRule |
whenChildIs(Rule condition,
Rule then)
Delegates to a rule if the specified condition matches the first child.
|
FieldPresentRule |
whenPresent(String selector,
Rule then)
Delegates to a rule if a selector expression returns a value
|
public ObjectRule objectType()
public <T extends Rule> T named(String name, RuleFactory<T> ruleFactory)
T - The node typename - The name of the ruleruleFactory - The factory of the rulepublic <T extends Rule> T inNewContext(Callable<T> callable)
T - The type of rule it returnscallable - The callable to execute in a new contextpublic ChildBasedConditionalRule whenChildIs(Rule condition, Rule then)
condition - The conditionthen - the rule to be delegatedpublic FieldPresentRule whenPresent(String selector, Rule then)
selector - The selector expressionthen - The rule to be delegated if the selector returns a valuepublic AnyValueRule any()
public ArrayRule array(Rule of)
of - The type of the arraypublic IntegerTypeRule integerType()
public Rule numberType()
public IntegerTypeRule range(com.google.common.collect.Range<Integer> range)
range - The valid rangepublic IntegerValueRule integer(Integer value)
value - The value to matchpublic KeyValueRule field(Rule keyRule, Rule valueRule)
keyRule - The key rulevalueRule - The value rulepublic KeyValueRule field(String keyName, Rule valueRule)
keyName - The key namevalueRule - The value rulepublic KeyValueRule fieldWithRequiredValue(Rule keyRule, Rule valueRule)
this#field(String, Rule) it that Null is not matched for the value.keyRule - The key rulevalueRule - The value rulepublic KeyValueRule requiredField(Rule keyRule, Rule valueRule)
this#field(String, Rule) it that Null is not matched for the value and also mark this field as required in the object rule.keyRule - The key rulevalueRule - The value rulepublic Rule scalarType()
public StringTypeRule stringType()
public BooleanTypeRule booleanType()
public StringValueRule string(String value)
value - The value to matchpublic RegexValueRule regex(String pattern)
pattern - The patternpublic RegexValueRule regex(Pattern pattern)
pattern - The patternpublic AnyOfRule anyOf(Rule... rules)
rules - The option rulespublic AnyOfRule anyOf(List<Rule> rules)
rules - The option rulespublic AnyOfRule firstOf(Rule... rules)
rules - The rulespublic NegativeRule not(Rule rule)
rule - The rule to be negatedpublic AllOfRule allOf(Rule... rules)
rules - All the rules to matchpublic AnyOfRule optional(Rule rule)
rule - The rule to matchpublic MinLengthRule minLength(int length)
length - The lengthprotected NullValueRule nullValue()
public ConditionalRules when(String expr, ConditionalRule... cases)
expr - The expression to selectcases - The conditional casespublic ConditionalRules when(List<String> expr, ConditionalRule... cases)
expr - The list of expressions to try the first that is not null will be usedcases - The conditional casespublic ConditionalRule is(Rule rule)
rule - The rule to be used as matchingpublic DefaultValue parentKey()
public ExclusiveKeys exclusiveKeys(String... keys)
keys - Each of the mutually exclusive rulesCopyright © 2017. All rights reserved.