public static < Value extends Comparable < Value > > int nullSafeCompare ( final Value first , final Value second ) { if ( first == null ) { return second == null ? EQUAL_COMPARE_RESULT : LOWER_THAN_COMPARE_RESULT ; } return second == null ? GREATER_THAN_COMPARE_RESULT : first . compareTo ( second ) ; }
Safely compares two values that might be null . Null value is considered lower than non - null even if the non - null value is minimal in its range .