Interface Term<T extends Comparable<T>>

Type Parameters:
T - the type being joined in the Junction; must be Comparable
All Superinterfaces:
Comparable<Term<T>>
All Known Implementing Classes:
Junction, Junction.All, Junction.Any, Junction.Leaf, Junction.Not, Junction.One, StringJunction, StringJunction.All, StringJunction.Any, StringJunction.Leaf, StringJunction.Not, StringJunction.One

public interface Term<T extends Comparable<T>> extends Comparable<Term<T>>
Mostly internal; describes part of a Junction.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Appender<Term<String>>
    An existing Appender for Terms of String, a common usage.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    If this Term has sub-Terms, which this calls children, calling appendChildren will take all children one level descendant from this and place them into appending, in undefined order.
    <S extends CharSequence & Appendable>
    S
    appendTo(S sb, Appender<T> appender)
    Appends a representation of this Term to an Appendable CharSequence, using appender to get textual forms from T items.
    Attempts to convert this Term and its children (recursively) to a single possible format for potentially many different internal representations.
    boolean
    Used primarily to check for equality between Terms, not to act like match(Collection).
    boolean
    match(Collection<? extends T> coll)
    A predicate that checks if the given Collection of T satisfies this Term.
    Gets a plain-English name, typically all lower-case and one word, that describes what operation this Term performs.
    Modifies the given Collection of T by removing any items that match this Term.
    char
    Gets a single char constant that represents this Term and determines its comparison order in the event of a tie.
    static <T extends Comparable<T>>
    Appender<Term<T>>
    termAppender(Appender<T> appender)
    Generates an Appender that can append Term of T items to an Appendable CharSequence.
    Slightly different from the normal toString() behavior, this may incorporate name() but doesn't need to, and if it contains multiple parts, they should be separated by symbol().
    If this term has a T value (not inside another wrapping Term), this returns that value.

    Methods inherited from interface Comparable

    compareTo
  • Field Details

    • termOfStringAppender

      static final Appender<Term<String>> termOfStringAppender
      An existing Appender for Terms of String, a common usage.
  • Method Details

    • match

      boolean match(Collection<? extends T> coll)
      A predicate that checks if the given Collection of T satisfies this Term. Returns true if this Term matches the given Collection, or false otherwise.
      Parameters:
      coll - a Collection of T that will not be modified
      Returns:
      true if coll matches, or false otherwise
    • remove

      Collection<T> remove(Collection<T> coll)
      Modifies the given Collection of T by removing any items that match this Term. You can use Junction.negate() on an outer Junction to flip this to perform the converse operation to removing, filtering.
      Parameters:
      coll - a Collection of T that may be modified
      Returns:
      usually coll, after modifications
    • appendChildren

      void appendChildren(Collection<Term<T>> appending)
      If this Term has sub-Terms, which this calls children, calling appendChildren will take all children one level descendant from this and place them into appending, in undefined order. Typically, after appendChildren() has been called at least once and doesn't need to append more, calling code will sort appending.
      Parameters:
      appending - will be modified by appending child Terms
    • value

      T value()
      If this term has a T value (not inside another wrapping Term), this returns that value. Otherwise, this returns null.
      Returns:
      a T value not inside another wrapping Term, or null if this Term doesn't have a T value.
    • canonicalize

      Term<T> canonicalize()
      Attempts to convert this Term and its children (recursively) to a single possible format for potentially many different internal representations. This mostly means things like Not(Not(Leaf("something"))) can be simplified to Leaf("something"), and chains of Any of Any of Any of... can be simplified to one Any with more items. The last case also works for All, but not One.
      Returns:
      a unified formatting of the data this held, modifying this Term in place.
    • symbol

      char symbol()
      Gets a single char constant that represents this Term and determines its comparison order in the event of a tie. Every Term class should return a different char from this method.
      Returns:
      a char that represents this Term and is used to break ties in sorting.
    • name

      String name()
      Gets a plain-English name, typically all lower-case and one word, that describes what operation this Term performs.
      Returns:
      a typically lower-case single-word name describing what this Term does
    • toString

      String toString()
      Slightly different from the normal toString() behavior, this may incorporate name() but doesn't need to, and if it contains multiple parts, they should be separated by symbol().
      Overrides:
      toString in class Object
      Returns:
      a String representation of this Term, or sometimes only its contents
    • appendTo

      <S extends CharSequence & Appendable> S appendTo(S sb, Appender<T> appender)
      Appends a representation of this Term to an Appendable CharSequence, using appender to get textual forms from T items.
      If this is a Term of String, you can use Appender.STRING_APPENDER as the second parameter.
      Type Parameters:
      S - any type that is both a CharSequence and an Appendable, such as StringBuilder, StringBuffer, CharBuffer, or CharList
      Parameters:
      sb - an Appendable CharSequence that this can append to
      appender - a function that takes an Appendable CharSequence and a T, and returns the modified S
      Returns:
      sb, with the appended representation of this Term
    • termAppender

      static <T extends Comparable<T>> Appender<Term<T>> termAppender(Appender<T> appender)
      Generates an Appender that can append Term of T items to an Appendable CharSequence.
      Type Parameters:
      T - the generic type that each Term carries, which is always Comparable (and is often String)
      Parameters:
      appender - an Appender that can append T items (not Term of T; that's what this method does)
      Returns:
      a new Appender of Term of T
    • equals

      boolean equals(Object o)
      Used primarily to check for equality between Terms, not to act like match(Collection).
      Overrides:
      equals in class Object
      Parameters:
      o - another Object that must be a Term of the same class for this to be able to return true
      Returns:
      true if and only if o is a Term of the same class, and this Term is equivalent to o