de.fu_berlin.ties.util
Class InvertedComparator

java.lang.Object
  extended byde.fu_berlin.ties.util.InvertedComparator
All Implemented Interfaces:
Comparator

public class InvertedComparator
extends Object
implements Comparator

Compares objects, inverting either their natural order or the order of a wrapped comparator. This means that number objects will be sorted in decreasing order etc.

Version:
$Revision: 1.3 $, $Date: 2004/03/29 07:50:40 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
InvertedComparator()
          Creates a new instance, inverting the natural order of objects.
InvertedComparator(Comparator wrappedComp)
          Creates a new instance, inverting the order returned by the provided comparator.
 
Method Summary
 int compare(Object o1, Object o2)
          Compares its two arguments for order.
 Comparator getWrappedComparator()
          Returns the comparator wrapped and inverted by this instance; or null if the natural order of objects is inverted.
 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()
Creates a new instance, inverting the natural order of objects.


InvertedComparator

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

Parameters:
wrappedComp - the comparator to wrap and invert; or null if the natural order of objects should be inverted
Method Detail

compare

public int compare(Object o1,
                   Object o2)
            throws ClassCastException
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
Parameters:
o1 - the first object to be compared
o2 - the second object to be compared
Returns:
the inverted ordering of the arguments, if they can be compared with each other
Throws:
ClassCastException - if the arguments' types prevent them from being compared

getWrappedComparator

public Comparator getWrappedComparator()
Returns the comparator wrapped and inverted by this instance; or null if the natural order of objects is inverted.

Returns:
the value of the attribute

toString

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

Returns:
a textual representation


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