ReportMill 7.0 API

com.reportmill.foundation
Class RMSort

java.lang.Object
  extended bycom.reportmill.foundation.RMObject
      extended bycom.reportmill.foundation.RMSort
All Implemented Interfaces:
java.lang.Cloneable, com.reportmill.foundation.RMArchiver.Archiving

public class RMSort
extends com.reportmill.foundation.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("title");
   RMSort bestRevenueFirst = new RMSort("revenue", ORDER_DESCEND);
 

This class also provides useful static methods for comparison and sorting:

   RMSort.sort(myList, "title"); // Sort myList by its contents' title method (alphabetically)
   RMSort.sort(myList, bestRevenueFirst); // Sort myList by its contents' revenue method (largest first)
   List mySortList = new ArrayList();
   mySortList.add(bestRevenueFirst);
   mySortList.add(titleFirst);
   RMSort.sort(myList, mySortList); // Sort myList by revenue and title
 


Nested Class Summary
static interface RMSort.Comparator
          Defines an interface for objects to implementation compare functionality.
static class RMSort.DefaultComparator
          Defines a default implementation of the Comparator interface to compare common object types.
 
Field Summary
static RMSort.DefaultComparator defaultComparator
           
static byte ORDER_ASCEND
           
static byte ORDER_DESCEND
           
static byte ORDER_SAME
           
 
Constructor Summary
RMSort()
          Creates a plain sort with no key.
RMSort(java.lang.String aKey)
          Creates a sort with the given key and ORDER_ASCEND.
RMSort(java.lang.String aKey, int anOrder)
          Creates a sort with the given key and order.
 
Method Summary
static int compare(java.lang.Object obj1, java.lang.Object obj2)
          Returns a description of how the given two objects compare in terms of order: ORDER_SAME, ORDER_ASCEND or ORDER_DESCEND.
 boolean equals(java.lang.Object anObj)
          Standard equals implementation.
 void flip()
          Deprecated - use getFlipped instead, RMSort should be immutable.
 java.lang.Object fromXML(com.ribs.RXArchiver anArchiver, com.ribs.RXElement anElement)
          XML unarchival.
 RMSort getFlipped()
          This method returns a sort with the same key but opposite order.
 java.lang.String getKey()
          This method returns the _key for this sort.
 int getOrder()
          This method returns the order for this sort.
 java.lang.Object initWithArchiver(com.reportmill.foundation.RMArchiver anArchiver)
          Legacy archival.
static java.util.List sort(java.util.List aList)
          Returns the given list sorted by RMSort's default comparator.
static java.util.List sort(java.util.List aList, java.util.List aSortList)
          Returns the given list sorted by the given list of sorts.
static java.util.List sort(java.util.List aList, java.lang.Object context)
          Returns the given list, sorted by RMSort's default comparator with the given context.
static java.util.List sort(java.util.List aList, RMSort.Comparator c, java.lang.Object context)
          Returns the given list sorted by a given RMSort Compartor with the given context.
static java.util.List sort(java.util.List aList, RMSort aSort)
          Returns the given list sorted by the given sort.
static java.util.List sort(java.util.List aList, java.lang.String aKey)
          Returns the given list sorted by the given key in ORDER_ASCEND.
static java.util.Vector sortedList(java.util.List aList, java.lang.String aKey)
          Returns a new list from the given list sorted by the given key in ORDER_ASCEND.
 com.ribs.RXElement toXML(com.ribs.RXArchiver anArchiver)
          XML archival.
 
Methods inherited from class com.reportmill.foundation.RMObject
archiverClassName, clone, copy, didChange, didUndo, getAnimAttribute, getClassNameShort, undoClone, undoCopy, undoEquals
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORDER_SAME

public static final byte ORDER_SAME
See Also:
Constant Field Values

ORDER_ASCEND

public static final byte ORDER_ASCEND
See Also:
Constant Field Values

ORDER_DESCEND

public static final byte ORDER_DESCEND
See Also:
Constant Field Values

defaultComparator

public static RMSort.DefaultComparator defaultComparator
Constructor Detail

RMSort

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


RMSort

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


RMSort

public RMSort(java.lang.String aKey,
              int anOrder)
Creates a sort with the given key and order.

Method Detail

getKey

public java.lang.String getKey()
This method returns the _key for this sort.


getOrder

public int getOrder()
This method returns the order for this sort.


getFlipped

public RMSort getFlipped()
This method 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(java.lang.Object obj1,
                          java.lang.Object obj2)
Returns a description of how the given two objects compare in terms of order: ORDER_SAME, ORDER_ASCEND or ORDER_DESCEND.


sortedList

public static java.util.Vector sortedList(java.util.List aList,
                                          java.lang.String aKey)
Returns a new list from the given list sorted by the given key in ORDER_ASCEND.


sort

public static java.util.List sort(java.util.List aList,
                                  java.lang.String aKey)
Returns the given list sorted by the given key in ORDER_ASCEND.


sort

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


sort

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


sort

public static java.util.List sort(java.util.List aList)
Returns the given list sorted by RMSort's default comparator.


sort

public static java.util.List sort(java.util.List aList,
                                  java.lang.Object context)
Returns the given list, sorted by RMSort's default comparator with the given context.


sort

public static java.util.List sort(java.util.List aList,
                                  RMSort.Comparator c,
                                  java.lang.Object context)
Returns the given list sorted by a given RMSort Compartor with the given context.


equals

public boolean equals(java.lang.Object anObj)
Standard equals implementation.


initWithArchiver

public java.lang.Object initWithArchiver(com.reportmill.foundation.RMArchiver anArchiver)
Legacy archival.


toXML

public com.ribs.RXElement toXML(com.ribs.RXArchiver anArchiver)
XML archival.


fromXML

public java.lang.Object fromXML(com.ribs.RXArchiver anArchiver,
                                com.ribs.RXElement anElement)
XML unarchival.


ReportMill 7.0 API