Class CollectionComparator


  • public class CollectionComparator
    extends java.lang.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
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int compare​(java.util.Collection<? extends java.lang.Comparable> first, java.util.Collection<? extends java.lang.Comparable> second)
      Compare the arguments.
      • Methods inherited from class java.lang.Object

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

      • CollectionComparator

        public CollectionComparator()
    • Method Detail

      • compare

        public static int compare​(java.util.Collection<? extends java.lang.Comparable> first,
                                  java.util.Collection<? extends java.lang.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:
        java.lang.NullPointerException - if any of the arguments are null