de.fu_berlin.ties.util
Class InvertedComparator<T>

java.lang.Object
  extended by de.fu_berlin.ties.util.InvertedComparator<T>
All Implemented Interfaces:
Comparator<T>

public class InvertedComparator<T>
extends Object
implements Comparator<T>

Compares objects, inverting the order of a wrapped comparator. This means that numeric objects will be sorted in decreasing order etc.

Version:
$Revision: 1.5 $, $Date: 2004/09/07 10:01:37 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
InvertedComparator(Comparator<T> wrappedComp)
          Creates a new instance, inverting the order returned by the provided comparator.
 
Method Summary
 int compare(T o1, T o2)
          Compares its two arguments for order.
 Comparator getWrappedComparator()
          Returns the comparator wrapped and inverted by this instance.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

InvertedComparator

public InvertedComparator(Comparator<T> wrappedComp)
Creates a new instance, inverting the order returned by the provided comparator.

Parameters:
wrappedComp - the comparator to wrap and invert; must not be null
Method Detail

compare

public int compare(T o1,
                   T o2)
Compares its two arguments for order. Inverts the natural ordering of the two arguments resp. if order of the wrapped comparator, if any. So this method returns a negative integer, zero, or a positive integer as the first argument is greater than, equal to, or less than the second.

Specified by:
compare in interface Comparator<T>
Parameters:
o1 - the first object to be compared
o2 - the second object to be compared
Returns:
the inverted ordering of the arguments

getWrappedComparator

public Comparator getWrappedComparator()
Returns the comparator wrapped and inverted by this instance.

Returns:
the value of the attribute

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a textual representation


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.