base/common/src/main/com/thesett/common/util/Comparisons.java
public static <T, U> String compareIterators(Iterator<U> iterator, Iterator<T> expectedIterator,
        Function<U, T> mapping)
    {
        String errorMessage = "";

        while (iterator.hasNext())
        {
            U next = iterator.next();
            T nextMapped = mapping.apply(next);
            T nextExpected = expectedIterator.next();

            if (!nextMapped.equals(nextExpected))
            {
                errorMessage += "Expecting " + nextExpected + " but got " + nextMapped;
            }
        }

        return errorMessage;
    }
public static <T, U> String compareIterators(Iterator<U> iterator, Iterator<T> expectedIterator,
        Function<U, T> mapping)
    {
        String errorMessage = "";

        while (iterator.hasNext())
        {
            U next = iterator.next();
            T nextMapped = mapping.apply(next);
            T nextExpected = expectedIterator.next();

            if (!nextMapped.equals(nextExpected))
            {
                errorMessage += "Expecting " + nextExpected + " but got " + nextMapped;
            }
        }

        return errorMessage;
    }
public static < T , U > String compareIterators ( Iterator < U > iterator , Iterator < T > expectedIterator , Function < U , T > mapping ) { String errorMessage = "" ; while ( iterator . hasNext ( ) ) { U next = iterator . next ( ) ; T nextMapped = mapping . apply ( next ) ; T nextExpected = expectedIterator . next ( ) ; if ( ! nextMapped . equals ( nextExpected ) ) { errorMessage += "Expecting " + nextExpected + " but got " + nextMapped ; } } return errorMessage ; }
Walks down two iterators, comparing them element by element, using the equals method.

@param  iterator         The first iterator to compare.
@param  expectedIterator The second iterator to compare.
@param  mapping          A mapping between the types of the iterators.
@param  <U>              The type of the left iterator.
@param  <T>              The type of the right iterator.

@return Any mismatches encountered in a string, or the empty string if none found.
Walks down two iterators comparing them element by element using the equals method .