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>

public static class CachedIteratorCollection.CachedIterator<E>extends Object implements Iterator<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 Details

  • 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

      public void remove()
      If nextCalled is true (i.e. next() has been called at least once), remove() will remove the last returned Node.
      Specified by:
      remove in interface Iterator<E>
    • hasNext

      public boolean hasNext()
      Returns true as long as current Iteration Index Node (itrIndexNode) is non-null.
      Specified by:
      hasNext in interface Iterator<E>
      Returns:
      whether next is present
    • next

      public E next()
      The next element in the iteration.
      Specified by:
      next in interface Iterator<E>
      Throws:
      NoSuchElementException - if the collection was cleared or the iteration is finished