Class CollationSpec

java.lang.Object
dev.frostlake.executor.expressions.CollationSpec

public final class CollationSpec extends Object
A collation specification — the text COLLATE names in a column definition or an expression — parsed into the rules a string comparison runs by.

The text is hyphen-separated specifiers, read case-insensitively and reported lower-cased: COLLATE 'EN-CI' is 'en-ci' to COLLATION, DESCRIBE and GET_DDL. A LOCALE may come first and is any word that is not an option — 'xx', 'bogus' and 'fr_CA' all parse, an unknown one comparing by the root rules. Without one the collation is the UTF8 pseudo-locale (spelled utf8 or bin as well), which compares code units. The options:

   cs / ci                  case-sensitive (the default) or not
   as / ai                  accent-sensitive (the default) or not
   ps / pi                  punctuation-sensitive or not
   fl / fu                  lower- or upper-case first when two differ only in case
   upper / lower            convert the case before comparing
   trim / ltrim / rtrim     drop leading and/or trailing spaces before comparing
 

The refusals, all live-verified and all worded Invalid value '<spec>' for COLLATION. Reason: ..., come in this order: an unknown option, the first in the text (Unknown option: zz — and a locale anywhere but first is one); upper beside lower; and a sensitivity option without a locale (Case sensitivity option not allowed for the UTF8 collation, then accent, punctuation and upper/lower preference). Repeating or contradicting a sensitivity option is no refusal — the last one wins — while the trims add up. Empty specifiers at the END are dropped, so '-' is the UTF8 collation and 'en-ci-' is 'en-ci'; one anywhere else is an unknown option, or no locale when it comes first.

A locale compares through the JDK's Collator, whose letter order, case tiers and accents agree with the account's: a < A < b under 'en', ä after z under 'sv', 'é' = 'e' only under ai. Punctuation and spaces weigh differently in the two rule sets, and live's case-insensitive level also folds full-width forms and the non-breaking space, which the JDK's does not.

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compare(String left, String right)
    Orders two strings.
    The key two strings share exactly when these rules call them equal — what a grouping, a DISTINCT or a set operation buckets by.
    The specification lower-cased, the spelling COLLATION reports.
    boolean
    Whether the comparison ignores case.
    static boolean
    isRefusal(String message)
    Whether message is this class's refusal, which a caller swallowing ordinary failures must let through: it is worded as neither a compilation nor an execution error.
    A LIKE operand, subject or pattern, as the match must see it: trimmed and case-converted as the rules say, and folded to lower case when they ignore case.
    parse(String spec)
    The rules spec names, refusing a specification live refuses.
    boolean
    Whether LIKE and ILIKE can match under these rules: not when they ignore accents or punctuation.
    boolean
    Whether LIKE ANY and LIKE ALL can: only without a locale.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parse

      public static CollationSpec parse(String spec)
      The rules spec names, refusing a specification live refuses.
      Parameters:
      spec - the specification as written, in any case
      Returns:
      its rules
    • isRefusal

      public static boolean isRefusal(String message)
      Whether message is this class's refusal, which a caller swallowing ordinary failures must let through: it is worded as neither a compilation nor an execution error.
      Parameters:
      message - a failure's message
      Returns:
      whether it refuses a collation specification
    • getText

      public String getText()
      The specification lower-cased, the spelling COLLATION reports.
    • isCaseInsensitive

      public boolean isCaseInsensitive()
      Whether the comparison ignores case.
    • supportsLike

      public boolean supportsLike()
      Whether LIKE and ILIKE can match under these rules: not when they ignore accents or punctuation.
    • supportsLikeAnyAll

      public boolean supportsLikeAnyAll()
      Whether LIKE ANY and LIKE ALL can: only without a locale.
    • compare

      public int compare(String left, String right)
      Orders two strings.
      Parameters:
      left - the first string
      right - the second
      Returns:
      negative, zero or positive, as left sorts before, with or after right
    • equalityKey

      public Object equalityKey(String value)
      The key two strings share exactly when these rules call them equal — what a grouping, a DISTINCT or a set operation buckets by. Derived from the same conversions compare(java.lang.String, java.lang.String) applies, so two values land in one bucket precisely when comparing them returns zero.
      Parameters:
      value - the string
      Returns:
      an object equal to another string's key exactly when the two compare equal
    • likeOperand

      public String likeOperand(String value)
      A LIKE operand, subject or pattern, as the match must see it: trimmed and case-converted as the rules say, and folded to lower case when they ignore case.
      Parameters:
      value - the operand's text
      Returns:
      the text to match