Package gov.usgs.earthquake.util
Class CompareUtil
- java.lang.Object
-
- gov.usgs.earthquake.util.CompareUtil
-
public class CompareUtil extends java.lang.Object
Utility class for comparing potentially null values.
-
-
Constructor Summary
Constructors Constructor Description CompareUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Comparable<T>>
intnullSafeCompare(T a, T b)
A method to simplify comparison of two values, either of which may be null.
-
-
-
Method Detail
-
nullSafeCompare
public static <T extends java.lang.Comparable<T>> int nullSafeCompare(T a, T b)
A method to simplify comparison of two values, either of which may be null. For purposes of this comparison, null values are > non-null values.- Type Parameters:
T
- type- Parameters:
a
- value to compareb
- value to compare- Returns:
- -1, if a is not null and b is null; 0, if a is null and b is null; 1, if a is null and b is not null; otherwise, a.compareTo(b).
-
-