E - type of elements in this collectionpublic class CachedIteratorCollection<E> extends AbstractCollection<E>
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.
| Modifier and Type | Class and Description |
|---|---|
class |
CachedIteratorCollection.CachedIterator
Inner CachedIterator class - implements hasNext(), next() & remove()
|
| 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 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
|
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streampublic 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 instancepublic int size()
size in interface Collection<E>size in class AbstractCollection<E>