public class InExRules<V,D,R> extends java.lang.Object implements InExRuleMatcher<V,R>
Rule engine works in one of two modes:
The logic of this rule engine depends on the current mode. In both cases, always the inverse rules are considered first. For example, for blacklist mode, engine first examine excludes, and then includes. This way you can set any filter combination.
All Jodd classes that filters something uses this class to unify the behavior across the Jodd library.
About generics: rule engine examine Values (V). Rules are defined as Definitions (D). They are stored internally as R, that is used with Values.
Modifier and Type | Class and Description |
---|---|
static class |
InExRules.Rule<R>
Rule definition.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
blacklist |
protected int |
excludesCount |
protected int |
includesCount |
protected InExRuleMatcher<V,R> |
inExRuleMatcher |
protected java.util.List<InExRules.Rule<R>> |
rules |
WILDCARD_PATH_RULE_MATCHER, WILDCARD_RULE_MATCHER
Constructor and Description |
---|
InExRules()
Creates default instance.
|
InExRules(InExRuleMatcher<V,R> inExRuleMatcher)
Creates instance that uses provided matcher.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(V value,
R rule,
boolean include)
Matches value against single rule.
|
protected void |
addRule(D ruleDefinition,
boolean include)
Adds a rule.
|
boolean |
apply(V value,
boolean flag)
Applies rules on given flag using current black/white list mode.
|
boolean |
apply(V value,
boolean blacklist,
boolean flag)
Applies rules on given flag.
|
void |
blacklist()
Enables blacklist mode - everything is included by default,
and user sets explicit excludes.
|
InExRules<java.lang.String,java.lang.String,java.lang.String> |
create() |
void |
detectMode()
Sets blacklist or whitelist mode depending on rules.
|
void |
exclude(D rule)
Adds exclude rule.
|
R |
getRule(int index)
Returns rule's value on given index.
|
boolean |
hasRules()
Returns
true if rule engine has at least one rule set. |
void |
include(D rule)
Adds include rule.
|
boolean |
isBlacklist()
Returns
true if blacklist mode is set. |
boolean |
isWhitelist()
Returns
true if whitelist mode is set. |
protected R |
makeRule(D rule) |
boolean |
match(V value)
Matches value against the set of rules using current white/black list mode.
|
boolean |
match(V value,
boolean blacklist)
Matches value against the set of rules using provided white/black list mode.
|
protected boolean |
processExcludes(V value,
boolean include)
Process excludes rules.
|
protected boolean |
processIncludes(V value,
boolean include)
Process includes rules.
|
void |
reset()
Resets all the rules in this rule engine.
|
int |
totalExcludeRules()
Returns total number of exclude rules.
|
int |
totalIncludeRules()
Returns total number of include rules.
|
int |
totalRules()
Returns total number of all rules.
|
void |
whitelist()
Enables whitelist mode - everything is excluded by default,
and user set explicit includes.
|
protected java.util.List<InExRules.Rule<R>> rules
protected final InExRuleMatcher<V,R> inExRuleMatcher
protected int includesCount
protected int excludesCount
protected boolean blacklist
public InExRules()
public InExRules(InExRuleMatcher<V,R> inExRuleMatcher)
public InExRules<java.lang.String,java.lang.String,java.lang.String> create()
public int totalRules()
public int totalIncludeRules()
public int totalExcludeRules()
public boolean hasRules()
true
if rule engine has at least one rule set.public R getRule(int index)
public void reset()
public void blacklist()
public boolean isBlacklist()
true
if blacklist mode is set.public void whitelist()
public boolean isWhitelist()
true
if whitelist mode is set.public void detectMode()
public void include(D rule)
public void exclude(D rule)
protected void addRule(D ruleDefinition, boolean include)
public boolean match(V value)
public boolean match(V value, boolean blacklist)
public boolean apply(V value, boolean flag)
apply(Object, boolean, boolean)
public boolean apply(V value, boolean blacklist, boolean flag)
protected boolean processIncludes(V value, boolean include)
protected boolean processExcludes(V value, boolean include)
Copyright © 2003-present Jodd Team