T - type of iterated elementspublic class IndexedIteratorDecorator<T> extends Object implements Iterator<T>, Iterable<T>
The difference between "normal" and "true" index becomes clear when remove()
is invoked - in the next iteration cycle, the true index is normally incremented,
but the normal index keeps the previous value. Assume the following sample:
IndexedIteratorDecorator iter = ...
...
iter.next();
int normalIndex1 = iter.getIndex();
int trueIndex1 = iter.getTrueIndex();
iter.remove();
iter.next();
int normalIndex2 = iter.getIndex();
int trueIndex2 = iter.getTrueIndex();
Due to remove(), the following relations are valid:
normalIndex1 == normalIndex2trueIndex1 + 1 == trueIndex2| Constructor and Description |
|---|
IndexedIteratorDecorator(Iterator<? extends T> baseIter)
Creates a new instance of the decorator.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getIndex()
Returns an index of the current element in the iterated collection.
|
int |
getTrueIndex()
Returns a "true" index of the current iteration cycle.
|
boolean |
hasNext() |
Iterator<T> |
iterator() |
T |
next() |
void |
remove() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingforEach, spliteratorpublic int getIndex()
next() that is not preceded by remove()
the index value is incremented by 1.public int getTrueIndex()
next() its value is incremented
by 1.Copyright © 2014 Boleslav Bobcik - Auderis. All rights reserved.