Class LiteralSelector

  • All Implemented Interfaces:
    Comparable<Item>, Iterable<Item>, Debug, Display

    public final class LiteralSelector
    extends Selector
    A Selector that, when evaluated, evaluates and yields item against interpreter. This allows us to express various selection criteria without having to implement the corresponding dedicated Selectors.

    Such behavior is especially useful in conjunction with FilterSelectors. For example, to select Items in some Interpreter such that the sum of the results of selecting "a" and "b" is less than 5, we could do

    Selector.literal(Selector.get("a").plus(Selector.get("b")).lt(5))

    This, notably, does not require a "ConditionalSelector" and only needs correct implementations of LtOperator and PlusOperator.

    • Constructor Detail

      • LiteralSelector

        public LiteralSelector​(Item item,
                               Selector then)
    • Method Detail

      • item

        public Item item()
      • then

        public Selector then()
        Description copied from class: Selector
        Returns the Selector that this Selector uses to match sub-selections.
        Specified by:
        then in class Selector
      • forSelected

        public <T> T forSelected​(Interpreter interpreter,
                                 Selectee<T> callback)
        Description copied from class: Selector
        Evaluates callback.selected against the Items that match this Selector's selection criteria. That is, it pushes such Items to interpreter, then invokes callback against it. To support chained Selectors, this is a recursive procedure that invokes forSelected through this.then wherever it exists (which it always does outside of IdentitySelector); we define "subselection" to be such an invocation.
        Specified by:
        forSelected in class Selector
        Returns:
        the result of executing callback from the context of the last Selector in the chain formed by Selector then fields.
      • andThen

        public Selector andThen​(Selector then)
        Description copied from class: Selector
        The means to chain Selectors. By intention, this is NOT a strict functional composition: for two Selectors s1 and s2, s1.andThen(s2) DOES NOT NECESSARILY return a new Selector s3 such that s3.evaluate(args) is equivalent to s2.evaluate(s1.evaluate(args)).

        The reason for this is that for Selectors like ChildrenSelector that yield (logical) collections, we wish to invoke the next Selector, say a GetSelector, 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.

        Specified by:
        andThen in class Selector
      • typeOrder

        public int typeOrder()
        Description copied from class: Item
        Returns the heterogeneous sort order of this Item. Used to impose a total order on the set of all items. When comparing two items of different types, the items order according to their typeOrder.
        Specified by:
        typeOrder in class Item
      • equals

        public boolean equals​(Object other)
        Specified by:
        equals in class Item
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in class Item
      • debug

        public <T> Output<T> debug​(Output<T> output)
        Description copied from interface: Debug
        Writes a developer readable, debug-formatted string representation of this object to output.
        Specified by:
        debug in interface Debug
        Overrides:
        debug in class Selector
        Returns:
        the continuation of the output.