- java.lang.Object
-
- swim.structure.Item
-
- swim.structure.Value
-
- swim.structure.Expression
-
- swim.structure.Selector
-
- swim.structure.selector.LiteralSelector
-
public final class LiteralSelector extends Selector
ASelectorthat, whenevaluated, evaluates and yieldsitemagainstinterpreter. This allows us to express various selection criteria without having to implement the corresponding dedicatedSelectors.Such behavior is especially useful in conjunction with
FilterSelectors. For example, to selectItemsin someInterpretersuch that the sum of the results ofselecting"a" and "b" is less than 5, we could doSelector.literal(Selector.get("a").plus(Selector.get("b")).lt(5))This, notably, does not require a "ConditionalSelector" and only needs correct implementations of
LtOperatorandPlusOperator.
-
-
Constructor Summary
Constructors Constructor Description LiteralSelector(Item item, Selector then)
-
Method Summary
Modifier and Type Method Description SelectorandThen(Selector that)The means to chainSelectors.protected intcompareTo(Selector that)voiddebug(Output<?> output)Writes a developer readable, debug-formatted string representation of this object tooutput.voiddebugThen(Output<?> output)booleanequals(Object other)<T> TforSelected(Interpreter interpreter, Selectee<T> callback)inthashCode()Itemitem()ItemmapSelected(Interpreter interpreter, Selectee<Item> transform)intprecedence()Itemsubstitute(Interpreter interpreter)Selectorthen()Returns theSelectorthat thisSelectoruses to match sub-selections.inttypeOrder()Returns the heterogeneous sort order of thisItem.-
Methods inherited from class swim.structure.Selector
children, compareTo, descendants, evaluate, filter, filter, get, get, getAttr, getAttr, getItem, getItem, identity, invoke, isConstant, keys, literal, 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
-
item
public Item item()
-
then
public Selector then()
Description copied from class:SelectorReturns theSelectorthat thisSelectoruses to match sub-selections.
-
forSelected
public <T> T forSelected(Interpreter interpreter, Selectee<T> callback)
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
public Item mapSelected(Interpreter interpreter, Selectee<Item> transform)
- Specified by:
mapSelectedin classSelector
-
substitute
public Item substitute(Interpreter interpreter)
- Overrides:
substitutein classItem
-
andThen
public Selector andThen(Selector that)
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.
-
precedence
public int precedence()
- Overrides:
precedencein classSelector
-
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.
-
debug
public void debug(Output<?> output)
Description copied from interface:DebugWrites a developer readable, debug-formatted string representation of this object tooutput.
-
-