Interface RuleEvaluationService
-
- All Known Implementing Classes:
SpelRuleEvaluationService
public interface RuleEvaluationService
Intended to provide a means to evaluate rule builder expressions written in some expression language.
- Author:
- Nathan Moore (nathanmoore).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
allMatch(Collection<String> rules, Object rootObject, ExpressionContext expressionContext)
Use to determine if the object matches all rules provided.boolean
anyMatch(Collection<String> rules, Object rootObject, ExpressionContext expressionContext)
Use to determine if the object matches any rule provided.boolean
evaluateRule(String rule, Object rootObject, ExpressionContext expressionContext)
Uses the configured expression parser to evaluate the rule against the root object.<T> Iterable<T>
findAll(Collection<String> rules, Collection<T> rootObjects, ExpressionContext expressionContext)
Use to find all objects matching the rules provided.<T> Optional<T>
findAny(Collection<String> rules, Collection<T> rootObjects, ExpressionContext expressionContext)
Use to find an object that matches the rules.<T> Iterable<T>
findAnyN(Collection<String> rules, Collection<T> rootObjects, ExpressionContext expressionContext)
Use to find a subset of all objects matching the rules provided.<T> Optional<T>
findFirst(Collection<String> rules, Collection<T> rootObjects, ExpressionContext expressionContext)
Use to find the first object that matches the rules.<T> Iterable<T>
findFirstN(Collection<String> rules, Collection<T> rootObjects, ExpressionContext expressionContext)
Use to find a subset of all objects matching the rules provided.boolean
noneMatch(Collection<String> rules, Object rootObject, ExpressionContext expressionContext)
Use to determine if the object matches no provided rule.
-
-
-
Method Detail
-
evaluateRule
boolean evaluateRule(@Nullable String rule, @NonNull Object rootObject, @NonNull ExpressionContext expressionContext)
Uses the configured expression parser to evaluate the rule against the root object. If the rule is null or blank, this method returns
true
.- Parameters:
rule
- String representation of an expressionrootObject
- Object to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- whether the object matches the rule
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
anyMatch
boolean anyMatch(@NonNull Collection<String> rules, @NonNull Object rootObject, @NonNull ExpressionContext expressionContext)
Use to determine if the object matches any rule provided.
- Parameters:
rules
- String representations of expressionsrootObject
- Object to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- whether the object matches any rules
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
allMatch
boolean allMatch(@NonNull Collection<String> rules, @NonNull Object rootObject, @NonNull ExpressionContext expressionContext)
Use to determine if the object matches all rules provided.
- Parameters:
rules
- String representations of expressionsrootObject
- Object to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- whether the object matches all rules
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
noneMatch
boolean noneMatch(@NonNull Collection<String> rules, @NonNull Object rootObject, @NonNull ExpressionContext expressionContext)
Use to determine if the object matches no provided rule.
- Parameters:
rules
- String representations of expressionsrootObject
- Object to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- whether the object matches no rules
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
findFirst
<T> Optional<T> findFirst(@NonNull Collection<String> rules, @NonNull Collection<T> rootObjects, @NonNull ExpressionContext expressionContext)
Use to find the first object that matches the rules.
ExpressionContext.isMatchAnyRule()
should be set to determine if returned object must match any or all rules.- Parameters:
rules
- String representations of expressionsrootObjects
- Objects to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- the first object provided that matches the rules
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
findAny
<T> Optional<T> findAny(@NonNull Collection<String> rules, @NonNull Collection<T> rootObjects, @NonNull ExpressionContext expressionContext)
Use to find an object that matches the rules.
ExpressionContext.isMatchAnyRule()
should be set to determine if returned object must match any or all rules.- Parameters:
rules
- String representations of expressionsrootObjects
- Objects to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- an object provided that matches the rules
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
findAll
<T> Iterable<T> findAll(@NonNull Collection<String> rules, @NonNull Collection<T> rootObjects, @NonNull ExpressionContext expressionContext)
Use to find all objects matching the rules provided.
ExpressionContext.isMatchAnyRule()
should be set to determine if returned objects must match any or all rules.- Parameters:
rules
- String representations of expressionsrootObjects
- Objects to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- all objects provided that match rules
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
findAnyN
<T> Iterable<T> findAnyN(@NonNull Collection<String> rules, @NonNull Collection<T> rootObjects, @NonNull ExpressionContext expressionContext)
Use to find a subset of all objects matching the rules provided. The subset will consist of any 'n' objects found with 'n' being determined by
ExpressionContext.getLimit()
.ExpressionContext.isMatchAnyRule()
should be set to determine if returned objects must match any or all rules.- Parameters:
rules
- String representations of expressionsrootObjects
- Objects to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- a subset of 'n' objects matching the rules
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
findFirstN
<T> Iterable<T> findFirstN(@NonNull Collection<String> rules, @NonNull Collection<T> rootObjects, @NonNull ExpressionContext expressionContext)
Use to find a subset of all objects matching the rules provided. The subset will consist of the first 'n' objects found with 'n' being determined by
ExpressionContext.getLimit()
.ExpressionContext.isMatchAnyRule()
should be set to determine if returned objects must match any or all rules.- Parameters:
rules
- String representations of expressionsrootObjects
- Objects to evaluate the rule againstexpressionContext
- Relevant information required to evaluate an expression or group of expressions- Returns:
- a subset of the first 'n' objects matching the rules
- See Also:
StandardExpressionContext.EMPTY_EXPRESSION_CONTEXT
-
-