Class PlannerBindings
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings
-
@API(EXPERIMENTAL) public class PlannerBindings extends Object
A map-like structure that supports a map from a binding to a collection ofBindable
s, such asRelationalExpression
s andExpressionRef
s. A binding's key is a pointer to theExpressionMatcher
that created the binding, eliminating the need for a unique string or symbol identifier. APlannerBindings
is immutable but has aPlannerBindings.Builder
that can be used to build up a set of bindings incrementally. Additionally, bindings can be combined usingmergedWith(PlannerBindings)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PlannerBindings.Builder
A mutable builder for a set ofPlannerBindings
which can be used to incrementally build up a set of bindings without repeatedly callingmergedWith(PlannerBindings)
, which is less efficient.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.common.collect.ImmutableListMultimap<ExpressionMatcher<? extends Bindable>,Bindable>
asMultiMap()
Return the bindings as multimap for callers that need reason about all bindings in a generic manner, e.g.boolean
containsKey(ExpressionMatcher<? extends Bindable> key)
Checks whether there is a bindable bound tokey
.static PlannerBindings
empty()
Return an empty set of bindings.static PlannerBindings
from(ExpressionMatcher<? extends Bindable> key, Bindable bindable)
Build a new set of bindings containing a single binding from the given key to the given bindable.<T extends Bindable>
Tget(ExpressionMatcher<T> key)
Retrieve the single bindable bound tokey
.<T extends Bindable>
List<T>getAll(ExpressionMatcher<T> key)
Retrieve allBindable
s bound tokey
if there is at least one such bindable.PlannerBindings
mergedWith(PlannerBindings other)
Combine this set of bindings with the given set of bindings.static PlannerBindings.Builder
newBuilder()
Return a new builder.
-
-
-
Method Detail
-
containsKey
public boolean containsKey(@Nonnull ExpressionMatcher<? extends Bindable> key)
Checks whether there is a bindable bound tokey
.- Parameters:
key
- a matcher- Returns:
- whether there is an object bound to
key
-
get
@Nonnull public <T extends Bindable> T get(@Nonnull ExpressionMatcher<T> key)
Retrieve the single bindable bound tokey
. This method is meant to be a convenient shortcut for the case where the developer is certain that precisely one bindable could be bound to this key. If no bindable is bound to this key, or if there are multipleBindable
s bound to this key, this throws aNoSuchElementException
.- Type Parameters:
T
- the type ofBindable
that was bound tokey
- Parameters:
key
- a matcher- Returns:
- the bindable object bound to key
- Throws:
NoSuchElementException
- if the number of bindables bound to this key is not exactly one
-
getAll
@Nonnull public <T extends Bindable> List<T> getAll(@Nonnull ExpressionMatcher<T> key)
Retrieve allBindable
s bound tokey
if there is at least one such bindable. The bindables in the returned list appear in same order as they appear in the list of children of theRelationalExpression
that produced this set of bindings. If no bindable is bound to this key, throw aNoSuchElementException
.- Type Parameters:
T
- the type ofBindable
that was bound tokey
- Parameters:
key
- a matcher- Returns:
- a list of bindable objects bound to the key
-
mergedWith
@Nonnull public PlannerBindings mergedWith(@Nonnull PlannerBindings other)
Combine this set of bindings with the given set of bindings. If both sets of bindings contain a binding with the same key, the resulting set of bindings will contain the concatenation of the bindables from this set of bindings and the bindables from the given set of bindings, in that order, providing a predictable ordering of bindings for planner rules that might need it.- Parameters:
other
- a set of bindings, which may share keys with this set of bindings- Returns:
- a new set of bindings that contains the bindings from both both sets of bindings
-
asMultiMap
@Nonnull public com.google.common.collect.ImmutableListMultimap<ExpressionMatcher<? extends Bindable>,Bindable> asMultiMap()
Return the bindings as multimap for callers that need reason about all bindings in a generic manner, e.g. this can be used by implementations ofDebugger
to show the contents of all bindings without the knowledge of the existence of particular matchers.- Returns:
- the backing immutable multi map
-
from
@Nonnull public static PlannerBindings from(@Nonnull ExpressionMatcher<? extends Bindable> key, @Nonnull Bindable bindable)
Build a new set of bindings containing a single binding from the given key to the given bindable.- Parameters:
key
- an expression matcherbindable
- a bindable object- Returns:
- a new set of bindings containing a single binding from
key
tobindable
-
empty
@Nonnull public static PlannerBindings empty()
Return an empty set of bindings.- Returns:
- an empty set of bindings
-
newBuilder
public static PlannerBindings.Builder newBuilder()
Return a new builder.- Returns:
- a new builder
-
-