- All Implemented Interfaces:
Comparable<Item>,Iterable<Item>,swim.codec.Debug,swim.codec.Display,Selectee<Item>
Selector that, when evaluated, yields each
Item in interpreter such that evaluating predicate
against this Item 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 just 5.
To accomplish this, FilterSelector itself implements Selectee<Item>.selected by always returning Extant which, crucially, is never null. forSelected still takes the form "if (condition) then subselect"; here,
"condition" is true only if predicate.forSelected(interpreter,this)
is not null. Thus, the responsibility to ensure that this.selected
is invoked only if predicate would select something in
Interpreter is in predicate.forSelected--exactly as it should be.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe means to chainSelectors.protected int<T> swim.codec.Output<T>debugThen(swim.codec.Output<T> output) booleanfilter()protected booleanfilterSelected(Interpreter interpreter) <T> TforSelected(Interpreter interpreter, Selectee<T> callback) inthashCode()mapSelected(Interpreter interpreter, Selectee<Item> transform) selected(Interpreter interpreter) Always returnsExtant, which, crucially, is never null.substitute(Interpreter interpreter) then()Returns theSelectorthat thisSelectoruses to match sub-selections.intReturns 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, valuesMethods 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, timesMethods 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, isDefinite, isDistinct, isMutable, key, keyEquals, lambda, length, longValue, longValue, numberValue, numberValue, removed, removed, shortValue, shortValue, stringValue, stringValue, tag, tail, target, toValue, unflattenedMethods 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, updatedSlotMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
FilterSelector
-
-
Method Details
-
predicate
-
then
Description copied from class:SelectorReturns theSelectorthat thisSelectoruses to match sub-selections. -
forSelected
Description copied from class:SelectorEvaluatescallback.selectedagainst theItemsthat match thisSelector'sselection criteria. That is, it pushes suchItemstointerpreter, then invokescallbackagainst it. To support chainedSelectors, this is a recursive procedure that invokesforSelectedthroughthis.thenwherever it exists (which it always does outside ofIdentitySelector); we define "subselection" to be such an invocation.- Specified by:
forSelectedin classSelector- Returns:
- the result of executing
callbackfrom the context of the lastSelectorin the chain formed bySelector thenfields.
-
mapSelected
- Specified by:
mapSelectedin classSelector
-
substitute
- Overrides:
substitutein classItem
-
filterSelected
-
selected
Always returnsExtant, which, crucially, is never null. SeeFilterSelectorfor an explanation. -
andThen
Description copied from class:SelectorThe means to chainSelectors. By intention, this is NOT a strict functional composition: for twoSelectorss1ands2,s1.andThen(s2)DOES NOT NECESSARILY return a newSelectors3such thats3.evaluate(args)is equivalent tos2.evaluate(s1.evaluate(args)).The reason for this is that for
SelectorslikeChildrenSelectorthat 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
Description copied from class:Selector -
typeOrder
public int typeOrder()Description copied from class:ItemReturns 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. -
compareTo
-
equals
-
hashCode
public int hashCode() -
debugThen
public <T> swim.codec.Output<T> debugThen(swim.codec.Output<T> output)
-