Class FilterSelector

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

public final class FilterSelector extends Selector implements Selectee<Item>
A 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,


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 Details

  • Method Details

    • predicate

      public Selector predicate()
    • 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
      the result of executing callback from the context of the last Selector in the chain formed by Selector then fields.
    • mapSelected

      public Item mapSelected(Interpreter interpreter, Selectee<Item> transform)
      Specified by:
      mapSelected in class Selector
    • substitute

      public Item substitute(Interpreter interpreter)
      substitute in class Item
    • filterSelected

      protected boolean filterSelected(Interpreter interpreter)
    • selected

      public Item selected(Interpreter interpreter)
      Always returns Extant, which, crucially, is never null. See FilterSelector for an explanation.
      Specified by:
      selected in interface Selectee<Item>
    • 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
    • filter

      public FilterSelector filter()
      Description copied from class: Selector
      Returns a new FilterSelector with this as the predicate.
      filter 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
    • compareTo

      protected int compareTo(Selector that)
      Specified by:
      compareTo in class Selector
    • equals

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

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

      public <T> Output<T> debugThen(Output<T> output)
      Specified by:
      debugThen in class Selector