Class LimitingShortIterator
java.lang.Object
com.github.tommyettinger.ds.support.util.LimitingShortIterator
- All Implemented Interfaces:
ShortIterator,Iterator<Short>
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
nextShort(). 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(ShortIterator, int), and can also just
change the Iterator with set(ShortIterator).-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasNext()shortReturns the nextshortelement in the iteration.voidremove()voidset(ShortIterator iterator) voidset(ShortIterator iterator, int limit) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemainingMethods inherited from interface com.github.tommyettinger.ds.support.util.ShortIterator
forEachRemaining, next
-
Field Details
-
iterator
-
limit
protected int limit -
remaining
protected int remaining
-
-
Constructor Details
-
LimitingShortIterator
public LimitingShortIterator() -
LimitingShortIterator
-
-
Method Details
-
set
-
set
-
hasNext
public boolean hasNext() -
nextShort
public short nextShort()Description copied from interface:ShortIteratorReturns the nextshortelement in the iteration.- Specified by:
nextShortin interfaceShortIterator- Returns:
- the next
shortelement in the iteration
-
remove
public void remove()
-