Class CollectionComparator


  • public class CollectionComparator
    extends Object
    Utility class which is useful when implementing Comparable and one needs to compare Collections of Comparables as instance variables.
    Author:
    Einar M R Rosenvinge
    • Constructor Detail

      • CollectionComparator

        public CollectionComparator()
    • Method Detail

      • compare

        public static int compare​(Collection<? extends Comparable> first,
                                  Collection<? extends Comparable> second)
        Compare the arguments. Shorter Collections are always considered smaller than longer Collections. For Collections of equal lengths, the elements are compared one-by-one. Whenever two corresponding elements in the two Collections are non-equal, the method returns. If all elements at corresponding positions in the two Collections are equal, the Collections are considered equal.
        Parameters:
        first - a Collection of Comparables to be compared
        second - a Collection of Comparables to be compared
        Returns:
        0 if the arguments are equal, -1 if the first argument is smaller, 1 if the second argument is smaller
        Throws:
        NullPointerException - if any of the arguments are null