Package gov.usgs.earthquake.util
Class CompareUtil
java.lang.Object
gov.usgs.earthquake.util.CompareUtil
Utility class for comparing potentially null values.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
intnullSafeCompare
(T a, T b) A method to simplify comparison of two values, either of which may be null.
-
Constructor Details
-
CompareUtil
public CompareUtil()
-
-
Method Details
-
nullSafeCompare
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).
-