org.apache.commons.collections.comparators
Class ComparableComparator
java.lang.Object
|
+--org.apache.commons.collections.comparators.ComparableComparator
- All Implemented Interfaces:
- Comparator, Serializable
- public class ComparableComparator
- extends Object
- implements Comparator, Serializable
A Comparator that compares Comparable objects.
Throws ClassCastExceptions if the objects are not
Comparable, or if they are null.
Throws ClassCastException if the compareTo of both
objects do not provide an inverse result of each other
as per the Comparable javadoc. This Comparator is useful, for example,
for enforcing the natural order in custom implementations
of SortedSet and SortedMap.
- Since:
- 2.0
- Version:
- $Id: ComparableComparator.java,v 1.5 2002/06/12 03:59:17 mas Exp $
- Author:
- bayard@generationjava.com
- See Also:
- Serialized Form
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ComparableComparator
public ComparableComparator()
compare
public int compare(Object o1,
Object o2)
- Specified by:
compare
in interface Comparator
getInstance
public static ComparableComparator getInstance()
- Return a shared instance of a ComparableComparator. Developers are
encouraged to use the comparator returned from this method instead of
constructing a new instance to reduce allocation and GC overhead when
multiple comparable comparators may be used in the same VM.
Copyright © 2001-2002 Apache Software Foundation. Documenation generated February 22 2003.