Record Class SortKey

java.lang.Object
java.lang.Record
io.keikai.axyra.sheets.SortKey

public record SortKey(int column, boolean ascending, String[] customOrder, boolean textAsNumber) extends Record
One sort key: a 0-based range-relative index and its direction, optionally carrying a custom ordering list (Excel's "Custom Lists").

For the default top-to-bottom sort (Range.sort(io.keikai.axyra.sheets.SortKey...)) column is the range-relative key column; for a left-to-right sort (Range.sortLeftToRight(io.keikai.axyra.sheets.SortKey...)) it is the range-relative key row.

When customOrder is non-null, values whose text matches a list entry (case-insensitively) sort by the entry's position; all non-matching values sort after every matching value, ordered among themselves by the normal comparator. A descending key produces the exact reverse of the ascending order.

textAsNumber is Excel's Sort Warning choice "Sort anything that looks like a number, as a number". Left off — the default, and what Excel's own Range.Sort does — text that spells a number is ordered by its characters, so "1" < "10" < "100" < "2". Turned on, such text is read as its numeric value and interleaves with genuine numeric cells, so "1" < "2" < "10" < "100".

  • Constructor Summary

    Constructors
    Constructor
    Description
    SortKey(int column, boolean ascending)
    A plain key without a custom ordering list.
    SortKey(int column, boolean ascending, String[] customOrder)
    A key with a custom ordering list but the default text ordering.
    SortKey(int column, boolean ascending, String[] customOrder, boolean textAsNumber)
    Creates an instance of a SortKey record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static SortKey
    asc(int column)
    Ascending sort on a column.
    boolean
    Returns the value of the ascending record component.
    int
    Returns the value of the column record component.
    Returns the value of the customOrder record component.
    static SortKey
    customOrder(int column, String... values)
    Ascending sort on a column by the position of each value in values (Excel's "Custom Lists" order, e.g.
    static SortKey
    desc(int column)
    Descending sort on a column.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    A copy of this key that reads numeric-looking text as a number — Excel's "Sort anything that looks like a number, as a number".
    boolean
    Returns the value of the textAsNumber record component.
    final String
    Returns a string representation of this record class.
    A copy of this key carrying the given custom ordering list.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SortKey

      public SortKey(int column, boolean ascending, String[] customOrder)
      A key with a custom ordering list but the default text ordering.
    • SortKey

      public SortKey(int column, boolean ascending)
      A plain key without a custom ordering list.
    • SortKey

      public SortKey(int column, boolean ascending, String[] customOrder, boolean textAsNumber)
      Creates an instance of a SortKey record class.
      Parameters:
      column - the value for the column record component
      ascending - the value for the ascending record component
      customOrder - the value for the customOrder record component
      textAsNumber - the value for the textAsNumber record component
  • Method Details

    • asc

      public static SortKey asc(int column)
      Ascending sort on a column.
    • desc

      public static SortKey desc(int column)
      Descending sort on a column.
    • customOrder

      public static SortKey customOrder(int column, String... values)
      Ascending sort on a column by the position of each value in values (Excel's "Custom Lists" order, e.g. "Mon", "Tue", "Wed", ...); unlisted values sort after all listed ones.
    • withCustomOrder

      public SortKey withCustomOrder(String... values)
      A copy of this key carrying the given custom ordering list.
    • sortingTextAsNumber

      public SortKey sortingTextAsNumber()
      A copy of this key that reads numeric-looking text as a number — Excel's "Sort anything that looks like a number, as a number".
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • column

      public int column()
      Returns the value of the column record component.
      Returns:
      the value of the column record component
    • ascending

      public boolean ascending()
      Returns the value of the ascending record component.
      Returns:
      the value of the ascending record component
    • customOrder

      public String[] customOrder()
      Returns the value of the customOrder record component.
      Returns:
      the value of the customOrder record component
    • textAsNumber

      public boolean textAsNumber()
      Returns the value of the textAsNumber record component.
      Returns:
      the value of the textAsNumber record component