Package generic.util
Class MultiIterator<T>
java.lang.Object
generic.util.MultiIterator<T>
- Type Parameters:
T
- the type of this iterator
- All Implemented Interfaces:
Iterator<T>
An iterator that is comprised of one or more
PeekableIterator
s. The type T
of the
the iterators must either implement Comparable
directly or you must provide a
Comparator
for comparing the types. Further, it is assumed that the iterators return
values in sorted order. If the sorted order is reversed, then that must be indicated in
the constructor of this class.
This class allows duplicate items in the iterators. Thus, if you do not wish to process
duplicate values, then you need to de-dup the data returned from next()
.
Alternatively, you could subclass this iterator and de-dup the returned values.
This class also does not handle null items returned during the iteration process.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMultiIterator
(List<PeekableIterator<T>> iterators, boolean forward) Use this constructor when the items of the iterators are naturally comparable (i.e., they implementComparable
).MultiIterator
(List<PeekableIterator<T>> iterators, Comparator<T> comparator, boolean forward) Use this constructor when the items of the iterators are not naturally comparable (i.e., they do not implementComparable
). -
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
-
Field Details
-
iterators
-
-
Constructor Details
-
MultiIterator
Use this constructor when the items of the iterators are naturally comparable (i.e., they implementComparable
).- Parameters:
iterators
- the iterators that provide the dataforward
- true if the iterators provide data sorted ascending; false for descending
-
MultiIterator
public MultiIterator(List<PeekableIterator<T>> iterators, Comparator<T> comparator, boolean forward) Use this constructor when the items of the iterators are not naturally comparable (i.e., they do not implementComparable
).- Parameters:
iterators
- the iterators that provide the datacomparator
- the comparator used to find the next itemforward
- true if the iterators provide data sorted ascending; false for descending
-
-
Method Details