javax.baja.nre.util
Class SortUtil

java.lang.Object
  extended byjavax.baja.nre.util.SortUtil

public class SortUtil
extends java.lang.Object

Sorting utilities.


Field Summary
static java.util.Comparator ASCENDING
          Comparator that uses SortUtil.compare().
static java.util.Comparator DESCENDING
          Comparator that uses reverse of SortUtil.compare().
 
Constructor Summary
SortUtil()
           
 
Method Summary
static int compare(java.lang.Object v1, java.lang.Object v2)
          Compare two objects.
static void rsort(java.lang.Object[] values)
          Convenience for sort(values, values, DESCENDING).
static void rsort(java.lang.Object[] keys, java.lang.Object[] values)
          Convenience for sort(keys, values, DESCENDING).
static void sort(java.lang.Object[] values)
          Convenience for sort(values, values, ASCENDING).
static void sort(java.lang.Object[] keys, java.lang.Object[] values)
          Convenience for sort(keys, values, ASCENDING).
static void sort(java.lang.Object[] keys, java.lang.Object[] values, boolean ascending)
          Convenience for sort(keys, values, ascending ? ASCENDING : DESCENDING).
static void sort(java.lang.Object[] keys, java.lang.Object[] values, java.util.Comparator comparator)
          Given a an array of keys and values, perform an in place sort using the given Comparator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ASCENDING

public static final java.util.Comparator ASCENDING
Comparator that uses SortUtil.compare().


DESCENDING

public static final java.util.Comparator DESCENDING
Comparator that uses reverse of SortUtil.compare().

Constructor Detail

SortUtil

public SortUtil()
Method Detail

sort

public static void sort(java.lang.Object[] values)
Convenience for sort(values, values, ASCENDING).


rsort

public static void rsort(java.lang.Object[] values)
Convenience for sort(values, values, DESCENDING).


sort

public static void sort(java.lang.Object[] keys,
                        java.lang.Object[] values)
Convenience for sort(keys, values, ASCENDING).


rsort

public static void rsort(java.lang.Object[] keys,
                         java.lang.Object[] values)
Convenience for sort(keys, values, DESCENDING).


sort

public static void sort(java.lang.Object[] keys,
                        java.lang.Object[] values,
                        boolean ascending)
Convenience for sort(keys, values, ascending ? ASCENDING : DESCENDING).


sort

public static void sort(java.lang.Object[] keys,
                        java.lang.Object[] values,
                        java.util.Comparator comparator)
Given a an array of keys and values, perform an in place sort using the given Comparator. The indices of the keys and values array should correspond. Both the keys and values array will be modified to reflect the results of the sort. The keys and values parameters may reference the same array.


compare

public static int compare(java.lang.Object v1,
                          java.lang.Object v2)
Compare two objects. The two objects should be of the same class. If the objects implement the Comparable interface then that is how they are compared. If not then the results of their toString() methods are used for the comparision. This method works with null values, where null objects are less than non-null objects.

Returns:
a negative integer, zero, or a positive integer as v1 is less than, equal to, or greater than the v2.