Class SortOrdering

java.lang.Object
xal.tools.data.SortOrdering
All Implemented Interfaces:
Comparator<KeyedRecord>

public class SortOrdering extends Object implements Comparator<KeyedRecord>
SortOrdering can be used in DataTable queries to order records based on their values associated with the sort ordering keys. These associated values must be comparable (i.e. their class must implement the Comparable interface). The comparison is made starting with the first key and considers successive keys as necessary until the records can be ordered or all keys are exhausted resulting in equality.
Author:
tap
  • Field Details

    • keys

      protected String[] keys
  • Constructor Details

    • SortOrdering

      public SortOrdering()
      Empty constructor with now sort keys specified.
    • SortOrdering

      public SortOrdering(String key)
      Constructor with a single sort key.
      Parameters:
      key - The lone key used for sorting.
    • SortOrdering

      public SortOrdering(String[] newKeys)
      Constructor with an array of sort keys.
      Parameters:
      newKeys - The array of keys used for the sort ordering.
  • Method Details

    • addKey

      public SortOrdering addKey(String newKey)
      Add a new sort key to the end of the sort keys.
      Parameters:
      newKey - The new sort key.
      Returns:
      this for convenience in adding sorting criteria
    • getKeys

      public String[] getKeys()
      Get the sort ordering keys.
      Returns:
      The sort ordering keys.
    • compare

      public int compare(KeyedRecord record1, KeyedRecord record2)
      Compare two records. The sort ordering compares records based on their values associated with the sort ordering keys. These associated values must be comparable (i.e. their class must implement the Comparable interface). The comparison is made starting with the first key and considers successive keys as necessary until the records can be ordered or all keys are exhausted resulting in equality.
      Specified by:
      compare in interface Comparator<KeyedRecord>
      Parameters:
      record1 - The first record of the comparison.
      record2 - The second record of the comparison.
      Returns:
      0 if the records are equal, negative if record2 > record1 and positive if record1 > record2