public static <T extends Comparable<T>> int compare(@Nullable T comparable1, @Nullable T comparable2) {
    if (comparable1 == null && comparable2 == null) return 0;
    if (comparable1 == null) return -1;
    if (comparable2 == null) return 1;
    return comparable1.compareTo(comparable2);
  }
Utility methods applicable to (almost) any object. Includes null-safe variants of methods on class Object.
spock-core/src/main/java/org/spockframework/util/ObjectUtil.java