Package generic.util
Class MultiIterator<T>
- java.lang.Object
-
- generic.util.MultiIterator<T>
-
- Type Parameters:
T
- the type of this iterator
- All Implemented Interfaces:
java.util.Iterator<T>
public class MultiIterator<T> extends java.lang.Object implements java.util.Iterator<T>
An iterator that is comprised of one or morePeekableIterator
s. The typeT
of the the iterators must either implementComparable
directly or you must provide aComparator
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
Fields Modifier and Type Field Description protected java.util.List<PeekableIterator<T>>
iterators
-
Constructor Summary
Constructors Constructor Description MultiIterator(java.util.List<PeekableIterator<T>> iterators, boolean forward)
Use this constructor when the items of the iterators are naturally comparable (i.e., they implementComparable
).MultiIterator(java.util.List<PeekableIterator<T>> iterators, java.util.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
T
next()
void
remove()
-
-
-
Field Detail
-
iterators
protected java.util.List<PeekableIterator<T>> iterators
-
-
Constructor Detail
-
MultiIterator
public MultiIterator(java.util.List<PeekableIterator<T>> iterators, boolean forward)
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(java.util.List<PeekableIterator<T>> iterators, java.util.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
-
-