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 Details

  • Constructor Details

    • RMSort

      public RMSort()
      Creates a plain sort with no key. Used for unarchival, shouldn't be called directly.
    • RMSort

      public RMSort(String aKey)
      Creates a sort with the given key and ORDER_ASCEND.
    • RMSort

      public RMSort(String aKey, int anOrder)
      Creates a sort with the given key and order.
  • Method Details

    • getKey

      public String getKey()
      Returns the key for this sort.
    • setKey

      public void setKey(String aKey)
      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

      public String getOrderString()
      Returns the order as a string.
    • setOrderString

      public void setOrderString(String aString)
      Sets the order as a string.
    • toggleOrder

      public void toggleOrder()
      Toggles the order for this sort between ORDER_ASCEND<->ORDER_DESCEND.
    • compare

      public int compare(Object obj1, Object obj2)
      Returns how the two given objects compare with this sort.
      Specified by:
      compare in interface Comparator
    • Compare

      public static int Compare(Object anObj1, Object anObj2)
      Compare two value objects (assumed to be String, Number, Boolean, Date, Comparable, etc.).
    • sort

      public static void sort(List aList, String aKey)
      Returns the given list sorted by the given key.
    • sort

      public static void sort(List aList, RMSort aSort)
      Returns the given list sorted by the given sort.
    • sort

      public static void sort(List aList, String... theKeys)
      Returns the given list sorted by the given key.
    • sort

      public static void sort(List aList, RMSort... theSorts)
      Returns the given list sorted by the given sort.
    • sort

      public static void sort(List aList, List aSortList)
      Returns the given list sorted by the given list of sorts.
    • sortedList

      public static <T extends Comparable<? super T>> List<T> sortedList(Collection<T> aCollection)
      Returns a new sorted list from given collection.
    • sortedList

      public static <T> Vector<T> sortedList(Collection<T> aCollection, String aKey)
      Returns a new list from the given list sorted by the given key.
    • sortedList

      public static <T> Vector<T> sortedList(Collection<T> aCollection, String... theKeys)
      Returns a new list from the given list sorted by the given key.
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Specified by:
      equals in interface Comparator
      Overrides:
      equals in class Object
    • clone

      public Object clone()
      Standard clone implementation.
      Overrides:
      clone in class Object
    • getJSONKeys

      public List<String> getJSONKeys()
      RMJSONArchiver GetKeys method.
      Specified by:
      getJSONKeys in interface RMJSONArchiver.GetKeys
    • toXML

      public RXElement toXML(RXArchiver anArchiver)
      XML archival.
      Specified by:
      toXML in interface Archivable
    • fromXML

      public Object fromXML(RXArchiver anArchiver, RXElement anElement)
      XML unarchival.
      Specified by:
      fromXML in interface Archivable
    • toString

      public String toString()
      Returns a string representation of sort (just the sort key).
      Overrides:
      toString in class Object