public class BoundedIterator<E> extends Objectimplements Iterator <E>
The decorated iterator is bounded in the range [offset, offset+max). The offset corresponds to the position of the first element to be returned from the decorated iterator, and max is the maximum number of elements to be returned at most.
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.
| Constructor and Description |
|---|
BoundedIterator(Iterator
Decorates the specified iterator to return at most the given number of elements, skipping all elements until the iterator reaches the position at
offset.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
hasNext()
|
E |
next()
|
void |
remove()
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingpublic BoundedIterator(Iterator<? extends E> iterator, long offset, long max)
offset.
The iterator is immediately advanced until it reaches the position at offset, incurring O(n) time.
iterator - the iterator to be decorated
offset - the index of the first element of the decorated iterator to return
max - the maximum number of elements of the decorated iterator to return
NullPointerException - if iterator is null
IllegalArgumentException - if either offset or max is negative
public boolean hasNext()
public E next()
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().