com.unboundid.util
Class ReverseComparator<T>

java.lang.Object
  extended by com.unboundid.util.ReverseComparator<T>
Type Parameters:
T - The type of object to use with this comparator.
All Implemented Interfaces:
java.io.Serializable, java.util.Comparator<T>

@NotMutable
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class ReverseComparator<T>
extends java.lang.Object
implements java.util.Comparator<T>, java.io.Serializable

This class provides an implementation of a Comparator object that may be used to iterate through values in what would normally be considered reverse order.

See Also:
Serialized Form

Constructor Summary
ReverseComparator()
          Creates a new comparator that will sort items in reverse order.
ReverseComparator(java.util.Comparator<T> baseComparator)
          Creates a new comparator that will sort items in the reverse order that they would be normally sorted using the given comparator.
 
Method Summary
 int compare(T o1, T o2)
          Compares the provided objects to determine their relative order in a sorted list.
 boolean equals(java.lang.Object o)
          Indicates whether the provided object may be considered equal to this comparator.
 int hashCode()
          Retrieves a hash code for this class.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReverseComparator

public ReverseComparator()
Creates a new comparator that will sort items in reverse order. The generic type for this class must implement the Comparable interface.


ReverseComparator

public ReverseComparator(java.util.Comparator<T> baseComparator)
Creates a new comparator that will sort items in the reverse order that they would be normally sorted using the given comparator.

Parameters:
baseComparator - The base comparator that will be used to make the determination.
Method Detail

compare

public int compare(T o1,
                   T o2)
Compares the provided objects to determine their relative order in a sorted list.

Specified by:
compare in interface java.util.Comparator<T>
Parameters:
o1 - The first object to compare.
o2 - The second object to compare.
Returns:
A negative integer if the first object should be ordered before the second, a positive integer if the first object should be ordered after the second, or zero if there is no difference in their relative orders.

hashCode

public int hashCode()
Retrieves a hash code for this class.

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code for this class.

equals

public boolean equals(java.lang.Object o)
Indicates whether the provided object may be considered equal to this comparator.

Specified by:
equals in interface java.util.Comparator<T>
Overrides:
equals in class java.lang.Object
Parameters:
o - The object for which to make the determination.
Returns:
true if the provided object may be considered equal to this comparator, or false if not.