ToEnumNullableImpl implements ToEnumNullable<T, E> { @Override public int compare(T first, T second) { final E f = apply(first); final E s = apply(second); if (f == null && s == null) { return 0; } else if (f == null) { return 1; } else if (s == null) { return -1; } else { return Integer.compare(f.ordinal(), s.ordinal()); } } ToEnumNullableImpl(Class<E> enumClass, Function<T, E> inner); @Override Class<E> enumClass(); @Override E apply(T t); @Override ToIntNullable<T> asOrdinal(); @Override ToStringNullable<T> asName(); @Override long hash(T object); @Override int compare(T first, T second);  }
@Test void compare() { final Pair<String, String> pair1 = new Pair<>(null, null); final Pair<String, String> pair2 = new Pair<>("FIRST", null); final Pair<String, String> pair3 = new Pair<>(null, "FIRST"); final Pair<String, String> pair4 = new Pair<>("SECOND", "SECOND"); assertEquals(0, instance.compare(pair1.getFirst(), pair1.getSecond())); assertEquals(-1, instance.compare(pair2.getFirst(), pair2.getSecond())); assertEquals(1, instance.compare(pair3.getFirst(), pair3.getSecond())); assertEquals(0, instance.compare(pair4.getFirst(), pair4.getSecond())); }