java.lang.Object
swim.structure.Item
swim.structure.Value
swim.structure.Expression
swim.structure.Selector
- Direct Known Subclasses:
ChildrenSelector,DescendantsSelector,FilterSelector,GetAttrSelector,GetItemSelector,GetSelector,IdentitySelector,KeysSelector,LiteralSelector,ValuesSelector
An
Expression that returns references to Items when it is
evaluated. Because most application-level Items
are Records, a way to only extract certain parts of
Records is often required. Technically, this can be accomplished without
Selectors to some extent because the Record class implements
java.util.List<Item> and (implicitly) java.util.Map<Value,Value>; however, Selectors
additionally expose functional patterns that enhance composability, providing
a foundation on top of which expression languages can be built.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract SelectorThe means to chainSelectors.children()intprotected abstract int<T> Output<T>Writes a developer readable, debug-formatted string representation of this object tooutput.abstract <T> Output<T>final Itemevaluate(Interpreter interpreter) Evaluates thisSelectoragainst someInterpreter.filter()abstract <T> TforSelected(Interpreter interpreter, Selectee<T> callback) getItem(int index) static Selectoridentity()Creates, but does not evaluate, anInvokeOperatorwhere thisSelectorevaluates to the operator.booleankeys()static Selectorabstract ItemmapSelected(Interpreter interpreter, Selectee<Item> transform) intabstract Selectorthen()Returns theSelectorthat thisSelectoruses to match sub-selections.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, 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, equals, evaluate, globalScope, hashCode, iterator, max, min, prepended, prepended, prepended, prepended, prepended, prepended, prepended, prepended, substitute, substitute, toString, typeOrder, 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
-
Selector
public Selector()
-
-
Method Details
-
isConstant
public boolean isConstant()Description copied from class:Item- Specified by:
isConstantin classItem
-
then
Returns theSelectorthat thisSelectoruses to match sub-selections. -
forSelected
Evaluatescallback.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.- Returns:
- the result of executing
callbackfrom the context of the lastSelectorin the chain formed bySelector thenfields.
-
mapSelected
-
evaluate
Evaluates thisSelectoragainst someInterpreter. This is accomplished by creating a newSelecteeBuilderand populating its internalRecordwith (recursive) calls toforSelected(swim.structure.Interpreter, swim.structure.Selectee<T>). -
andThen
The 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. -
get
-
get
-
getAttr
-
getAttr
-
getItem
- Parameters:
index- theindexfield in the composingGetItemSelector.
-
getItem
-
keys
-
values
-
children
-
descendants
-
filter
-
filter
-
invoke
Creates, but does not evaluate, anInvokeOperatorwhere thisSelectorevaluates to the operator. -
precedence
public int precedence()- Overrides:
precedencein classItem
-
debug
Description copied from interface:DebugWrites a developer readable, debug-formatted string representation of this object tooutput. -
debugThen
-
compareTo
- Specified by:
compareToin interfaceComparable<Item>- Specified by:
compareToin classItem
-
compareTo
-
identity
-
literal
-