Class Sort
- java.lang.Object
- 
- com.inductiveautomation.snap.data.Sort
 
- 
- All Implemented Interfaces:
- RMJSONArchiver.GetKeys,- java.lang.Cloneable,- java.util.Comparator
 
 public class Sort extends java.lang.Object implements java.util.Comparator, java.lang.Cloneable, RMJSONArchiver.GetKeys 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:Sort titleFirst = new Sort("Title"); Sort bestRevenueFirst = new Sort("Revenue", ORDER_DESCEND);This class also provides useful static methods for comparison and sorting: Sort.sort(myList, "Title"); // Sort myList by its contents' getTitle method (alphabetically) Sort.sort(myList, bestRevenueFirst); // Sort myList by its contents' getRevenue method (largest first) List mySortList = new ArrayList(); mySortList.add(bestRevenueFirst); mySortList.add(titleFirst); Sort.sort(myList, mySortList); // Sort myList by revenue and title 
- 
- 
Field SummaryFields Modifier and Type Field Description static java.util.ComparatorCOMPARATORstatic byteORDER_ASCENDstatic byteORDER_DESCENDstatic byteORDER_SAME
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Standard clone implementation.intcompare(java.lang.Object obj1, java.lang.Object obj2)Returns how the two given objects compare with this sort.static intCompare(java.lang.Object anObj1, java.lang.Object anObj2)Compare two value objects (assumed to be String, Number, Boolean, Date, Comparable, etc.).booleanequals(java.lang.Object anObj)Standard equals implementation.java.util.List<java.lang.String>getJSONKeys()RMJSONArchiver GetKeys method.java.lang.StringgetKey()Returns the key for this sort.intgetOrder()Returns the order for this sort.voidsetKey(java.lang.String aKey)Sets the key for this sort.voidsetOrder(int anOrder)Sets the order for this sort.static voidsort(java.util.List aList, Sort aSort)Returns the given list sorted by the given sort.static voidsort(java.util.List aList, Sort... theSorts)Returns the given list sorted by the given sort.static voidsort(java.util.List aList, java.lang.String aKey)Returns the given list sorted by the given key.static voidsort(java.util.List aList, java.lang.String... theKeys)Returns the given list sorted by the given key.static voidsort(java.util.List aList, java.util.List aSortList)Returns the given list sorted by the given list of sorts.static <T extends java.lang.Comparable<? super T>>
 java.util.List<T>sortedList(java.util.Collection<T> aCollection)Returns a new sorted list from given collection.static <T> java.util.List<T>sortedList(java.util.Collection<T> aCollection, java.lang.String aKey)Returns a new list from the given list sorted by the given key.static <T> java.util.List<T>sortedList(java.util.Collection<T> aCollection, java.lang.String... theKeys)Returns a new list from the given list sorted by the given key.voidtoggleOrder()Toggles the order for this sort between ORDER_ASCEND<->ORDER_DESCEND.java.lang.StringtoString()Returns a string representation of sort (just the sort key).
 
- 
- 
- 
Field Detail- 
ORDER_SAMEpublic static final byte ORDER_SAME - See Also:
- Constant Field Values
 
 - 
ORDER_ASCENDpublic static final byte ORDER_ASCEND - See Also:
- Constant Field Values
 
 - 
ORDER_DESCENDpublic static final byte ORDER_DESCEND - See Also:
- Constant Field Values
 
 - 
COMPARATORpublic static java.util.Comparator COMPARATOR 
 
- 
 - 
Constructor Detail- 
Sortpublic Sort() Creates a plain sort with no key. Used for unarchival, shouldn't be called directly.
 - 
Sortpublic Sort(java.lang.String aKey) Creates a sort with the given key and ORDER_ASCEND.
 - 
Sortpublic Sort(java.lang.String aKey, int anOrder)Creates a sort with the given key and order.
 
- 
 - 
Method Detail- 
getKeypublic java.lang.String getKey() Returns the key for this sort.
 - 
setKeypublic void setKey(java.lang.String aKey) Sets the key for this sort.
 - 
getOrderpublic int getOrder() Returns the order for this sort.
 - 
setOrderpublic void setOrder(int anOrder) Sets the order for this sort.
 - 
toggleOrderpublic void toggleOrder() Toggles the order for this sort between ORDER_ASCEND<->ORDER_DESCEND.
 - 
comparepublic int compare(java.lang.Object obj1, java.lang.Object obj2)Returns how the two given objects compare with this sort.- Specified by:
- comparein interface- java.util.Comparator
 
 - 
Comparepublic static int Compare(java.lang.Object anObj1, java.lang.Object anObj2)Compare two value objects (assumed to be String, Number, Boolean, Date, Comparable, etc.).
 - 
sortpublic static void sort(java.util.List aList, java.lang.String aKey)Returns the given list sorted by the given key.
 - 
sortpublic static void sort(java.util.List aList, Sort aSort)Returns the given list sorted by the given sort.
 - 
sortpublic static void sort(java.util.List aList, java.lang.String... theKeys)Returns the given list sorted by the given key.
 - 
sortpublic static void sort(java.util.List aList, Sort... theSorts)Returns the given list sorted by the given sort.
 - 
sortpublic static void sort(java.util.List aList, java.util.List aSortList)Returns the given list sorted by the given list of sorts.
 - 
sortedListpublic static <T extends java.lang.Comparable<? super T>> java.util.List<T> sortedList(java.util.Collection<T> aCollection) Returns a new sorted list from given collection.
 - 
sortedListpublic static <T> java.util.List<T> sortedList(java.util.Collection<T> aCollection, java.lang.String aKey)Returns a new list from the given list sorted by the given key.
 - 
sortedListpublic static <T> java.util.List<T> sortedList(java.util.Collection<T> aCollection, java.lang.String... theKeys)Returns a new list from the given list sorted by the given key.
 - 
clonepublic java.lang.Object clone() Standard clone implementation.- Overrides:
- clonein class- java.lang.Object
 
 - 
getJSONKeyspublic java.util.List<java.lang.String> getJSONKeys() RMJSONArchiver GetKeys method.- Specified by:
- getJSONKeysin interface- RMJSONArchiver.GetKeys
 
 - 
equalspublic boolean equals(java.lang.Object anObj) Standard equals implementation.- Specified by:
- equalsin interface- java.util.Comparator
- Overrides:
- equalsin class- java.lang.Object
 
 - 
toStringpublic java.lang.String toString() Returns a string representation of sort (just the sort key).- Overrides:
- toStringin class- java.lang.Object
 
 
- 
 
-