public class MatchRule
extends java.lang.Object
implements java.io.Serializable
Any instance of this class can handle one rule.
A rule can be create through one of the different parsers.
(e.g. DefaultMatchRuleParser
or LdapFilterParser
)
If the constructor with a rule string as parameter is used, it
automatically uses the DefaultMatchRuleParser
to parse the rule.
Example:
Map attributes = new HashMap() ; attributes.put( "firstname", "Pedro" ) ; attributes.put( "surname", "Vazquez" ) ; attributes.put( "dob", "19610422" ) ; attributes.put( "city", "Madrid" ) ; MatchRule rule = DefaultMatchRuleParser.parse( "surname{V*} & city{Madrid}" ) ; if ( rule.match( attributes ) ) .....
Constructor and Description |
---|
MatchRule()
Initialize the new instance with default values.
|
MatchRule(boolean ignoreCase)
Initialize the new instance with default values.
|
MatchRule(MatchGroup aGroup)
Initialize the new instance with a root group
|
MatchRule(java.lang.String rule)
Initialize the new instance with a rule for later pattern-matching.
|
MatchRule(java.lang.String rule,
MatchRuleChars charSet)
Initialize the new instance with rule for later pattern-matching
and a set of special characters which are the operators and
separators on the rule.
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendGroup(MatchGroup group) |
void |
apply(MatchRuleVisitor visitor)
Iterates through all elements of the rule and calls the
appropriate methods of the given visitor.
|
protected boolean |
getIgnoreCase() |
protected boolean |
getIgnoreCaseInNames()
Returns true, if the parser produces MatchRules that treat
attribute names case-insensitive.
|
protected boolean |
getMultiCharWildcardMatchesEmptyString()
Returns true, if this match rule allows empty strings
at the position of the multi character wildcard ('*').
|
protected DefaultMatchRuleParser |
getParser() |
protected MatchGroup |
getRootGroup() |
void |
ignoreCase(boolean ignoreIt)
Defines whether or not the case of characters in value comparison
must be ignored.
|
void |
ignoreCaseInNames(boolean ignoreIt)
Defines whether or not the case of characters in attribute names
must be ignored.
|
boolean |
matches(java.util.Map<java.lang.String,?> dictionary)
Returns true, if the attributes and their values in the given
dictionary comply to the rules of the receiver.
|
void |
mergeAnd(MatchRule rule)
Append the given rule to the receiver with a logical AND
|
void |
mergeOr(MatchRule rule)
Append the given rule to the receiver with a logical OR
|
void |
multiCharWildcardMatchesEmptyString(boolean yesOrNo)
Sets whether or not this match rule allows empty
strings at the position of the multi character wildcard ('*').
|
void |
optimize()
Optimize the rule for best performance.
|
protected DefaultMatchRuleParser |
parser() |
protected void |
parseRule(java.lang.String rule,
MatchRuleChars charSet) |
void |
setDatatypes(java.util.Map<java.lang.String,java.lang.Class<?>> datatypes)
Sets the datatypes specified in the given map.
|
protected void |
setIgnoreCase(boolean newValue) |
protected void |
setParser(DefaultMatchRuleParser newValue) |
protected void |
setRootGroup(MatchGroup newValue) |
void |
setRule(java.lang.String rule)
Set (and parse) the given rule and keep it for later
checks with matches().
|
java.lang.String |
toString() |
public MatchRule()
public MatchRule(boolean ignoreCase)
public MatchRule(java.lang.String rule) throws MatchRuleParseException
MatchRuleParseException
public MatchRule(MatchGroup aGroup)
public MatchRule(java.lang.String rule, MatchRuleChars charSet) throws MatchRuleParseException
MatchRuleParseException
public void setRule(java.lang.String rule) throws MatchRuleParseException
MatchRuleParseException
public void ignoreCase(boolean ignoreIt)
public void ignoreCaseInNames(boolean ignoreIt)
public void multiCharWildcardMatchesEmptyString(boolean yesOrNo)
The default value is false.
public void mergeAnd(MatchRule rule)
public void mergeOr(MatchRule rule)
public boolean matches(java.util.Map<java.lang.String,?> dictionary)
dictionary
- The attribute-value pairs that have to be checked against the rulespublic java.lang.String toString()
toString
in class java.lang.Object
public void apply(MatchRuleVisitor visitor)
visitor
- the object that receives all callbacks for the visited elementspublic void optimize()
public void setDatatypes(java.util.Map<java.lang.String,java.lang.Class<?>> datatypes) throws MatchRuleException
Currently supported datatypes are:
datatypes
- The attributes and their corresponding typesMatchRuleException
- if a value of the rule cannot be converted to the specified datatypeprotected DefaultMatchRuleParser parser()
protected void parseRule(java.lang.String rule, MatchRuleChars charSet) throws MatchRuleParseException
MatchRuleParseException
protected void appendGroup(MatchGroup group)
protected MatchGroup getRootGroup()
protected void setRootGroup(MatchGroup newValue)
protected boolean getIgnoreCase()
protected void setIgnoreCase(boolean newValue)
protected boolean getIgnoreCaseInNames()
protected DefaultMatchRuleParser getParser()
protected void setParser(DefaultMatchRuleParser newValue)
protected boolean getMultiCharWildcardMatchesEmptyString()
The default value is false.