Class StringJunction.One

java.lang.Object
com.github.tommyettinger.ds.StringJunction.One
All Implemented Interfaces:
Term<String>, Comparable<Term<String>>
Enclosing class:
StringJunction

public static class StringJunction.One extends Object implements Term<String>
Takes one or more Terms and matches if exactly one of those Terms matches.
  • Field Details

  • Constructor Details

  • Method Details

    • match

      public boolean match(Collection<? extends String> coll)
      Description copied from interface: Term
      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.
      Specified by:
      match in interface Term<String>
      Parameters:
      coll - a Collection of T that will not be modified
      Returns:
      true if coll matches, or false otherwise
    • remove

      public Collection<String> remove(Collection<String> coll)
      Description copied from interface: Term
      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.
      Specified by:
      remove in interface Term<String>
      Parameters:
      coll - a Collection of T that may be modified
      Returns:
      usually coll, after modifications
    • appendChildren

      public void appendChildren(Collection<Term<String>> appending)
      Description copied from interface: Term
      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.
      Specified by:
      appendChildren in interface Term<String>
      Parameters:
      appending - will be modified by appending child Terms
    • value

      public String value()
      Description copied from interface: Term
      If this term has a T value (not inside another wrapping Term), this returns that value. Otherwise, this returns null.
      Specified by:
      value in interface Term<String>
      Returns:
      a T value not inside another wrapping Term, or null if this Term doesn't have a T value.
    • canonicalize

      public Term<String> canonicalize()
      Description copied from interface: Term
      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.
      Specified by:
      canonicalize in interface Term<String>
      Returns:
      a unified formatting of the data this held, modifying this Term in place.
    • symbol

      public char symbol()
      Description copied from interface: Term
      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.
      Specified by:
      symbol in interface Term<String>
      Returns:
      a char that represents this Term and is used to break ties in sorting.
    • name

      public String name()
      Description copied from interface: Term
      Gets a plain-English name, typically all lower-case and one word, that describes what operation this Term performs.
      Specified by:
      name in interface Term<String>
      Returns:
      a typically lower-case single-word name describing what this Term does
    • toString

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

      public <S extends CharSequence & Appendable> S appendTo(S sb, Appender<String> appender)
      Description copied from interface: Term
      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.
      Specified by:
      appendTo in interface Term<String>
      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
    • appendTo

      public <S extends CharSequence & Appendable> S appendTo(S sb)
    • equals

      public final boolean equals(Object o)
      Description copied from interface: Term
      Used primarily to check for equality between Terms, not to act like Term.match(Collection).
      Specified by:
      equals in interface Term<String>
      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
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(Term<String> o)
      Specified by:
      compareTo in interface Comparable<Term<String>>
    • of

      @SafeVarargs public static StringJunction.One of(Term<String>... terms)