net.sf.molae.pipe.sorted
Class ComparatorUtil

java.lang.Object
  |
  +--net.sf.molae.pipe.sorted.ComparatorUtil

public final class ComparatorUtil
extends Object

Utility methods for Comparators.


Method Summary
static boolean areEqual(Object o1, Object o2)
          Checks the specified objects for equality.
static int compare(Object o1, Object o2, Comparator c)
          Compares two objects using the specified comparator.
static boolean isSorted(Iterator it, Comparator comparator)
          Checks if the specified iterator is in sorted order of the specified comparator.
static Object max(Object o1, Object o2)
          Compares the two specified objects and returns the greater one.
static Object max(Object o1, Object o2, Comparator comparator)
          Compares the two specified objects and returns the greater one.
static Object min(Object o1, Object o2)
          Compares the two specified objects and returns the smaller one.
static Object min(Object o1, Object o2, Comparator comparator)
          Compares the two specified objects and returns the smaller one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

areEqual

public static boolean areEqual(Object o1,
                               Object o2)
Checks the specified objects for equality. The objects are also considered equal if they are both null.
Parameters:
o1 - first object to compare
o2 - second object to compare
Returns:
true iff both objects are null or both objects are equal.

compare

public static int compare(Object o1,
                          Object o2,
                          Comparator c)
Compares two objects using the specified comparator.
Parameters:
o1 - first object to compare
o2 - second object to compare
c - comparator to use for comparison or null if natural ordering is used
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
Throws:
ClassCastException - if o1 and o2 cannot be compared to one another using the comparator (or, if it is null, using natural ordering).
NullPointerException - if o1 or o2 is null and natural order is used, or if the comparator does not tolerate null elements.

max

public static Object max(Object o1,
                         Object o2,
                         Comparator comparator)
Compares the two specified objects and returns the greater one.
Parameters:
o1 - first object to compare
o2 - second object to compare
comparator - comparator to use for comparison or null if natural ordering is used
Returns:
The maximum of o1 and o2. If both are equal, o1 is returned.
Throws:
ClassCastException - if o1 and o2 cannot be compared to one another using the comparator (or, if it is null, using natural ordering).
NullPointerException - if o1 or o2 is null and natural order is used, or if the comparator does not tolerate null elements.

min

public static Object min(Object o1,
                         Object o2,
                         Comparator comparator)
Compares the two specified objects and returns the smaller one.
Parameters:
o1 - first object to compare
o2 - second object to compare
comparator - comparator to use for comparison or null if natural ordering is used
Returns:
The minimum of o1 and o2. If both are equal, o1 is returned.
Throws:
ClassCastException - if o1 and o2 cannot be compared to one another using the comparator (or, if it is null, using natural ordering).
NullPointerException - if o1 or o2 is null and natural order is used, or if the comparator does not tolerate null elements.

max

public static Object max(Object o1,
                         Object o2)
Compares the two specified objects and returns the greater one.
Parameters:
o1 - first object to compare
o2 - second object to compare
Returns:
The maximum of o1 and o2. If both are equal, o1 is returned.
Throws:
ClassCastException - if o1 and o2 cannot be compared to one another.
NullPointerException - if o1 or o2 is null.

min

public static Object min(Object o1,
                         Object o2)
Compares the two specified objects and returns the smaller one.
Parameters:
o1 - first object to compare
o2 - second object to compare
Returns:
The minimum of o1 and o2. If both are equal, o1 is returned.
Throws:
ClassCastException - if o1 and o2 cannot be compared to one another.
NullPointerException - if o1 or o2 is null.

isSorted

public static boolean isSorted(Iterator it,
                               Comparator comparator)
Checks if the specified iterator is in sorted order of the specified comparator.
Parameters:
it - iterator to be examined
comparator - comparator to use for comparison or null if natural ordering is used
Returns:
true if the specified iterator is in sorted order of the specified comparator.
Throws:
ClassCastException - if the elements of the iterator cannont be compared to one another using. the comparator (or, if it is null, using natural ordering).
NullPointerException - the iterator contains a null element and natural order is used, or if the comparator does not tolerate null elements.