public static <U> int lexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2, Comparator<U> elemComparator) {
        Iterator<? extends U> it1 = o1.iterator(), it2 = o2.iterator();

        while (it1.hasNext() && it2.hasNext()) {
            int cmp = elemComparator.compare(it1.next(), it2.next());
            if (cmp != 0) {
                return cmp;
            }
        }

        if (it1.hasNext()) {
            return 1;
        } else if (it2.hasNext()) {
            return -1;
        }
        return 0;
    }
public static < U > int lexCompare ( Iterable < ? extends U > o1 , Iterable < ? extends U > o2 , Comparator < U > elemComparator ) { Iterator < ? extends U > it1 = o1 . iterator ( ) , it2 = o2 . iterator ( ) ; while ( it1 . hasNext ( ) && it2 . hasNext ( ) ) { int cmp = elemComparator . compare ( it1 . next ( ) , it2 . next ( ) ) ; if ( cmp != 0 ) { return cmp ; } } if ( it1 . hasNext ( ) ) { return 1 ; } else if ( it2 . hasNext ( ) ) { return - 1 ; } return 0 ; }
Lexicographically compares two {@link Iterable}s. Comparison of the elements is done using the specified
comparator.

@param o1
the first iterable.
@param o2
the second iterable.
@param elemComparator
the comparator.

@return <code>&lt; 0</code> iff o1 is lexicographically smaller, <code>0</code> if o1 equals o2 and <code>&gt;
0</code> otherwise.