Class Overview
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.
Summary
[Expand]
Inherited Methods |
From class
org.apache.commons.collections.list.AbstractLinkedList
boolean
|
add(Object value)
|
void
|
add(int index, Object value)
|
boolean
|
addAll(Collection coll)
|
boolean
|
addAll(int index, Collection coll)
|
boolean
|
addFirst(Object o)
|
boolean
|
addLast(Object o)
|
void
|
addNode(AbstractLinkedList.Node nodeToInsert, AbstractLinkedList.Node insertBeforeNode)
Inserts a new node into the list.
|
void
|
addNodeAfter(AbstractLinkedList.Node node, Object value)
Creates a new node with the specified object as its
value and inserts it after node .
|
void
|
addNodeBefore(AbstractLinkedList.Node node, Object value)
Creates a new node with the specified object as its
value and inserts it before node .
|
void
|
clear()
|
boolean
|
contains(Object value)
|
boolean
|
containsAll(Collection coll)
|
AbstractLinkedList.Node
|
createHeaderNode()
Creates a new node with previous, next and element all set to null.
|
AbstractLinkedList.Node
|
createNode(Object value)
Creates a new node with the specified properties.
|
Iterator
|
createSubListIterator(AbstractLinkedList.LinkedSubList subList)
Creates an iterator for the sublist.
|
ListIterator
|
createSubListListIterator(AbstractLinkedList.LinkedSubList subList, int fromIndex)
Creates a list iterator for the sublist.
|
void
|
doReadObject(ObjectInputStream inputStream)
Deserializes the data held in this object to the stream specified.
|
void
|
doWriteObject(ObjectOutputStream outputStream)
Serializes the data held in this object to the stream specified.
|
boolean
|
equals(Object obj)
|
Object
|
get(int index)
|
Object
|
getFirst()
|
Object
|
getLast()
|
AbstractLinkedList.Node
|
getNode(int index, boolean endMarkerAllowed)
Gets the node at a particular index.
|
int
|
hashCode()
|
int
|
indexOf(Object value)
|
void
|
init()
The equivalent of a default constructor, broken out so it can be called
by any constructor and by readObject .
|
boolean
|
isEmpty()
|
boolean
|
isEqualValue(Object value1, Object value2)
Compares two values for equals.
|
Iterator
|
iterator()
|
int
|
lastIndexOf(Object value)
|
ListIterator
|
listIterator(int fromIndex)
|
ListIterator
|
listIterator()
|
Object
|
remove(int index)
|
boolean
|
remove(Object value)
|
boolean
|
removeAll(Collection coll)
|
void
|
removeAllNodes()
Removes all nodes by resetting the circular list marker.
|
Object
|
removeFirst()
|
Object
|
removeLast()
|
void
|
removeNode(AbstractLinkedList.Node node)
Removes the specified node from the list.
|
boolean
|
retainAll(Collection coll)
|
Object
|
set(int index, Object value)
|
int
|
size()
|
List
|
subList(int fromIndexInclusive, int toIndexExclusive)
Gets a sublist of the main list.
|
Object[]
|
toArray(Object[] array)
|
Object[]
|
toArray()
|
String
|
toString()
|
void
|
updateNode(AbstractLinkedList.Node node, Object value)
Updates the node with a new value.
|
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
|
From interface
java.lang.Iterable
|
From interface
java.util.Collection
abstract
boolean
|
add(E arg0)
|
abstract
boolean
|
addAll(Collection<? extends E> arg0)
|
abstract
void
|
clear()
|
abstract
boolean
|
contains(Object arg0)
|
abstract
boolean
|
containsAll(Collection<?> arg0)
|
abstract
boolean
|
equals(Object arg0)
|
abstract
int
|
hashCode()
|
abstract
boolean
|
isEmpty()
|
abstract
Iterator<E>
|
iterator()
|
abstract
boolean
|
remove(Object arg0)
|
abstract
boolean
|
removeAll(Collection<?> arg0)
|
abstract
boolean
|
retainAll(Collection<?> arg0)
|
abstract
int
|
size()
|
abstract
<T>
T[]
|
toArray(T[] arg0)
|
abstract
Object[]
|
toArray()
|
|
From interface
java.util.List
abstract
boolean
|
add(E arg0)
|
abstract
void
|
add(int arg0, E arg1)
|
abstract
boolean
|
addAll(Collection<? extends E> arg0)
|
abstract
boolean
|
addAll(int arg0, Collection<? extends E> arg1)
|
abstract
void
|
clear()
|
abstract
boolean
|
contains(Object arg0)
|
abstract
boolean
|
containsAll(Collection<?> arg0)
|
abstract
boolean
|
equals(Object arg0)
|
abstract
E
|
get(int arg0)
|
abstract
int
|
hashCode()
|
abstract
int
|
indexOf(Object arg0)
|
abstract
boolean
|
isEmpty()
|
abstract
Iterator<E>
|
iterator()
|
abstract
int
|
lastIndexOf(Object arg0)
|
abstract
ListIterator<E>
|
listIterator(int arg0)
|
abstract
ListIterator<E>
|
listIterator()
|
abstract
E
|
remove(int arg0)
|
abstract
boolean
|
remove(Object arg0)
|
abstract
boolean
|
removeAll(Collection<?> arg0)
|
abstract
boolean
|
retainAll(Collection<?> arg0)
|
abstract
E
|
set(int arg0, E arg1)
|
abstract
int
|
size()
|
abstract
List<E>
|
subList(int arg0, int arg1)
|
abstract
<T>
T[]
|
toArray(T[] arg0)
|
abstract
Object[]
|
toArray()
|
|
Constants
protected
static
final
int
DEFAULT_MAXIMUM_CACHE_SIZE
Constant Value:
20
(0x00000014)
Fields
The first cached node, or null
if no nodes are cached.
Cached nodes are stored in a singly-linked list with
next
pointing to the next element.
protected
int
maximumCacheSize
The maximum size of the cache.
Public Constructors
public
NodeCachingLinkedList
()
Constructor that creates.
public
NodeCachingLinkedList
(Collection coll)
Constructor that copies the specified collection
Parameters
coll
| the collection to copy
|
public
NodeCachingLinkedList
(int maximumCacheSize)
Constructor that species the maximum cache size.
Parameters
maximumCacheSize
| the maximum cache size
|
Protected Methods
Adds a node to the cache, if the cache isn't full.
The node's contents are cleared to so they can be garbage collected.
Parameters
node
| the node to add to the cache
|
Creates a new node, either by reusing one from the cache or creating
a new one.
Parameters
value
| value of the new node |
protected
int
getMaximumCacheSize
()
Gets the maximum size of the cache.
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.
protected
boolean
isCacheFull
()
Checks whether the cache is full.
Returns
- true if the cache is full
protected
void
removeAllNodes
()
Removes all the nodes from the list, storing as many as required in the
cache for reuse.
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.
Parameters
maximumCacheSize
| the new maximum cache size
|
protected
void
shrinkCacheToMaximumSize
()
Reduce the size of the cache to the maximum, if necessary.