net.rim.device.api.util
Interface Comparator

All Known Implementing Classes:
LongKeyProviderAdaptorComparator, LDAPComparator, InvertedOrderComparator, StringComparator

public interface Comparator

Defines comparison methods useable to impose a total ordering on a collection of objects.

The ordering you can produce with these methods is the class's natural ordering, and the class's implementation of compare is its natural comparison method.


Method Summary
 int compare(Object o1, Object o2)
          Compares two arguments for order.
 boolean equals(Object obj)
          Determines if provided object is equal to this one.
 



Method Detail

compare

int compare(Object o1,
            Object o2)
Compares two arguments for order.

Parameters:
o1 - First object to compare.
o2 - Second object to compare.
Returns:
A Negative integer if the first object is 'less than' the second; a positive integer if the first object is 'greater than' the second; zero if the two objects are 'equal'.
Throws:
ClassCastException - If this comparator cannot compare the two objects.

equals

boolean equals(Object obj)
Determines if provided object is equal to this one.

This method must obey the general contract of Object.equals(Object).

Additionally, this method can return true only if the provided object also implements this interface and imposes the same ordering as this comparator. Thus, comp1.equals(comp2) implies that sgn(comp1.compare(o1, o2))==sgn(comp2.compare(o1, o2)) for every object reference o1 and o2.

Note that it is always safe not to override Object.equals(Object). However, overriding this method may, in some cases, improve performance by allowing programs to determine that two distinct comparators impose the same order.

Overrides:
equals in class Object
Parameters:
obj - Object to compare with this comparator.
Returns:
True if your provided object is also a comparator and imposes the same ordering as this comparator.
See Also:
Boolean.hashCode(), Hashtable





Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.