Package 

Object ComparatorContract


  • 
    public class ComparatorContract
    
                        

    Tests the various properties the Comparable contract is supposed to uphold.

    • Method Summary

      Modifier and Type Method Description
      final static <T extends Any> Unit testComparator(T least1, T middle1, T greatest1, Comparator<T> comparator) Tests the various properties the Comparable contract is supposed to uphold.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • testComparator

         final static <T extends Any> Unit testComparator(T least1, T middle1, T greatest1, Comparator<T> comparator)

        Tests the various properties the Comparable contract is supposed to uphold. Also tests that the behavior of compareTo() is compatible with equals() and hashCode() which is strongly suggested, but not actually required, but keeps things much simpler (your class will behave the same way in a sorted and unsorted set or map).

        It's safest to also make your comparator serializable. Instead of a static class, use an enum singleton. If your comparator must be instantiated with parameters, ensure that it is serializable, for instance with Serialization.serializeDeserialize before passing it to this method.

        Expects three unique objects. The first must be less than the second, which in turn is less than the third.

        See note in class documentation.