Package xal.tools.data
Class SortOrdering
java.lang.Object
xal.tools.data.SortOrdering
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor with now sort keys specified.SortOrdering
(String key) Constructor with a single sort key.SortOrdering
(String[] newKeys) Constructor with an array of sort keys. -
Method Summary
Modifier and TypeMethodDescriptionAdd a new sort key to the end of the sort keys.int
compare
(KeyedRecord record1, KeyedRecord record2) Compare two records.String[]
getKeys()
Get the sort ordering keys.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
keys
-
-
Constructor Details
-
SortOrdering
public SortOrdering()Empty constructor with now sort keys specified. -
SortOrdering
Constructor with a single sort key.- Parameters:
key
- The lone key used for sorting.
-
SortOrdering
Constructor with an array of sort keys.- Parameters:
newKeys
- The array of keys used for the sort ordering.
-
-
Method Details
-
addKey
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
Get the sort ordering keys.- Returns:
- The sort ordering keys.
-
compare
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 interfaceComparator<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
-