Package org.apache.commons.collections4.list

# Class NodeCachingLinkedList<E>

java.lang.Object
org.apache.commons.collections4.list.AbstractLinkedList<E>
org.apache.commons.collections4.list.NodeCachingLinkedList<E>

Type Parameters:
  `E` - The type of the elements in the list.

All Implemented Interfaces:
  `Serializable`, `Iterable<E>`, `Collection<E>`, `List<E>`

@Deprecated public class NodeCachingLinkedList<E> extends AbstractLinkedList<E> implements Serializable
Deprecated.
parent `AbstractLinkedList` is source incompatible with List methods added in Java 21
A `List` implementation that stores a cache of internal Node objects in an effort to reduce wasteful object creation.

A linked list creates one Node for each item of data added. This can result in a lot of object creation and garbage collection. This implementation seeks to avoid that by maintaining a store of cached nodes.

This implementation is suitable for long-lived lists where both add and remove are used. Short-lived lists, or lists which only grow will have worse performance using this class.

Note that this implementation is not synchronized.

Since:
  3.0
See Also:
  - Serialized Form

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.commons.collections4.list.AbstractLinkedList

  `AbstractLinkedList.LinkedListIterator<E>, AbstractLinkedList.LinkedSubList<E>, AbstractLinkedList.LinkedSubListIterator<E>, AbstractLinkedList.Node<E>`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NodeCachingLinkedList()`
  Deprecated.
  Constructor that creates.
  `NodeCachingLinkedList(int maximumCacheSize)`
  Deprecated.
  Constructor that species the maximum cache size.
  `NodeCachingLinkedList(Collection<? extends E> coll)`
  Deprecated.
  Constructor that copies the specified collection

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `addNodeToCache(AbstractLinkedList.Node<E> node)`
  Deprecated.
  Adds a node to the cache, if the cache isn't full.
  `protected AbstractLinkedList.Node<E>`
  `createNode(E value)`
  Deprecated.
  Creates a new node, either by reusing one from the cache or creating a new one.
  `protected int`
  `getMaximumCacheSize()`
  Deprecated.
  Gets the maximum size of the cache.
  `protected AbstractLinkedList.Node<E>`
  `getNodeFromCache()`
  Deprecated.
  Gets a node from the cache.
  `protected boolean`
  `isCacheFull()`
  Deprecated.
  Checks whether the cache is full.
  `protected void`
  `removeAllNodes()`
  Deprecated.
  Removes all the nodes from the list, storing as many as required in the cache for reuse.
  `protected void`
  `removeNode(AbstractLinkedList.Node<E> node)`
  Deprecated.
  Removes the node from the list, storing it in the cache for reuse if the cache is not yet full.
  `protected void`
  `setMaximumCacheSize(int maximumCacheSize)`
  Deprecated.
  Sets the maximum size of the cache.
  `protected void`
  `shrinkCacheToMaximumSize()`
  Deprecated.
  Reduce the size of the cache to the maximum, if necessary.

  ### Methods inherited from class org.apache.commons.collections4.list.AbstractLinkedList

  `add, add, addAll, addAll, addFirst, addLast, addNode, addNodeAfter, addNodeBefore, clear, contains, containsAll, createHeaderNode, createSubListIterator, createSubListListIterator, doReadObject, doWriteObject, equals, get, getFirst, getLast, getNode, hashCode, indexOf, init, isEmpty, isEqualValue, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeLast, retainAll, set, size, subList, toArray, toArray, toString, updateNode`

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

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

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

  `parallelStream, removeIf, stream`

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

  `forEach`

  ### Methods inherited from interface java.util.List

  `replaceAll, sort, spliterator`

- ## Constructor Details

  - ### NodeCachingLinkedList

    public NodeCachingLinkedList()
    Deprecated.
    Constructor that creates.

  - ### NodeCachingLinkedList

    public NodeCachingLinkedList(Collection<? extends E> coll)
    Deprecated.
    Constructor that copies the specified collection
    Parameters:
      `coll` - The collection to copy

  - ### NodeCachingLinkedList

    public NodeCachingLinkedList(int maximumCacheSize)
    Deprecated.
    Constructor that species the maximum cache size.
    Parameters:
      `maximumCacheSize` - The maximum cache size

- ## Method Details

  - ### addNodeToCache

    protected void addNodeToCache(AbstractLinkedList.Node<E> node)
    Deprecated.
    Adds a node to the cache, if the cache isn't full. The node's contents are cleared, so they can be garbage collected.
    Parameters:
      `node` - The node to add to the cache

  - ### createNode

    protected AbstractLinkedList.Node<E> createNode(E value)
    Deprecated.
    Creates a new node, either by reusing one from the cache or creating a new one.
    Overrides:
      `createNode` in class `AbstractLinkedList<E>`
    Parameters:
      `value` - value of the new node
    Returns:
      The newly created node

  - ### getMaximumCacheSize

    protected int getMaximumCacheSize()
    Deprecated.
    Gets the maximum size of the cache.
    Returns:
      The maximum cache size

  - ### getNodeFromCache

    protected AbstractLinkedList.Node<E> getNodeFromCache()
    Deprecated.
    Gets a node from the cache. If a node is returned, then the value of `cacheSize` is decreased accordingly. The node that is returned will have `null` values for next, previous and element.
    Returns:
      A node, or `null` if there are no nodes in the cache.

  - ### isCacheFull

    protected boolean isCacheFull()
    Deprecated.
    Checks whether the cache is full.
    Returns:
      true if the cache is full

  - ### removeAllNodes

    protected void removeAllNodes()
    Deprecated.
    Removes all the nodes from the list, storing as many as required in the cache for reuse.
    Overrides:
      `removeAllNodes` in class `AbstractLinkedList<E>`

  - ### removeNode

    protected void removeNode(AbstractLinkedList.Node<E> node)
    Deprecated.
    Removes the node from the list, storing it in the cache for reuse if the cache is not yet full.
    Overrides:
      `removeNode` in class `AbstractLinkedList<E>`
    Parameters:
      `node` - The node to remove

  - ### setMaximumCacheSize

    protected void setMaximumCacheSize(int maximumCacheSize)
    Deprecated.
    Sets the maximum size of the cache.
    Parameters:
      `maximumCacheSize` - The new maximum cache size

  - ### shrinkCacheToMaximumSize

    protected void shrinkCacheToMaximumSize()
    Deprecated.
    Reduce the size of the cache to the maximum, if necessary.