E - type of elements in this collectionpublic class CachedIteratorCollection<E> extends AbstractCollection<E>
Extends AbstractCollection to provide a collection that can be iterated without creating new iterator objects per call. Uses a linked list structure with per-thread cached iterator instances to minimize object churn during frequent iteration operations.
All mutation and iteration methods are synchronized for thread safety. Nested iteration from the same thread allocates a new iterator.
| Modifier and Type | Class and Description |
|---|---|
static class | CachedIteratorCollection.CachedIterator<E>Static inner CachedIterator class - implements hasNext(), next() & remove() |
| Modifier and Type | Field and Description |
|---|---|
(package private) boolean | _clearedTrue after clear() to signal iterator instances the collection is gone |
(package private) net.i2p.router.util.CachedIteratorCollection.Node<E> | firstFirst node in the linked list |
(package private) net.i2p.router.util.CachedIteratorCollection.Node<E> | lastLast node in the linked list |
(package private) int | sizeSize of the collection |
| Constructor and Description |
|---|
CachedIteratorCollection()Default constructor |
| 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 collection, all pointers reset to 'null' |
Iterator<E> | iterator()Returns a cached iterator over the elements in this collection. |
void | releaseCurrentThreadIterator()Reset the current thread's cached iterator so it is no longer
considered "in use". |
boolean | remove(Object o)Remove the first element matching by identity (==). |
int | size()Return size of current collection |
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streamvolatile boolean _cleared
net.i2p.router.util.CachedIteratorCollection.Node<E> first
net.i2p.router.util.CachedIteratorCollection.Node<E> last
int size
public boolean add(E element)
add in interface Collection<E>add in class AbstractCollection<E>public void clear()
clear in interface Collection<E>clear in class AbstractCollection<E>public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in class AbstractCollection<E>CachedIteratorCollection.CachedIterator instance, reset to the beginningpublic void releaseCurrentThreadIterator()
public boolean remove(Object o)
remove in interface Collection<E>remove in class AbstractCollection<E>public int size()
size in interface Collection<E>size in class AbstractCollection<E>