Class LimitingIterator<T>
java.lang.Object
com.github.tommyettinger.ds.support.util.LimitingIterator<T>
- Type Parameters:
T- the type of items this can return, and the type the wrapped Iterator returns
- All Implemented Interfaces:
Iterator<T>
Wraps an Iterator so that it only returns at most a specific amount of items (defined by calls to
You can change the Iterator and limit at once using
next().
This can be useful to limit infinite Iterators so they only produce a finite amount of results.
This has undefined behavior if any items the Iterator could return are modified during iteration.
You can change the Iterator and limit at once using
set(Iterator, int), and can also just
change the Iterator with set(Iterator).-
Field Details
-
iterator
-
limit
protected int limit -
remaining
protected int remaining
-
-
Constructor Details
-
LimitingIterator
public LimitingIterator() -
LimitingIterator
-
-
Method Details