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 Comparatorstatic final bytestatic final bytestatic final bytestatic final byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Standard clone implementation.intReturns how the two given objects compare with this sort.static intCompare two value objects (assumed to be String, Number, Boolean, Date, Comparable, etc.).booleanStandard equals implementation.fromXML(RXArchiver anArchiver, RXElement anElement) XML unarchival.RMJSONArchiver GetKeys method.getKey()Returns the key for this sort.intgetOrder()Returns the order for this sort.intReturns the order default.Returns the order as a string.voidSets the key for this sort.voidsetOrder(int anOrder) Sets the order for this sort.voidsetOrderString(String aString) Sets the order as a string.static voidReturns the given list sorted by the given sort.static voidReturns the given list sorted by the given sort.static voidReturns the given list sorted by the given key.static voidReturns the given list sorted by the given key.static voidReturns 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.voidToggles 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, waitMethods 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:
comparein 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:
equalsin interfaceComparator- Overrides:
equalsin classObject
-
clone
Standard clone implementation. -
getJSONKeys
RMJSONArchiver GetKeys method.- Specified by:
getJSONKeysin interfaceRMJSONArchiver.GetKeys
-
toXML
XML archival.- Specified by:
toXMLin interfaceArchivable
-
fromXML
XML unarchival.- Specified by:
fromXMLin interfaceArchivable
-
toString
Returns a string representation of sort (just the sort key).
-