Class BoundedIterator<E>
- java.lang.Object
-
- org.apache.commons.collections4.iterators.BoundedIterator<E>
-
- All Implemented Interfaces:
java.util.Iterator<E>
public class BoundedIterator<E> extends java.lang.Object implements java.util.Iterator<E>
Decorates another iterator to return elements in a specific range.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, andmax
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.
- Since:
- 4.1
-
-
Constructor Summary
Constructors Constructor Description BoundedIterator(java.util.Iterator<? extends E> iterator, long offset, long max)
Decorates the specified iterator to return at most the given number of elements, skipping all elements until the iterator reaches the position atoffset
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
E
next()
void
remove()
-
-
-
Constructor Detail
-
BoundedIterator
public BoundedIterator(java.util.Iterator<? extends E> iterator, long offset, long max)
Decorates the specified iterator to return at most the given number of elements, skipping all elements until the iterator reaches the position atoffset
.The iterator is immediately advanced until it reaches the position at
offset
, incurring O(n) time.- Parameters:
iterator
- the iterator to be decoratedoffset
- the index of the first element of the decorated iterator to returnmax
- the maximum number of elements of the decorated iterator to return- Throws:
java.lang.NullPointerException
- if iterator is nulljava.lang.IllegalArgumentException
- if either offset or max is negative
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<E>
-
remove
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 anIllegalStateException
if no explicit call tonext()
has been made prior to callingremove()
.- Specified by:
remove
in interfacejava.util.Iterator<E>
-
-