org.tentackle.util
Class Compare

java.lang.Object
  extended by org.tentackle.util.Compare

public class Compare
extends Object

Some handy static methods to compare two Comparables even if one or both are null-pointers.

Author:
harald

Constructor Summary
Compare()
           
 
Method Summary
static
<T extends Comparable<? super T>>
int
compare(T o1, T o2)
          Compares two objects.
null is being treated as smallest value.
static int compareLong(long val1, long val2)
          Compares two long integers.
Notice when checking object-ids: make sure that values are provided from getId() because deleted objects change their id (negate), but don't change their identity!
static
<T extends Comparable<? super T>>
int
compareWithNullLargest(T o1, T o2)
          Compares two objects.
null is being treated as largest value.
static boolean equals(Object o1, Object o2)
          Checks whether two objects are equal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Compare

public Compare()
Method Detail

compare

public static <T extends Comparable<? super T>> int compare(T o1,
                                                            T o2)
Compares two objects.
null is being treated as smallest value.

Type Parameters:
T - the class type
Parameters:
o1 - the first object
o2 - the second object
Returns:
a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2.

compareWithNullLargest

public static <T extends Comparable<? super T>> int compareWithNullLargest(T o1,
                                                                           T o2)
Compares two objects.
null is being treated as largest value.

Type Parameters:
T - the class type
Parameters:
o1 - the first object
o2 - the second object
Returns:
a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2.

equals

public static boolean equals(Object o1,
                             Object o2)
Checks whether two objects are equal.

Parameters:
o1 - the first object
o2 - the second object
Returns:
true if objects are equal.

compareLong

public static int compareLong(long val1,
                              long val2)
Compares two long integers.
Notice when checking object-ids: make sure that values are provided from getId() because deleted objects change their id (negate), but don't change their identity!

Parameters:
val1 - the first value
val2 - the second value
Returns:
a -1, 0, or +1 integer as val1 is less than, equal to, or greater than val2.


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de