org.apache.commons.collections.comparators

Class ComparableComparator

Implemented Interfaces:
Comparator, Serializable

public class ComparableComparator
extends java.lang.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.
Version:
$Id: ComparableComparator.java,v 1.5.2.1 2004/05/22 12:14:04 scolebourne Exp $
Author:
bayard@generationjava.com
Since:
2.0

Constructor Summary

ComparableComparator()

Method Summary

int
compare(Object o1, Object o2)
static ComparableComparator
getInstance()
Return a shared instance of a ComparableComparator.

Constructor Details

ComparableComparator

public ComparableComparator()

Method Details

compare

public int compare(Object o1,
                   Object o2)

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-2004 Apache Software Foundation. Documenation generated ${TODAY}.