base/common/src/main/com/thesett/common/util/LexicographicalCollectionComparator.java
public int compare(Collection<T> c1, Collection<T> c2)
    {
        // Simultaneously iterator over both collections until one runs out.
        Iterator<T> i1 = c1.iterator();
        Iterator<T> i2 = c2.iterator();

        while (i1.hasNext() && i2.hasNext())
        {
            T t1 = i1.next();
            T t2 = i2.next();

            // Compare t1 and t2.
            int comp = comparator.compare(t1, t2);

            // Check if t1 < t2 in which case c1 < c2.
            if (comp < 0)
            {
                return -1;
            }

            // Check if t2 < t1 in which case c2 < c1.
            else if (comp > 0)
            {
                return 1;
            }

            // Otherwise t1 = t2 in which case further elements must be examined in order to determine the ordering.
        }

        // If this point is reached then one of the collections ran out of elements before the ordering was determined.

        // Check if c1 ran out and c2 still has elements, in which case c1 < c2.
        if (!i1.hasNext() && i2.hasNext())
        {
            return -1;
        }

        // Check if c2 ran out and c1 still has elements, in which case c2 < c1.
        if (i1.hasNext() && !i2.hasNext())
        {
            return 1;
        }

        // Otherwise both ran out in which case c1 = c2.
        return 0;
    }
public int compare(Collection<T> c1, Collection<T> c2)
    {
        // Simultaneously iterator over both collections until one runs out.
        Iterator<T> i1 = c1.iterator();
        Iterator<T> i2 = c2.iterator();

        while (i1.hasNext() && i2.hasNext())
        {
            T t1 = i1.next();
            T t2 = i2.next();

            // Compare t1 and t2.
            int comp = comparator.compare(t1, t2);

            // Check if t1 < t2 in which case c1 < c2.
            if (comp < 0)
            {
                return -1;
            }

            // Check if t2 < t1 in which case c2 < c1.
            else if (comp > 0)
            {
                return 1;
            }

            // Otherwise t1 = t2 in which case further elements must be examined in order to determine the ordering.
        }

        // If this point is reached then one of the collections ran out of elements before the ordering was determined.

        // Check if c1 ran out and c2 still has elements, in which case c1 < c2.
        if (!i1.hasNext() && i2.hasNext())
        {
            return -1;
        }

        // Check if c2 ran out and c1 still has elements, in which case c2 < c1.
        if (i1.hasNext() && !i2.hasNext())
        {
            return 1;
        }

        // Otherwise both ran out in which case c1 = c2.
        return 0;
    }
public int compare ( Collection < T > c1 , Collection < T > c2 ) { // Simultaneously iterator over both collections until one runs out. Iterator < T > i1 = c1 . iterator ( ) ; Iterator < T > i2 = c2 . iterator ( ) ; while ( i1 . hasNext ( ) && i2 . hasNext ( ) ) { T t1 = i1 . next ( ) ; T t2 = i2 . next ( ) ; // Compare t1 and t2. int comp = comparator . compare ( t1 , t2 ) ; // Check if t1 < t2 in which case c1 < c2. if ( comp < 0 ) { return - 1 ; } // Check if t2 < t1 in which case c2 < c1. else if ( comp > 0 ) { return 1 ; } // Otherwise t1 = t2 in which case further elements must be examined in order to determine the ordering. } // If this point is reached then one of the collections ran out of elements before the ordering was determined. // Check if c1 ran out and c2 still has elements, in which case c1 < c2. if ( ! i1 . hasNext ( ) && i2 . hasNext ( ) ) { return - 1 ; } // Check if c2 ran out and c1 still has elements, in which case c2 < c1. if ( i1 . hasNext ( ) && ! i2 . hasNext ( ) ) { return 1 ; } // Otherwise both ran out in which case c1 = c2. return 0 ; }
Compares two collections using lexicographic ordering based on a comparator of their elements.

@param  c1 The first collection to compare.
@param  c2 The second collection to compare.

@return A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater
than the second.
Compares two collections using lexicographic ordering based on a comparator of their elements .