- java.lang.Object
-
- swim.structure.Item
-
- swim.structure.Value
-
- swim.structure.Expression
-
- swim.structure.Selector
-
- swim.structure.selector.FilterSelector
-
public final class FilterSelector extends Selector implements Selectee<Item>
ASelector
that, whenevaluated
, yields eachItem
ininterpreter
such thatevaluating
predicate
against thisItem
would select at least one defined result. This is fundamentally different from returning the result itself; for example,FilterSelector(predicate=GetSelector(key="a")).evaluate(Record(Slot("a",5))
yields the
Record
itself, NOT just5
.To accomplish this,
FilterSelector
itself implementsSelectee<Item>.selected
by always returningExtant
which, crucially, is never null.forSelected
still takes the form "if (condition) then subselect"; here, "condition" is true only ifpredicate.forSelected(interpreter,this)
is not null. Thus, the responsibility to ensure thatthis.selected
is invoked only ifpredicate
would select something inInterpreter
is inpredicate.forSelected
--exactly as it should be.
-
-
Constructor Summary
Constructors Constructor Description FilterSelector(Selector predicate, Selector then)
-
Method Summary
Modifier and Type Method Description Selector
andThen(Selector then)
The means to chainSelectors
.protected int
compareTo(Selector that)
void
debugThen(Output<?> output)
boolean
equals(Object other)
FilterSelector
filter()
protected boolean
filterSelected(Interpreter interpreter)
<T> T
forSelected(Interpreter interpreter, Selectee<T> callback)
int
hashCode()
Item
mapSelected(Interpreter interpreter, Selectee<Item> transform)
Selector
predicate()
Item
selected(Interpreter interpreter)
Always returnsExtant
, which, crucially, is never null.Item
substitute(Interpreter interpreter)
Selector
then()
Returns theSelector
that thisSelector
uses to match sub-selections.int
typeOrder()
Returns the heterogeneous sort order of thisItem
.-
Methods inherited from class swim.structure.Selector
children, compareTo, debug, descendants, evaluate, filter, get, get, getAttr, getAttr, getItem, getItem, identity, invoke, isConstant, keys, literal, precedence, values
-
Methods inherited from class swim.structure.Expression
and, and, bitwiseAnd, bitwiseAnd, bitwiseNot, bitwiseOr, bitwiseOr, bitwiseXor, bitwiseXor, conditional, conditional, divide, divide, eq, eq, ge, ge, gt, gt, inverse, le, le, lt, lt, minus, minus, modulo, modulo, ne, ne, negative, not, or, or, plus, plus, positive, times, times
-
Methods inherited from class swim.structure.Value
absent, alias, body, booleanValue, booleanValue, branch, builder, byteValue, byteValue, charValue, charValue, commit, contains, containsKey, containsKey, containsValue, doubleValue, doubleValue, empty, extant, flattened, floatValue, floatValue, fromObject, getField, getField, getSlot, getSlot, head, header, headers, integerValue, integerValue, intValue, intValue, isAliased, isDefined, isDistinct, isMutable, key, keyEquals, lambda, length, longValue, longValue, numberValue, numberValue, removed, removed, shortValue, shortValue, stringValue, stringValue, tag, tail, target, toValue, unflattened
-
Methods inherited from class swim.structure.Item
appended, appended, appended, appended, appended, appended, appended, appended, cast, cast, coerce, coerce, concat, display, evaluate, globalScope, iterator, max, min, prepended, prepended, prepended, prepended, prepended, prepended, prepended, prepended, substitute, toString, updated, updated, updated, updated, updated, updated, updated, updated, updated, updated, updated, updated, updated, updated, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedAttr, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot, updatedSlot
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
predicate
public Selector predicate()
-
then
public Selector then()
Description copied from class:Selector
Returns theSelector
that thisSelector
uses to match sub-selections.
-
forSelected
public <T> T forSelected(Interpreter interpreter, Selectee<T> callback)
Description copied from class:Selector
Evaluatescallback.selected
against theItems
that match thisSelector's
selection criteria. That is, it pushes suchItems
tointerpreter
, then invokescallback
against it. To support chainedSelectors
, this is a recursive procedure that invokesforSelected
throughthis.then
wherever it exists (which it always does outside ofIdentitySelector
); we define "subselection" to be such an invocation.- Specified by:
forSelected
in classSelector
- Returns:
- the result of executing
callback
from the context of the lastSelector
in the chain formed bySelector then
fields.
-
mapSelected
public Item mapSelected(Interpreter interpreter, Selectee<Item> transform)
- Specified by:
mapSelected
in classSelector
-
substitute
public Item substitute(Interpreter interpreter)
- Overrides:
substitute
in classItem
-
filterSelected
protected boolean filterSelected(Interpreter interpreter)
-
selected
public Item selected(Interpreter interpreter)
Always returnsExtant
, which, crucially, is never null. SeeFilterSelector
for an explanation.
-
andThen
public Selector andThen(Selector then)
Description copied from class:Selector
The means to chainSelectors
. By intention, this is NOT a strict functional composition: for twoSelectors
s1
ands2
,s1.andThen(s2)
DOES NOT NECESSARILY return a newSelector
s3
such thats3.evaluate(args)
is equivalent tos2.evaluate(s1.evaluate(args))
.The reason for this is that for
Selectors
likeChildrenSelector
that yield (logical) collections, we wish to invoke the nextSelector
, say aGetSelector
, against every result. Under strict functional rules,ChildrenSelector.andThen(someGetSelector).evaluate(args)
would instead return at most one defined value regardless of the number of children.
-
filter
public FilterSelector filter()
Description copied from class:Selector
-
typeOrder
public int typeOrder()
Description copied from class:Item
Returns the heterogeneous sort order of thisItem
. Used to impose a total order on the set of all items. When comparing two items of different types, the items order according to theirtypeOrder
.
-
-