Class RMSort

All Implemented Interfaces:
RMArchiver.Archiving, Cloneable

public class RMSort extends RMObject
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.
    • getOrder

      public int getOrder()
      Returns the order for this sort.
    • getFlipped

      public RMSort getFlipped()
      Returns a sort with the same key but opposite order.
    • flip

      public void flip()
      Deprecated - use getFlipped instead, RMSort should be immutable.
    • compare

      public static int compare(Object obj1, Object obj2, RMSort aSort)
      Compare objects with given RMSort.
    • compare

      public static int compare(Object obj1, Object obj2, List aSortList)
      Compare objects with given list of RMSorts.
    • compare

      public static int compare(Object obj1, Object obj2)
      Compare two value objects (assumed to be String, Numer, Boolean, Date, Comparable, etc.).
    • sort

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

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

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

      public static Vector sortedList(List aList, String aKey)
      Returns a new list from the given list sorted by the given key.
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class Object
    • toString

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

      public RXElement toXML(RXArchiver anArchiver)
      XML archival.
    • fromXML

      public Object fromXML(RXArchiver anArchiver, RXElement anElement)
      XML unarchival.
    • initWithArchiver

      public Object initWithArchiver(RMArchiver anArchiver)
      Legacy unarchival.
      Specified by:
      initWithArchiver in interface RMArchiver.Archiving
      Overrides:
      initWithArchiver in class RMObject