net.i2p.router.util

## Class CachedIteratorCollection<E>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - net.i2p.router.util.CachedIteratorCollection<E>

- Type Parameters:
    `E` - type of elements in this collection
  All Implemented Interfaces:
    Iterable<E>, Collection<E>

      public class CachedIteratorCollection<E>
      extends AbstractCollection<E>

  Thread-safe collection with cached iterator for efficient element iteration.

  Extends AbstractCollection to provide a collection that can be iterated over without creating new iterator objects. Uses a linked list structure with a single cached iterator instance to minimize object churn during frequent iteration operations.

  Provides efficient iteration for scenarios where the same collection is traversed multiple times, avoiding the overhead of creating multiple iterator instances. Thread-safe for concurrent access with proper synchronization on iterator state management.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `CachedIteratorCollection.CachedIterator` Inner CachedIterator class - implements hasNext(), next() & remove()

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CachedIteratorCollection()` Default constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(E element)` Adds a data object (element) as a Node and sets previous/next pointers accordingly
    `void` | `clear()` Clears the AbstractCollectionTest object, all pointers reset to 'null'
    `Iterator<E>` | `iterator()` Returns a new iterator over the elements in this collection.
    `int` | `size()` Return size of current LinkedListTest object

    - ### Methods inherited from class java.util.AbstractCollection

      `addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Collection

      `equals, hashCode, parallelStream, removeIf, spliterator, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Constructor Detail

    - #### CachedIteratorCollection

          public CachedIteratorCollection()

      Default constructor

  - ### Method Detail

    - #### add

          public boolean add(E element)

      Adds a data object (element) as a Node and sets previous/next pointers accordingly
      Specified by:
        `add` in interface `Collection<E>`
      Overrides:
        `add` in class `AbstractCollection<E>`

    - #### clear

          public void clear()

      Clears the AbstractCollectionTest object, all pointers reset to 'null'
      Specified by:
        `clear` in interface `Collection<E>`
      Overrides:
        `clear` in class `AbstractCollection<E>`

    - #### iterator

          public Iterator<E> iterator()

      Returns a new iterator over the elements in this collection. Each iterator has independent state.
      Specified by:
        `iterator` in interface `Iterable<E>`
      Specified by:
        `iterator` in interface `Collection<E>`
      Specified by:
        `iterator` in class `AbstractCollection<E>`
      Returns:
        a new `CachedIteratorCollection.CachedIterator` instance

    - #### size

          public int size()

      Return size of current LinkedListTest object
      Specified by:
        `size` in interface `Collection<E>`
      Specified by:
        `size` in class `AbstractCollection<E>`