public abstract static class LongIterators.AbstractIndexBasedIterator extends AbstractLongIterator
This class is only appropriate for sequences that are at most Integer.MAX_VALUE long.
If your backing data store can be bigger then this, consider the equivalently named class in
the type specific BigListIterators class.
As the abstract methods in this class are used in inner loops, it is generally a
good idea to override the class as final as to encourage the JVM to inline
them (or alternatively, override the abstract methods as final).
| Modifier and Type | Field and Description |
|---|---|
protected int |
lastReturned
The last returned index by a call to
LongIterator.next() or, if a list-iterator, {@link java.util.ListIterator#previous(). |
protected int |
minPos
The minimum pos can be, and is the logical start of the "range".
|
protected int |
pos
The current position index, the index of the item to be returned after the next call to
LongIterator.next(). |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractIndexBasedIterator(int minPos,
int initialPos) |
| Modifier and Type | Method and Description |
|---|---|
void |
forEachRemaining(java.util.function.LongConsumer action) |
protected abstract long |
get(int location)
Get the item corresponding to the given index location.
|
protected abstract int |
getMaxPos()
The maximum pos can be, and is the logical end (exclusive) of the "range".
|
boolean |
hasNext() |
long |
nextLong() |
void |
remove() |
protected abstract void |
remove(int location)
Remove the item at the given index.
|
int |
skip(int n) |
forEachRemainingprotected final int minPos
remove(int)),
so this is final.protected int pos
LongIterator.next().
This value will be between minPos and getMaxPos() (exclusive) (on a best effort, so concurrent
structural modifications outside this iterator may cause this to be violated, but that usually invalidates
iterators anyways). Thus pos being minPos + 2 would mean LongIterator.next()
was called twice and the next call will return the third element of this iterator.
protected int lastReturned
LongIterator.next() or, if a list-iterator, {@link java.util.ListIterator#previous().
It is −1 if no such call has occurred or a mutation has occurred through this iterator and no
advancement has been done.protected AbstractIndexBasedIterator(int minPos,
int initialPos)
protected abstract long get(int location)
Do not advance pos in this method; the default next method takes care of this.
The location given will be between minPos and getMaxPos() (exclusive).
Thus, a location of minPos + 2 would mean LongIterator.next() was called twice
and this method should return what the next call to LongIterator.next() should return.
protected abstract void remove(int location)
Do not modify pos in this method; the default #remove() method takes care of this.
This method should also do what is needed to track the change to the getMaxPos().
Usually this is accomplished by having this method call the parent Collection's appropriate remove
method, and having getMaxPos() track the parent collection's size.
protected abstract int getMaxPos()
If pos is equal to the return of this method, this means the last element has been returned and the next call to LongIterator.next() will throw.
Usually set return the parent collection's size, but does not have to be (for example, sublists and subranges).
public boolean hasNext()
public long nextLong()
public void remove()
public void forEachRemaining(java.util.function.LongConsumer action)
public int skip(int n)