ReportMill 11 API

com.reportmill.base
Class RMSort

java.lang.Object
  extended by com.reportmill.base.RMSort
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator

public class RMSort
extends java.lang.Object
implements java.util.Comparator, java.lang.Cloneable

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
static java.util.Comparator COMPARATOR
           
static byte ORDER_ASCEND
           
static byte ORDER_DESCEND
           
static byte ORDER_INDETERMINATE
           
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
 java.lang.Object clone()
          Standard clone implementation.
 int compare(java.lang.Object obj1, java.lang.Object obj2)
          Returns how the two given objects compare with this sort.
static int Compare(java.lang.Object obj1, java.lang.Object obj2)
          Compare two value objects (assumed to be String, Number, Boolean, Date, Comparable, etc.).
 boolean equals(java.lang.Object anObj)
          Standard equals implementation.
 java.lang.Object fromXML(com.reportmill.archiver.RXArchiver anArchiver, com.reportmill.archiver.RXElement anElement, java.lang.Object anOwner)
          XML unarchival.
 java.lang.String getKey()
          Returns the key for this sort.
 int getOrder()
          Returns the order for this sort.
 java.lang.String getOrderString()
          Returns the order as a string.
 void setKey(java.lang.String aKey)
          Sets the key for this sort.
 void setOrder(int anOrder)
          Sets the order for this sort.
 void setOrderString(java.lang.String aString)
          Sets the order as a string.
static void sort(java.util.List aList, java.util.List aSortList)
          Returns the given list sorted by the given list of sorts.
static void sort(java.util.List aList, RMSort aSort)
          Returns the given list sorted by the given sort.
static void sort(java.util.List aList, java.lang.String aKey)
          Returns the given list sorted by the given key.
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.Vector<T>
sortedList(java.util.Collection<T> aCollection, java.lang.String aKey)
          Returns a new list from the given list sorted by the given key.
 void toggleOrder()
          Toggles the order for this sort between ORDER_ASCEND<->ORDER_DESCEND.
 java.lang.String toString()
          Returns a string representation of sort (just the sort key).
 com.reportmill.archiver.RXElement toXML(com.reportmill.archiver.RXArchiver anArchiver, java.lang.Object anOwner)
          XML archival.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, 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

ORDER_INDETERMINATE

public static final byte ORDER_INDETERMINATE
See Also:
Constant Field Values

COMPARATOR

public static java.util.Comparator COMPARATOR
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()
Returns the key for this sort.


setKey

public void setKey(java.lang.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.


getOrderString

public java.lang.String getOrderString()
Returns the order as a string.


setOrderString

public void setOrderString(java.lang.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(java.lang.Object obj1,
                   java.lang.Object obj2)
Returns how the two given objects compare with this sort.

Specified by:
compare in interface java.util.Comparator

Compare

public static int Compare(java.lang.Object obj1,
                          java.lang.Object obj2)
Compare two value objects (assumed to be String, Number, Boolean, Date, Comparable, etc.).


sort

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


sort

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


sort

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


sortedList

public 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.


sortedList

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


equals

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

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class java.lang.Object

clone

public java.lang.Object clone()
Standard clone implementation.

Overrides:
clone in class java.lang.Object

toXML

public com.reportmill.archiver.RXElement toXML(com.reportmill.archiver.RXArchiver anArchiver,
                                               java.lang.Object anOwner)
XML archival.


fromXML

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


toString

public java.lang.String toString()
Returns a string representation of sort (just the sort key).

Overrides:
toString in class java.lang.Object

ReportMill 11 API