Monday, October 21, 2013

Comparable - some tips...

Tips :
 
                    -  The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C.


*******  Since null is not an instance of any class, and e.compateTo(null) should throw NullPointerException even though e.equals(null) returns false.

******* This interface is a member of the Java Collections Framework.

 - The implementor must ensure sign(x.compareTo(y)) == -sign(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.)

- It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y))

suppose returning value is 'v'.

value           meaning
v<0 dd="" is="" less="" nbsp="" obj="" specified="" than="" the="" this="">
0                 this obj is equal to specified obj,
v>0             this obj is greater than the specified obj


source: http://docs.oracle.com/javase/6/docs/api/java/lang/Comparable.html

No comments:

Post a Comment