public static int compare(Comparable c1,Comparable c2,boolean nullGreater){
  if (c1 == c2) {
    return 0;
  }
 else   if (c1 == null) {
    return (nullGreater ? 1 : -1);
  }
 else   if (c2 == null) {
    return (nullGreater ? -1 : 1);
  }
  return c1.compareTo(c2);
}

public static int compare ( Comparable c1 , Comparable c2 , boolean nullGreater ) { if ( c1 == c2 ) { return 0 ; } else if ( c1 == null ) { return ( nullGreater ? 1 : - 1 ) ; } else if ( c2 == null ) { return ( nullGreater ? - 1 : 1 ) ; } return c1 . compareTo ( c2 ) ; }
null safe comparison of comparables .
