net.sf.jga.util

Class IteratorComparator<T>

public class IteratorComparator<T> extends Object implements Comparator<Iterator<? extends T>>

Comparator used to compare iterations lexically.

Author: David A. Hall

Constructor Summary
IteratorComparator(Comparator<? super T> comp)
Builds an IteratorComparator that uses the given Comparator to compare the elements of an iteration.
Method Summary
intcompare(Iterator<? extends T> x, Iterator<? extends T> y)
Compares the contents of the two iterations.

Constructor Detail

IteratorComparator

public IteratorComparator(Comparator<? super T> comp)
Builds an IteratorComparator that uses the given Comparator to compare the elements of an iteration.

Method Detail

compare

public int compare(Iterator<? extends T> x, Iterator<? extends T> y)
Compares the contents of the two iterations. An element from each iteration is passed to the given comparator, and if they are not equal, the iteration that produced the lesser of the two elements is determined to be the lesser of the two iterations. If the elements are equal, then the next pair of elements if passed. If one of the two iterations is exhausted before a pair of unequal elements is found, then it is considered to be the lesser. If both iterations are exhausted before a pair of unequal elements is found, then the iterations are determined to be equal.

Neither iteration will be advanced past the point where an unequal pair is found, but the elements that were unequal will have been consumed.

UNKNOWN: -1 if x < y, 1 if x > y, 0 if x == y