Oracle Application Development Framework Model and Business Components Java API Reference 10g Release 3 (10.1.3)
B16005-01


oracle.jbo.server.java.util
Interface Comparable


public interface Comparable

This interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class's natural ordering, and the class's compareTo function is referred to as its natural comparison method.

Arrays of Objects that implement this interface can be sorted automatically by List.sort. Objects of these classes can also be used as keys in TreeTables without the need to specify a Comparator.

Classes that implement this interface include String, Byte, Character, Short, Integer, Long, Float, Double, BigInteger, BigDecimal, File, URL, Date.

See Also:
Comparator, Arrays.sort(Object[], Comparator)

Method Summary
 int compareTo(java.lang.Object o)
          Compares this Object with the specified Object for order.

 

Method Detail

compareTo

public int compareTo(java.lang.Object o)
Compares this Object with the specified Object for order. Returns a negative integer, zero, or a positive integer as this Object is less than, equal to, or greater than the given Object.

The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.

The implementer must also ensure that x.equals(y) implies that x.compareTo(y)==0. Note that the converse is not necessarily true (e.g., BigDecimal).

Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.

Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this Object is less than, equal to, or greater than the given Object.
Throws:
java.lang.ClassCastException - the specified Object's type prevents it from being compared to this Object.
Since:
JDK1.2

Oracle Application Development Framework Model and Business Components Java API Reference 10g Release 3 (10.1.3)
B16005-01


Copyright © 1997, 2005, Oracle. All rights reserved.