Package org.plumelib.util
Class OrderedPairIterator<T extends @Nullable Object>
java.lang.Object
org.plumelib.util.OrderedPairIterator<T>
- Type Parameters:
T
- the element type of each component iterator; this OrderedPairIterator has elements of typeMPair<T,T>
public class OrderedPairIterator<T extends @Nullable Object>
extends Object
implements Iterator<MPair<@Nullable T,@Nullable T>>
Given two sorted iterators, this class returns a new iterator that pairs equal elements of the
inputs, according to the sort order or the given comparator. If an element has no equal element
in the other iterator, then the element is paired with null.
For example, suppose that the inputs are
[1, 2, 3, 5] and [1, 3, 5, 7, 9].
Then the output is
[(1,1), (2,null), (3,3), (5,5), (null,7), (null, 9)].
(This operation is similar to, but not the same as, the operation called "zipping".)
In some cases this is just the right abstraction. But in some cases it's appropriate to use set intersection/difference instead.
-
Constructor Summary
ConstructorDescriptionOrderedPairIterator
(Iterator<T> itor1, Iterator<T> itor2) Create an iterator that returns pairs, where each pair contains has an element from each iterator and the two elements are equal.OrderedPairIterator
(Iterator<T> itor1, Iterator<T> itor2, Comparator<T> comparator) Create an iterator that returns pairs, where each pair contains has an element from each iterator and the two elements are equal according to the comparator. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
OrderedPairIterator
Create an iterator that returns pairs, where each pair contains has an element from each iterator and the two elements are equal.- Parameters:
itor1
- iterator for first elements of pairsitor2
- iterator for second elements of pairs
-
OrderedPairIterator
Create an iterator that returns pairs, where each pair contains has an element from each iterator and the two elements are equal according to the comparator.- Parameters:
itor1
- iterator for first elements of pairsitor2
- iterator for second elements of pairscomparator
- determines whether two elements are equal and should be paired together
-
-
Method Details
-
hasNext
-
next
-
remove
-