Class Sorting


  • public final class Sorting
    extends Object
    Methods for comparing and sorting.
    Author:
    David B. Bracewell
    • Method Detail

      • natural

        public static <E> SerializableComparator<E> natural()
        Natural serializable comparator.
        Type Parameters:
        E - the type parameter
        Returns:
        the serializable comparator
      • compare

        public static int compare​(Object o1,
                                  Object o2)
        Generic method for comparing to objects that is null safe. Assumes that the objects are Comparable.
        Parameters:
        o1 - the first object
        o2 - the second object
        Returns:
        the comparison result
        Throws:
        IllegalArgumentException - if the objects are non-null and not comparable
      • hashCodeComparator

        public static <T> SerializableComparator<T> hashCodeComparator()
        Compares two objects based on their hashcode.
        Type Parameters:
        T - the type of object being compared
        Returns:
        A simplistic comparator that compares hash code values