Class 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>>
      int
      nullSafeCompare​(T a, T b)
      A method to simplify comparison of two values, either of which may be null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CompareUtil

        public CompareUtil()
    • 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 compare
        b - 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).