Package com.inductiveautomation.rm.base
Class RMSort
java.lang.Object
com.inductiveautomation.rm.base.RMSort
- All Implemented Interfaces:
Archivable
,RMJSONArchiver.GetKeys
,Cloneable
,Comparator
- Direct Known Subclasses:
RMTopNSort
,RMValueSort
public class RMSort
extends Object
implements Comparator, Cloneable, RMJSONArchiver.GetKeys, Archivable
This class provides a basic description for comparison and sorting with a simple key and order (ascending or
descending). You can create a new order like this:
RMSort titleFirst = new RMSort("getTitle"); RMSort bestRevenueFirst = new RMSort("getRevenue", ORDER_DESCEND);
This class also provides useful static methods for comparison and sorting:
RMSort.sort(myList, "getTitle"); // Sort myList by its contents' getTitle method (alphabetically) RMSort.sort(myList, bestRevenueFirst); // Sort myList by its contents' getRevenue method (largest first) List mySortList = new ArrayList(); mySortList.add(bestRevenueFirst); mySortList.add(titleFirst); RMSort.sort(myList, mySortList); // Sort myList by revenue and title
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Comparator
static final byte
static final byte
static final byte
static final byte
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
Standard clone implementation.int
Returns how the two given objects compare with this sort.static int
Compare two value objects (assumed to be String, Number, Boolean, Date, Comparable, etc.).boolean
Standard equals implementation.fromXML
(RXArchiver anArchiver, RXElement anElement) XML unarchival.RMJSONArchiver GetKeys method.getKey()
Returns the key for this sort.int
getOrder()
Returns the order for this sort.int
Returns the order default.Returns the order as a string.void
Sets the key for this sort.void
setOrder
(int anOrder) Sets the order for this sort.void
setOrderString
(String aString) Sets the order as a string.static void
Returns the given list sorted by the given sort.static void
Returns the given list sorted by the given sort.static void
Returns the given list sorted by the given key.static void
Returns the given list sorted by the given key.static void
Returns the given list sorted by the given list of sorts.static <T extends Comparable<? super T>>
List<T>sortedList
(Collection<T> aCollection) Returns a new sorted list from given collection.static <T> Vector<T>
sortedList
(Collection<T> aCollection, String aKey) Returns a new list from the given list sorted by the given key.static <T> Vector<T>
sortedList
(Collection<T> aCollection, String... theKeys) Returns a new list from the given list sorted by the given key.void
Toggles the order for this sort between ORDER_ASCEND<->ORDER_DESCEND.toString()
Returns a string representation of sort (just the sort key).toXML
(RXArchiver anArchiver) XML archival.Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
ORDER_SAME
public static final byte ORDER_SAME- See Also:
-
ORDER_ASCEND
public static final byte ORDER_ASCEND- See Also:
-
ORDER_DESCEND
public static final byte ORDER_DESCEND- See Also:
-
ORDER_INDETERMINATE
public static final byte ORDER_INDETERMINATE- See Also:
-
COMPARATOR
-
-
Constructor Details
-
RMSort
public RMSort()Creates a plain sort with no key. Used for unarchival, shouldn't be called directly. -
RMSort
Creates a sort with the given key and ORDER_ASCEND. -
RMSort
Creates a sort with the given key and order.
-
-
Method Details
-
getKey
Returns the key for this sort. -
setKey
Sets the key for this sort. -
getOrder
public int getOrder()Returns the order for this sort. -
setOrder
public void setOrder(int anOrder) Sets the order for this sort. -
getOrderDefault
public int getOrderDefault()Returns the order default. -
getOrderString
Returns the order as a string. -
setOrderString
Sets the order as a string. -
toggleOrder
public void toggleOrder()Toggles the order for this sort between ORDER_ASCEND<->ORDER_DESCEND. -
compare
Returns how the two given objects compare with this sort.- Specified by:
compare
in interfaceComparator
-
Compare
Compare two value objects (assumed to be String, Number, Boolean, Date, Comparable, etc.). -
sort
Returns the given list sorted by the given key. -
sort
Returns the given list sorted by the given sort. -
sort
Returns the given list sorted by the given key. -
sort
Returns the given list sorted by the given sort. -
sort
Returns the given list sorted by the given list of sorts. -
sortedList
Returns a new sorted list from given collection. -
sortedList
Returns a new list from the given list sorted by the given key. -
sortedList
Returns a new list from the given list sorted by the given key. -
equals
Standard equals implementation.- Specified by:
equals
in interfaceComparator
- Overrides:
equals
in classObject
-
clone
Standard clone implementation. -
getJSONKeys
RMJSONArchiver GetKeys method.- Specified by:
getJSONKeys
in interfaceRMJSONArchiver.GetKeys
-
toXML
XML archival.- Specified by:
toXML
in interfaceArchivable
-
fromXML
XML unarchival.- Specified by:
fromXML
in interfaceArchivable
-
toString
Returns a string representation of sort (just the sort key).
-