public class SkippingIterator<E> extends AbstractIteratorDecorator<E>
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.
| Modifier and Type | Field and Description |
|---|---|
private long |
offset
The offset to bound the first element return
|
private long |
pos
The position of the current element
|
| Constructor and Description |
|---|
SkippingIterator(java.util.Iterator<E> iterator,
long offset)
Decorates the specified iterator to skip all elements until the iterator
reaches the position at
offset. |
| Modifier and Type | Method and Description |
|---|---|
private void |
init()
Skips the given number of elements.
|
E |
next() |
void |
remove() |
getIterator, hasNextprivate final long offset
private long pos
public SkippingIterator(java.util.Iterator<E> iterator, long offset)
offset.
The iterator is immediately advanced until it reaches the position at offset,
incurring O(n) time.
iterator - the iterator to be decoratedoffset - the index of the first element of the decorated iterator to returnjava.lang.NullPointerException - if iterator is nulljava.lang.IllegalArgumentException - if offset is negativeprivate void init()
public E next()
AbstractIteratorDecoratornext in interface java.util.Iterator<E>next in class AbstractIteratorDecorator<E>public void remove()
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().
remove in interface java.util.Iterator<E>remove in class AbstractUntypedIteratorDecorator<E,E>