Interface ExpressionMatcher<T extends Bindable>
-
- Type Parameters:
T
- the bindable type that this matcher binds to
- All Known Implementing Classes:
QuantifierMatcher
,ReferenceMatcher
,TypeMatcher
,TypeWithPredicateMatcher
@API(EXPERIMENTAL) public interface ExpressionMatcher<T extends Bindable>
AExpressionMatcher
is an expression that can be matched against aRelationalExpression
tree, while binding certain expressions/references in the tree to expression matcher objects. The bindings can be retrieved from the rule call once the binding is matched.An
ExpressionMatcher
interacts with aPlannerExpression
tree using itsmatchWith(RelationalExpression)
andmatchWith(ExpressionRef)
methods. At a high level, thematchWith()
methods are responsible for determining whether this matcher matches the root expression or reference passed tomatchWith()
. AlthoughExpressionMatcher
s are themselves hierarchical structures, anExpressionMatcher
must not try to match into the contents (in the case of matching a reference) or children (in the case of matching an expression) of the given root. Depending on the specific implementation of the root structure, matching against children/members can be quite complicated, so this behavior is implemented by theBindable.bindTo(ExpressionMatcher)
method instead. AnExpressionMatcher
holds anExpressionChildrenMatcher
which describes how the children should be matched.Extreme care should be taken when implementing
ExpressionMatcher
, since it can be very delicate. In particular, expression matchers may (or may not) be reused between successive rule calls and should be stateless. Additionally, implementors ofExpressionMatcher
must use the (default) reference equals.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ExpressionChildrenMatcher
getChildrenMatcher()
Return the child matchers of this matcher as a list.Class<? extends Bindable>
getRootClass()
Get a class or interface extendingRelationalExpression
that is a super class of every planner expression that this matcher can match.Stream<PlannerBindings>
matchWith(ExpressionRef<? extends RelationalExpression> ref)
Attempt to match this matcher against the given expression reference.Stream<PlannerBindings>
matchWith(Quantifier quantifier)
Attempt to match this matcher against the givenQuantifier
.Stream<PlannerBindings>
matchWith(RelationalExpression expression)
Attempt to match this matcher against the givenExpressionMatcher
.Stream<PlannerBindings>
matchWith(QueryPredicate predicate)
Attempt to match this matcher against the givenQueryPredicate
.
-
-
-
Method Detail
-
getRootClass
@Nonnull Class<? extends Bindable> getRootClass()
Get a class or interface extendingRelationalExpression
that is a super class of every planner expression that this matcher can match. Ideally, it should be the lowest such class but it may not be. A planner will generally use this method to quickly determine a set of rules that could match an expression, without considering each rule and trying to apply it. A good implementation of this method helps the planner match rules efficiently.- Returns:
- a class object for a class that is a super class of every planner expression this matcher can match
-
getChildrenMatcher
@Nonnull ExpressionChildrenMatcher getChildrenMatcher()
Return the child matchers of this matcher as a list.- Returns:
- a list of the child matchers of this matcher
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull ExpressionRef<? extends RelationalExpression> ref)
Attempt to match this matcher against the given expression reference. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression and should not call into theExpressionChildrenMatcher
returned bygetChildrenMatcher()
or attempt to access the members of the given reference.- Parameters:
ref
- a reference to match with- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull RelationalExpression expression)
Attempt to match this matcher against the givenExpressionMatcher
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression and should not call into theExpressionChildrenMatcher
returned bygetChildrenMatcher()
or attempt to access children of the given expression.- Parameters:
expression
- a planner expression to match with- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull QueryPredicate predicate)
Attempt to match this matcher against the givenQueryPredicate
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression and should not call into theExpressionChildrenMatcher
returned bygetChildrenMatcher()
or attempt to access children of the given expression.- Parameters:
predicate
- a predicate to match with- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
matchWith
@Nonnull Stream<PlannerBindings> matchWith(@Nonnull Quantifier quantifier)
Attempt to match this matcher against the givenQuantifier
. Note that implementations ofmatchWith()
should only attempt to match the given root with this planner expression and should not call into theExpressionChildrenMatcher
returned bygetChildrenMatcher()
or attempt to access children of the given expression.- Parameters:
quantifier
- a quantifier to match with- Returns:
- a stream of
PlannerBindings
containing the matched bindings, or an empty stream is no match was found
-
-