public static int compareAllowNull ( final Comparable c1 , final Comparable c2 ) { if ( c1 == null && c2 == null ) { return 0 ; } else if ( c1 == null ) { return - 1 ; } else if ( c2 == null ) { return 1 ; } else { return c1 . compareTo ( c2 ) ; } }
Compares two comparable objects where either may be null . Null is regarded as the smallest value and 2 nulls are considered equal .