Top Description Fields Constructors Methods
org.apache.commons.collections4.iterators

public Class ZippingIterator<E>

extends Object
implements Iterator<E>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Imports
java.util.ArrayList, .Iterator, .List, .NoSuchElementException, org.apache.commons.collections4.FluentIterable

Provides an interleaved iteration over the elements contained in a collection of Iterators.

Given two Iterator instances A and B, the next method on this iterator will switch between A.next() and B.next() until both iterators are exhausted.

Since
4.1

Field Summary

Modifier and TypeField and Description
private final Iterator<Iterator<? extends E>>
iterators

The Iterators to evaluate.

private Iterator<? extends E>
lastReturned

The last iterator which was used for next().

private Iterator<? extends E>
nextIterator

The next iterator to use for next().

Constructor Summary

AccessConstructor and Description
public
ZippingIterator(final Iterator<? extends E>
the first child iterator
a
,
final Iterator<? extends E>
the second child iterator
b
)

Constructs a new ZippingIterator that will provide interleaved iteration over the two given iterators.

public
ZippingIterator(final Iterator<? extends E>
the first child iterator
a
,
final Iterator<? extends E>
the second child iterator
b
,
final Iterator<? extends E>
the third child iterator
c
)

Constructs a new ZippingIterator that will provide interleaved iteration over the three given iterators.

public
ZippingIterator(final Iterator<? extends E>...
the array of iterators
iterators
)

Constructs a new ZippingIterator that will provide interleaved iteration of the specified iterators.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this iterator has remaining elements
hasNext
()

Implements java.util.Iterator.hasNext.

Returns true if any child iterator has remaining elements.
public E

Returns:

the next interleaved element
next
()

Implements java.util.Iterator.next.

Returns the next element from a child iterator.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes the last returned element from the child iterator that produced it.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iteratorsback to summary
private final Iterator<Iterator<? extends E>> iterators

The Iterators to evaluate.

lastReturnedback to summary
private Iterator<? extends E> lastReturned

The last iterator which was used for next().

nextIteratorback to summary
private Iterator<? extends E> nextIterator

The next iterator to use for next().

Constructor Detail

ZippingIteratorback to summary
public ZippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b)

Constructs a new ZippingIterator that will provide interleaved iteration over the two given iterators.

Parameters
a:Iterator<? extends E>

the first child iterator

b:Iterator<? extends E>

the second child iterator

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if either iterator is null
ZippingIteratorback to summary
public ZippingIterator(final Iterator<? extends E> a, final Iterator<? extends E> b, final Iterator<? extends E> c)

Constructs a new ZippingIterator that will provide interleaved iteration over the three given iterators.

Parameters
a:Iterator<? extends E>

the first child iterator

b:Iterator<? extends E>

the second child iterator

c:Iterator<? extends E>

the third child iterator

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if either iterator is null
ZippingIteratorback to summary
public ZippingIterator(final Iterator<? extends E>... iterators)

Constructs a new ZippingIterator that will provide interleaved iteration of the specified iterators.

Parameters
iterators:Iterator<? extends E>[]

the array of iterators

Exceptions
NullPointerException:
if any iterator is null

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Returns true if any child iterator has remaining elements.

Returns:boolean

true if this iterator has remaining elements

Annotations
@Override
nextback to summary
public E next() throws NoSuchElementException

Implements java.util.Iterator.next.

Returns the next element from a child iterator.

Returns:E

the next interleaved element

Annotations
@Override
Exceptions
NoSuchElementException:
if no child iterator has any more elements
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Removes the last returned element from the child iterator that produced it.

Annotations
@Override
Exceptions
IllegalStateException:
if there is no last returned element, or if the last returned element has already been removed