org.apache.commons.collections.list
public class NodeCachingLinkedList extends AbstractLinkedList implements Serializable
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: Commons Collections 3.0
Version: $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
| Field Summary | |
|---|---|
| protected int | cacheSize
The size of the cache. |
| protected static int | DEFAULT_MAXIMUM_CACHE_SIZE
The default value for maximumCacheSize. |
| protected Node | firstCachedNode
The first cached node, or null if no nodes are cached.
|
| protected int | maximumCacheSize
The maximum size of the cache. |
| Constructor Summary | |
|---|---|
| NodeCachingLinkedList()
Constructor that creates. | |
| NodeCachingLinkedList(Collection coll)
Constructor that copies the specified collection
| |
| NodeCachingLinkedList(int maximumCacheSize)
Constructor that species the maximum cache size.
| |
| Method Summary | |
|---|---|
| protected void | addNodeToCache(Node node)
Adds a node to the cache, if the cache isn't full.
|
| protected Node | createNode(Object value)
Creates a new node, either by reusing one from the cache or creating
a new one.
|
| protected int | getMaximumCacheSize()
Gets the maximum size of the cache.
|
| protected Node | getNodeFromCache()
Gets a node from the cache. |
| protected boolean | isCacheFull()
Checks whether the cache is full.
|
| protected void | removeAllNodes()
Removes all the nodes from the list, storing as many as required in the
cache for reuse.
|
| protected void | removeNode(Node node)
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)
Sets the maximum size of the cache.
|
| protected void | shrinkCacheToMaximumSize()
Reduce the size of the cache to the maximum, if necessary. |
null if no nodes are cached.
Cached nodes are stored in a singly-linked list with
next pointing to the next element.Parameters: coll the collection to copy
Parameters: maximumCacheSize the maximum cache size
Parameters: node the node to add to the cache
Parameters: value value of the new node
Returns: the newly created node
Returns: the maximum cache size
null values for next, previous and element.
Returns: a node, or null if there are no nodes in the cache.
Returns: true if the cache is full
Parameters: node the node to remove
Parameters: maximumCacheSize the new maximum cache size