- java.lang.Object
-
- org.tentackle.common.Compare
-
public class Compare extends java.lang.ObjectSome handy static methods to compare two Comparables even if one or both are null-pointers.- Author:
- harald
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Comparable<? super T>>
intcompare(T o1, T o2)Compares two objects.
nullis being treated as smallest value.static <T extends java.lang.Comparable<? super T>>
intcompareWithNullLargest(T o1, T o2)Compares two objects.
nullis being treated as largest value.
-
-
-
Method Detail
-
compare
public static <T extends java.lang.Comparable<? super T>> int compare(T o1, T o2)Compares two objects.
nullis being treated as smallest value.Notice the different semantics compared to
Objects.compare(java.lang.Object, java.lang.Object, java.util.Comparator)for null-values.- Type Parameters:
T- the class type- Parameters:
o1- the first objecto2- 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 java.lang.Comparable<? super T>> int compareWithNullLargest(T o1, T o2)Compares two objects.
nullis being treated as largest value.- Type Parameters:
T- the class type- Parameters:
o1- the first objecto2- the second object- Returns:
- a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2.
-
-