Class ZippingIterator<E>
- java.lang.Object
-
- org.apache.commons.collections4.iterators.ZippingIterator<E>
-
- All Implemented Interfaces:
java.util.Iterator<E>
public class ZippingIterator<E> extends java.lang.Object implements java.util.Iterator<E>Provides an interleaved iteration over the elements contained in a collection of Iterators.Given two
IteratorinstancesAandB, 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(java.util.Iterator<? extends E>... iterators)Constructs a newZippingIteratorthat will provide interleaved iteration of the specified iterators.ZippingIterator(java.util.Iterator<? extends E> a, java.util.Iterator<? extends E> b)Constructs a newZippingIteratorthat will provide interleaved iteration over the two given iterators.ZippingIterator(java.util.Iterator<? extends E> a, java.util.Iterator<? extends E> b, java.util.Iterator<? extends E> c)Constructs a newZippingIteratorthat will provide interleaved iteration over the three given iterators.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasNext()Returnstrueif any child iterator has remaining elements.Enext()Returns the next element from a child iterator.voidremove()Removes the last returned element from the child iterator that produced it.
-
-
-
Constructor Detail
-
ZippingIterator
public ZippingIterator(java.util.Iterator<? extends E> a, java.util.Iterator<? extends E> b)
Constructs a newZippingIteratorthat will provide interleaved iteration over the two given iterators.- Parameters:
a- the first child iteratorb- the second child iterator- Throws:
java.lang.NullPointerException- if either iterator is null
-
ZippingIterator
public ZippingIterator(java.util.Iterator<? extends E> a, java.util.Iterator<? extends E> b, java.util.Iterator<? extends E> c)
Constructs a newZippingIteratorthat will provide interleaved iteration over the three given iterators.- Parameters:
a- the first child iteratorb- the second child iteratorc- the third child iterator- Throws:
java.lang.NullPointerException- if either iterator is null
-
ZippingIterator
public ZippingIterator(java.util.Iterator<? extends E>... iterators)
Constructs a newZippingIteratorthat will provide interleaved iteration of the specified iterators.- Parameters:
iterators- the array of iterators- Throws:
java.lang.NullPointerException- if any iterator is null
-
-
Method Detail
-
hasNext
public boolean hasNext()
Returnstrueif any child iterator has remaining elements.- Specified by:
hasNextin interfacejava.util.Iterator<E>- Returns:
- true if this iterator has remaining elements
-
next
public E next() throws java.util.NoSuchElementException
Returns the next element from a child iterator.- Specified by:
nextin interfacejava.util.Iterator<E>- Returns:
- the next interleaved element
- Throws:
java.util.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:
removein interfacejava.util.Iterator<E>- Throws:
java.lang.IllegalStateException- if there is no last returned element, or if the last returned element has already been removed
-
-