Class SortKey


  • public class SortKey
    extends Object
    A combination of a key field and an ordering. Used alone or in an ordered collection, specifies the ordering of record data.
    See Also:
    TokenOrder
    • Constructor Detail

      • SortKey

        public SortKey​(String name)
        Create a key using ascending order.
        Parameters:
        name - Name of the key field
      • SortKey

        public SortKey​(String name,
                       TokenOrder order)
        Create a key using the specified order.
        Parameters:
        name - Name of the key field
        order - Order of the data
    • Method Detail

      • getName

        public String getName()
        Get the field name associated with this key.
        Returns:
        Name of the key field
      • hashCode

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

        public TokenOrder getOrder()
        Get the ordering associated with this key.
        Returns:
        Key's ordering
      • toString

        public String toString()
        Pretty-print this SortKey.
        Overrides:
        toString in class Object
        Returns:
        String containing field name and associated ordering
      • asc

        public static SortKey asc​(String name)
        Create an ascending key.
        Parameters:
        name - Name of the key field
        Returns:
        Descending sort key
      • asc

        public static SortKey[] asc​(String... names)
        Create multiple ascending keys.
        Parameters:
        names - Names of the key fields
        Returns:
        Ascending sort keys, in the same order as the supplied field names
      • desc

        public static SortKey desc​(String name)
        Create a descending key.
        Parameters:
        name - Name of the key field
        Returns:
        Descending sort key
      • desc

        public static SortKey[] desc​(String... names)
        Create multiple descending keys.
        Parameters:
        names - Names of the key fields
        Returns:
        Descending sort keys, in the same order as the supplied field names
      • makeSortKeys

        public static SortKey[] makeSortKeys​(TokenOrder order,
                                             String... names)
        Create multiple keys using the specified order.
        Parameters:
        order - Ordering to use for the keys
        names - Names of the key fields
        Returns:
        Sort keys, in the same order as the supplied field names
      • getNames

        public static String[] getNames​(SortKey... sortKeys)
        Extract the field names from several keys.
        Parameters:
        sortKeys - Keys from which to get the field names
        Returns:
        Field names for the keys, in the same order as the supplied keys
      • getOrders

        public static TokenOrder[] getOrders​(SortKey... sortKeys)
        Extract the orderings from several keys.
        Parameters:
        sortKeys - Keys from which to get the orderings
        Returns:
        Orderings for the keys, in the same order as the supplied keys
      • parseKey

        public static SortKey[] parseKey​(String... keyExpressions)
        Parse key expressions into SortKeys. A key expression consists of a field name and optionally the sort order: either "asc" or "desc" for ascending and descending respectively. Ascending is the default. Field names with embedded white space characters can optionally use single or double quotes to surround the field name.

        Examples:

        • "field desc" specifies to sort the column named "field" in descending order.
        • "'field with spaces' desc" specifies to sort the column named "field with spaces" in descending order.
        Parameters:
        keyExpressions - list of expressions to parse into sort keys
        Returns:
        a list of SortKey instances