java.lang.Object
net.i2p.router.util.CachedIteratorCollection.CachedIterator<E>
- Type Parameters:
E- the type of elements in this iterator
- All Implemented Interfaces:
Iterator<E>
- Enclosing class:
CachedIteratorCollection<E>
Static inner CachedIterator class - implements hasNext(),
next() & remove() Static to avoid holding an implicit this$0 reference to the enclosing collection, which would prevent GC of the collection (and its owning PeerState) when held in another thread's ThreadLocal after CachedIteratorCollection.clear() is called.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final WeakReference<CachedIteratorCollection<E>> Weak link to the iterated collection.private CachedIteratorCollection.Node<E> The node at the current index.private booleanTrue once next was called.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionbooleanhasNext()Returns true as long as current Iteration Index Node (itrIndexNode) is non-null.private booleaninUse()Whether this iterator is in the middle of an iteration.next()The next element in the iteration.voidremove()If nextCalled is true (i.e.private voidreset()Reset iteration.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterator
forEachRemaining
Field Details
collRef
Weak link to the iterated collection.nextCalled
private boolean nextCalledTrue once next was called.itrIndexNode
The node at the current index.
Constructor Details
CachedIterator
CachedIterator(CachedIteratorCollection<E> coll) Create a new CachedIterator.- Parameters:
coll- the owning collection
Method Details
reset
private void reset()Reset iteration.inUse
private boolean inUse()Whether this iterator is in the middle of an iteration.- Returns:
- true if this iterator is in the middle of an iteration
remove
hasNext
next
The next element in the iteration.- Specified by:
nextin interfaceIterator<E>- Throws:
NoSuchElementException- if the collection was cleared or the iteration is finished