Class CollatedKey

java.lang.Object
dev.frostlake.executor.expressions.CollatedKey
All Implemented Interfaces:
Comparable<CollatedKey>

public final class CollatedKey extends Object implements Comparable<CollatedKey>
A sorting, grouping or DISTINCT key that carries the collation it compares under. Wrapping the key value — never the row's value — lets one comparator serve every key site: two texts equal under the collation hash and compare alike, so they fall into one group and sort as one value, while the text itself is kept verbatim for whoever reports it.

A group's REPORTED value is not this wrapper: values that tie under the collation are reported by their binary minimum, which leastOf(java.lang.Object, java.lang.Object) settles.

  • Method Details

    • of

      public static Object of(Object value, CollationSpec rules)
      The key for a value under a collation: the value itself when there is no collation, or when it is not text (a collation orders strings; everything else keeps its own order).
      Parameters:
      value - the key's value
      rules - the collation it compares under, or null for none
      Returns:
      the value, or a collated key wrapping it
    • unwrap

      public static Object unwrap(Object value)
      The text behind a key, so a wrapper never reaches a result.
      Parameters:
      value - a key value
      Returns:
      its text when it is a collated key, otherwise the value unchanged
    • leastOf

      public static Object leastOf(Object first, Object second)
      Which of two collation-equal values a group reports: the smaller by the raw text, since values that tie under the collation are still told apart by their code points.
      Parameters:
      first - one value, or null
      second - the other, or null
      Returns:
      the one a group reports
    • getText

      public String getText()
      The text this key carries.
      Returns:
      the text, verbatim
    • rulesOf

      public CollationSpec rulesOf()
      The collation this key compares under.
      Returns:
      the rules
    • compareTo

      public int compareTo(CollatedKey other)
      Specified by:
      compareTo in interface Comparable<CollatedKey>
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object