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

public Class SkippingIterator<E>

extends AbstractIteratorDecorator<E>
Class Inheritance
Imports
java.util.Iterator

Decorates another iterator to skip the first N elements.

In case an offset parameter other than 0 is provided, the decorated iterator is immediately advanced to this position, skipping all elements before that position.

Since
4.1

Field Summary

Modifier and TypeField and Description
private final long
offset

The offset to bound the first element return

private long
pos

The position of the current element

Constructor Summary

AccessConstructor and Description
public
SkippingIterator(final Iterator<E>
the iterator to be decorated
iterator
,
final long
the index of the first element of the decorated iterator to return
offset
)

Decorates the specified iterator to skip all elements until the iterator reaches the position at offset.

Method Summary

Modifier and TypeMethod and Description
private void
init()

Skips the given number of elements.

public E
next()

Overrides org.apache.commons.collections4.iterators.AbstractIteratorDecorator.next.

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides org.apache.commons.collections4.iterators.AbstractUntypedIteratorDecorator.remove.

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Field Detail

offsetback to summary
private final long offset

The offset to bound the first element return

posback to summary
private long pos

The position of the current element

Constructor Detail

SkippingIteratorback to summary
public SkippingIterator(final Iterator<E> iterator, final long offset)

Decorates the specified iterator to skip all elements until the iterator reaches the position at offset.

The iterator is immediately advanced until it reaches the position at offset, incurring O(n) time.

Parameters
iterator:Iterator<E>

the iterator to be decorated

offset:long

the index of the first element of the decorated iterator to return

Exceptions
NullPointerException:
if iterator is null
IllegalArgumentException:
if offset is negative

Method Detail

initback to summary
private void init()

Skips the given number of elements.

nextback to summary
public E next()

Overrides org.apache.commons.collections4.iterators.AbstractIteratorDecorator.next.

Implements java.util.Iterator.next.

Doc from org.apache.commons.collections4.iterators.AbstractIteratorDecorator.next.

Returns the next element in the iteration.

Returns:E

Doc from java.util.Iterator.next.

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides org.apache.commons.collections4.iterators.AbstractUntypedIteratorDecorator.remove.

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

In case an offset other than 0 was specified, the underlying iterator will be advanced to this position upon creation. A call to remove() will still result in an IllegalStateException if no explicit call to next() has been made prior to calling remove().

Annotations
@Override