|
Orbital library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object orbital.util.ReverseComparator
public class ReverseComparator
This class is a ReverseComparator which imposes the reverse order on a collection of objects.
Depending on whether a Comparator to be reverted is given, the ordering induced by that Comparator will be reverted. Otherwise, the natural ordering will be reverted - as Collections.revertOrder() does - supposing that the objects in the collection implement the Comparable interface.
This corresponds roughly to a negation of a comparator (except for the case of equality).
Collections.reverseOrder()
,
Serialized FormField Summary | |
---|---|
protected java.util.Comparator |
inner
Contains the Comparator to be inverted, or null
if the objects Comparable implementation should be used, instead. |
Constructor Summary | |
---|---|
ReverseComparator()
Create a Comparator that is the opposite to the natural ordering induced by the Comparable implementation of the objects compared. |
|
ReverseComparator(java.util.Comparator inner)
Create a Comparator that is the opposite to an ordering induced by a given one. |
Method Summary | |
---|---|
int |
compare(java.lang.Object o1,
java.lang.Object o2)
Compares two objects. |
boolean |
equals(java.lang.Object obj)
|
int |
hashCode()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Comparator inner
null
if the objects Comparable implementation should be used, instead.
Constructor Detail |
---|
public ReverseComparator(java.util.Comparator inner)
inner
- the Comparator to be inverted, or null
if the objects Comparable implementation should be used, instead.public ReverseComparator()
Method Detail |
---|
public int compare(java.lang.Object o1, java.lang.Object o2)
compare
in interface java.util.Comparator
inner!=null
, then this method returns inner.compare(o2,o1)
.
If inner==null
and if one of the objects (preferably o1) is Comparable, -((Comparable)on).compareTo(om)
is returned.
If no comparator is specified and none of the objects implements Comparable, an exception is thrown.
java.lang.ClassCastException
- if Comparator inner==null
and both, o1 and o2 do not implement Comparable.public boolean equals(java.lang.Object obj)
equals
in interface java.util.Comparator
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
|
Orbital library 1.3.0: 11 Apr 2009 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |