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 Selector
The means to chainSelectors
.children()
int
protected abstract int
<T> Output<T>
Writes a developer readable, debug-formatted string representation of this object tooutput
.abstract <T> Output<T>
final Item
evaluate
(Interpreter interpreter) Evaluates thisSelector
against someInterpreter
.filter()
abstract <T> T
forSelected
(Interpreter interpreter, Selectee<T> callback) getItem
(int index) static Selector
identity()
Creates, but does not evaluate, anInvokeOperator
where thisSelector
evaluates to the operator.boolean
keys()
static Selector
abstract Item
mapSelected
(Interpreter interpreter, Selectee<Item> transform) int
abstract Selector
then()
Returns theSelector
that thisSelector
uses 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, 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, isDefinite, 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, 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, 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
-
Constructor Details
-
Selector
public Selector()
-
-
Method Details
-
isConstant
public boolean isConstant()Description copied from class:Item
- Specified by:
isConstant
in classItem
-
then
Returns theSelector
that thisSelector
uses to match sub-selections. -
forSelected
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.- Returns:
- the result of executing
callback
from the context of the lastSelector
in the chain formed bySelector then
fields.
-
mapSelected
-
evaluate
Evaluates thisSelector
against someInterpreter
. This is accomplished by creating a newSelecteeBuilder
and populating its internalRecord
with (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 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. -
get
-
get
-
getAttr
-
getAttr
-
getItem
- Parameters:
index
- theindex
field in the composingGetItemSelector
.
-
getItem
-
keys
-
values
-
children
-
descendants
-
filter
-
filter
-
invoke
Creates, but does not evaluate, anInvokeOperator
where thisSelector
evaluates to the operator. -
precedence
public int precedence()- Overrides:
precedence
in classItem
-
debug
Description copied from interface:Debug
Writes a developer readable, debug-formatted string representation of this object tooutput
. -
debugThen
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Item>
- Specified by:
compareTo
in classItem
-
compareTo
-
identity
-
literal
-