Class ZippingIterator<E>
- java.lang.Object
-
- org.apache.commons.collections4.iterators.ZippingIterator<E>
-
- All Implemented Interfaces:
Iterator<E>
public class ZippingIterator<E> extends Object implements Iterator<E>
Provides an interleaved iteration over the elements contained in a collection of Iterators.Given two
Iterator
instancesA
andB
, thenext()
method on this iterator will switch betweenA.next()
andB.next()
until both iterators are exhausted.- Since:
- 4.1
-
-
Constructor Summary
Constructors Constructor Description ZippingIterator(Iterator<? extends E>... iterators)
Constructs a newZippingIterator
that will provide interleaved iteration of the specified iterators.ZippingIterator(Iterator<? extends E> a, Iterator<? extends E> b)
Constructs a newZippingIterator
that will provide interleaved iteration over the two given iterators.ZippingIterator(Iterator<? extends E> a, Iterator<? extends E> b, Iterator<? extends E> c)
Constructs a newZippingIterator
that will provide interleaved iteration over the three given iterators.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
Returnstrue
if any child iterator has remaining elements.E
next()
Returns the next element from a child iterator.void
remove()
Removes the last returned element from the child iterator that produced it.-
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 Detail
-
ZippingIterator
public ZippingIterator(Iterator<? extends E> a, Iterator<? extends E> b)
Constructs a newZippingIterator
that will provide interleaved iteration over the two given iterators.- Parameters:
a
- the first child iteratorb
- the second child iterator- Throws:
NullPointerException
- if either iterator is null
-
ZippingIterator
public ZippingIterator(Iterator<? extends E> a, Iterator<? extends E> b, Iterator<? extends E> c)
Constructs a newZippingIterator
that will provide interleaved iteration over the three given iterators.- Parameters:
a
- the first child iteratorb
- the second child iteratorc
- the third child iterator- Throws:
NullPointerException
- if either iterator is null
-
ZippingIterator
public ZippingIterator(Iterator<? extends E>... iterators)
Constructs a newZippingIterator
that will provide interleaved iteration of the specified iterators.- Parameters:
iterators
- the array of iterators- Throws:
NullPointerException
- if any iterator is null
-
-
Method Detail
-
hasNext
public boolean hasNext()
Returnstrue
if any child iterator has remaining elements.
-
next
public E next() throws NoSuchElementException
Returns the next element from a child iterator.- Specified by:
next
in interfaceIterator<E>
- Returns:
- the next interleaved element
- Throws:
NoSuchElementException
- if no child iterator has any more elements
-
remove
public void remove()
Removes the last returned element from the child iterator that produced it.- Specified by:
remove
in interfaceIterator<E>
- Throws:
IllegalStateException
- if there is no last returned element, or if the last returned element has already been removed
-
-