⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.list

Class AbstractLinkedList

java.lang.Object
|
+--org.apache.commons.collections.list.AbstractLinkedList

All Implemented Interfaces:
List

Known Direct Subclasses:
CursorableLinkedList, NodeCachingLinkedList


public abstract class AbstractLinkedList
extends java.lang.Object
implements List

An abstract implementation of a linked list which provides numerous points for subclasses to override.

Overridable methods are provided to change the storage node and to change how nodes are added to and removed. Hopefully, all you need for unusual subclasses is here.

Since:
Commons Collections 3.0
Authors:
Rich Dougherty
Phil Steitz
Stephen Colebourne

Field Summary

transient AbstractLinkedList.Node

header

A Node which indicates the start and end of the list and does not hold a value.

transient int

modCount

Modification count for iterators

transient int

size

The size of the list

Constructor Summary

AbstractLinkedList()

Constructor that does nothing intended for deserialization.

AbstractLinkedList(Collection coll)

Constructs a list copying data from the specified collection.

Method Summary

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()

ListIterator

listIterator(int fromIndex)

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[]

toArray(Object[] array)

String

toString()

void

updateNode(AbstractLinkedList.Node node, Object value)

Updates the node with a new value.

Field Details

header

protected transient AbstractLinkedList.Node header

A Node which indicates the start and end of the list and does not hold a value. The value of next is the first item in the list. The value of of previous is the last item in the list.


modCount

protected transient int modCount

Modification count for iterators


size

protected transient int size

The size of the list

Constructor Details

AbstractLinkedList

protected AbstractLinkedList()

Constructor that does nothing intended for deserialization.

If this constructor is used by a serializable subclass then the init() method must be called.


AbstractLinkedList

protected AbstractLinkedList(Collection coll)

Constructs a list copying data from the specified collection.

Parameters:
coll - the collection to copy

Method Details

add

public void add(int index, Object value)

Parameters:
index
value

add

public boolean add(Object value)

Parameters:
value

addAll

public boolean addAll(Collection coll)

Parameters:
coll

addAll

public boolean addAll(int index, Collection coll)

Parameters:
index
coll

addFirst

public boolean addFirst(Object o)

Parameters:
o

addLast

public boolean addLast(Object o)

Parameters:
o

addNode

protected void addNode(AbstractLinkedList.Node nodeToInsert, AbstractLinkedList.Node insertBeforeNode)

Inserts a new node into the list.

Parameters:
nodeToInsert - new node to insert
insertBeforeNode - node to insert before
Throws:
- if either node is null

addNodeAfter

protected void addNodeAfter(AbstractLinkedList.Node node, Object value)

Creates a new node with the specified object as its value and inserts it after node.

This implementation uses createNode(Object) and addNode(AbstractLinkedList.Node,AbstractLinkedList.Node).

Parameters:
node - node to insert after
value - value of the newly added node
Throws:
- if node is null

addNodeBefore

protected void addNodeBefore(AbstractLinkedList.Node node, Object value)

Creates a new node with the specified object as its value and inserts it before node.

This implementation uses createNode(Object) and addNode(AbstractLinkedList.Node,AbstractLinkedList.Node).

Parameters:
node - node to insert before
value - value of the newly added node
Throws:
- if node is null

clear

public void clear()


contains

public boolean contains(Object value)

Parameters:
value

containsAll

public boolean containsAll(Collection coll)

Parameters:
coll

createHeaderNode

protected AbstractLinkedList.Node createHeaderNode()

Creates a new node with previous, next and element all set to null. This implementation creates a new empty Node. Subclasses can override this to create a different class.

Returns:
newly created node

createNode

protected AbstractLinkedList.Node createNode(Object value)

Creates a new node with the specified properties. This implementation creates a new Node with data. Subclasses can override this to create a different class.

Parameters:
value - value of the new node

createSubListIterator

protected Iterator createSubListIterator(AbstractLinkedList.LinkedSubList subList)

Creates an iterator for the sublist.

Parameters:
subList - the sublist to get an iterator for

createSubListListIterator

protected ListIterator createSubListListIterator(AbstractLinkedList.LinkedSubList subList, int fromIndex)

Creates a list iterator for the sublist.

Parameters:
subList - the sublist to get an iterator for
fromIndex - the index to start from, relative to the sublist

doReadObject

protected void doReadObject(ObjectInputStream inputStream)

Deserializes the data held in this object to the stream specified.

The first serializable subclass must call this method from readObject.

Parameters:
inputStream

doWriteObject

protected void doWriteObject(ObjectOutputStream outputStream)

Serializes the data held in this object to the stream specified.

The first serializable subclass must call this method from writeObject.

Parameters:
outputStream

equals

public boolean equals(Object obj)

Parameters:
obj

get

public Object get(int index)

Parameters:
index

getFirst

public Object getFirst()


getLast

public Object getLast()


getNode

protected AbstractLinkedList.Node getNode(int index, boolean endMarkerAllowed)

Gets the node at a particular index.

Parameters:
index - the index, starting from 0
endMarkerAllowed - whether or not the end marker can be returned if startIndex is set to the list's size
Throws:
- if the index is less than 0; equal to the size of the list and endMakerAllowed is false; or greater than the size of the list

hashCode

public int hashCode()


indexOf

public int indexOf(Object value)

Parameters:
value

init

protected void init()

The equivalent of a default constructor, broken out so it can be called by any constructor and by readObject. Subclasses which override this method should make sure they call super, so the list is initialised properly.


isEmpty

public boolean isEmpty()


isEqualValue

protected boolean isEqualValue(Object value1, Object value2)

Compares two values for equals. This implementation uses the equals method. Subclasses can override this to match differently.

Parameters:
value1 - the first value to compare, may be null
value2 - the second value to compare, may be null
Returns:
true if equal

iterator

public Iterator iterator()


lastIndexOf

public int lastIndexOf(Object value)

Parameters:
value

listIterator

public ListIterator listIterator()


listIterator

public ListIterator listIterator(int fromIndex)

Parameters:
fromIndex

remove

public Object remove(int index)

Parameters:
index

remove

public boolean remove(Object value)

Parameters:
value

removeAll

public boolean removeAll(Collection coll)

Parameters:
coll

removeAllNodes

protected void removeAllNodes()

Removes all nodes by resetting the circular list marker.


removeFirst

public Object removeFirst()


removeLast

public Object removeLast()


removeNode

protected void removeNode(AbstractLinkedList.Node node)

Removes the specified node from the list.

Parameters:
node - the node to remove
Throws:
- if node is null

retainAll

public boolean retainAll(Collection coll)

Parameters:
coll

set

public Object set(int index, Object value)

Parameters:
index
value

size

public int size()


subList

public List subList(int fromIndexInclusive, int toIndexExclusive)

Gets a sublist of the main list.

Parameters:
fromIndexInclusive - the index to start from
toIndexExclusive - the index to end at
Returns:
the new sublist

toArray

public Object[] toArray()


toArray

public Object[] toArray(Object[] array)

Parameters:
array

toString

public String toString()


updateNode

protected void updateNode(AbstractLinkedList.Node node, Object value)

Updates the node with a new value. This implementation sets the value on the node. Subclasses can override this to record the change.

Parameters:
node - node to update
value - new value of the node