Top Description Inners Fields Constructors Methods
org.apache.commons.collections4.list

public abstract Class AbstractLinkedList<E>

extends Object
implements List<E>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
org.apache.commons.collections4.list.CursorableLinkedList, org.apache.commons.collections4.list.NodeCachingLinkedList
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, java.lang.reflect.Array, java.util.AbstractList, .Collection, .ConcurrentModificationException, .Iterator, .List, .ListIterator, .NoSuchElementException, org.apache.commons.collections4.OrderedIterator

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
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AbstractLinkedList.LinkedListIterator<E>

A list iterator over the linked list.

protected static class
AbstractLinkedList.LinkedSubList<E>

The sublist implementation for AbstractLinkedList.

protected static class
AbstractLinkedList.LinkedSubListIterator<E>

A list iterator over the linked sub list.

protected static class
AbstractLinkedList.Node<E>

A node within the linked list.

Field Summary

Modifier and TypeField and Description
pack-priv transient AbstractLinkedList.Node<E>
header

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

pack-priv transient int
modCount

Modification count for iterators

pack-priv transient int
size

The size of the list

Constructor Summary

AccessConstructor and Description
protected
AbstractLinkedList()

Constructor that does nothing intended for deserialization.

protected
AbstractLinkedList(final Collection<? extends E>
the collection to copy
coll
)

Constructs a list copying data from the specified collection.

Method Summary

Modifier and TypeMethod and Description
public boolean
add(final E
element to be appended to this list
value
)

Implements java.util.List.add.

Appends the specified element to the end of this list (optional operation).
public void
add(final int
index at which the specified element is to be inserted
index
,
final E
element to be inserted
value
)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).
public boolean
addAll(final Collection<? extends E>
collection containing elements to be added to this list
coll
)

Implements java.util.List.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).
public boolean
addAll(final int
index at which to insert the first element from the specified collection
index
,
final Collection<? extends E>
collection containing elements to be added to this list
coll
)

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
public boolean
addFirst(final E
the element to be added
o
)

Overrides default java.util.List.addFirst.

Adds an element as the first element of this collection (optional operation).
public boolean
addLast(final E
the element to be added.
o
)

Overrides default java.util.List.addLast.

Adds an element as the last element of this collection (optional operation).
protected void
addNode(final AbstractLinkedList.Node<E>
new node to insert
nodeToInsert
,
final AbstractLinkedList.Node<E>
node to insert before
insertBeforeNode
)

Inserts a new node into the list.

protected void
addNodeAfter(final AbstractLinkedList.Node<E>
node to insert after
node
,
final E
value of the newly added node
value
)

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

protected void
addNodeBefore(final AbstractLinkedList.Node<E>
node to insert before
node
,
final E
value of the newly added node
value
)

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

public void
clear()

Implements java.util.List.clear.

Removes all of the elements from this list (optional operation).
public boolean
contains(final Object
element whose presence in this list is to be tested
value
)

Implements java.util.List.contains.

Returns true if this list contains the specified element.
public boolean
containsAll(final Collection<?>
collection to be checked for containment in this list
coll
)

Implements java.util.List.containsAll.

Returns true if this list contains all of the elements of the specified collection.
protected AbstractLinkedList.Node<E>

Returns:

newly created node
createHeaderNode
()

Creates a new node with previous, next and element all set to null.

protected AbstractLinkedList.Node<E>

Returns:

a new node containing the value
createNode
(final E
value of the new node
value
)

Creates a new node with the specified properties.

protected Iterator<E>

Returns:

a new iterator on the given sublist
createSubListIterator
(final AbstractLinkedList.LinkedSubList<E>
the sublist to get an iterator for
subList
)

Creates an iterator for the sublist.

protected ListIterator<E>

Returns:

a new list iterator on the given sublist
createSubListListIterator
(final AbstractLinkedList.LinkedSubList<E>
the sublist to get an iterator for
subList
,
final int
the index to start from, relative to the sublist
fromIndex
)

Creates a list iterator for the sublist.

protected void
doReadObject(final ObjectInputStream
the stream to read the object from
inputStream
)

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

protected void
doWriteObject(final ObjectOutputStream
the stream to write the object to
outputStream
)

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

public boolean
equals(final Object
the object to be compared for equality with this list
obj
)

Overrides java.lang.Object.equals.

Implements java.util.List.equals.

Compares the specified object with this list for equality.
public E
get(final int
index of the element to return
index
)

Implements java.util.List.get.

Returns the element at the specified position in this list.
public E
getFirst()

Overrides default java.util.List.getFirst.

Gets the first element of this collection.
public E
getLast()

Overrides default java.util.List.getLast.

Gets the last element of this collection.
protected AbstractLinkedList.Node<E>

Returns:

the node at the given index
getNode
(final int
the index, starting from 0
index
,
final boolean
whether or not the end marker can be returned if startIndex is set to the list's size
endMarkerAllowed
)

Gets the node at a particular index.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode.

Returns the hash code value for this list.
public int
indexOf(final Object
element to search for
value
)

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
protected void
init()

The equivalent of a default constructor, broken out so it can be called by any constructor and by readObject.

public boolean
isEmpty()

Implements java.util.List.isEmpty.

Returns true if this list contains no elements.
protected boolean

Returns:

true if equal
isEqualValue
(final Object
the first value to compare, may be null
value1
,
final Object
the second value to compare, may be null
value2
)

Compares two values for equals.

public Iterator<E>
iterator()

Implements java.util.List.iterator.

Returns an iterator over the elements in this list in proper sequence.
public int
lastIndexOf(final Object
element to search for
value
)

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public ListIterator<E>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).
public ListIterator<E>
listIterator(final int
index of the first element to be returned from the list iterator (by a call to next)
fromIndex
)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
public E
remove(final int
the index of the element to be removed
index
)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).
public boolean
remove(final Object
element to be removed from this list, if present
value
)

Implements java.util.List.remove.

Removes the first occurrence of the specified element from this list, if it is present (optional operation).
public boolean
removeAll(final Collection<?>
collection containing elements to be removed from this list
coll
)

Implements java.util.List.removeAll.

Removes from this list all of its elements that are contained in the specified collection (optional operation).
protected void
removeAllNodes()

Removes all nodes by resetting the circular list marker.

public E
removeFirst()

Overrides default java.util.List.removeFirst.

Removes and returns the first element of this collection (optional operation).
public E
removeLast()

Overrides default java.util.List.removeLast.

Removes and returns the last element of this collection (optional operation).
protected void
removeNode(final AbstractLinkedList.Node<E>
the node to remove
node
)

Removes the specified node from the list.

public boolean
retainAll(final Collection<?>
collection containing elements to be retained in this list
coll
)

Implements java.util.List.retainAll.

Retains only the elements in this list that are contained in the specified collection (optional operation).
public E
set(final int
index of the element to replace
index
,
final E
element to be stored at the specified position
value
)

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).
public int
size()

Implements java.util.List.size.

Returns the number of elements in this list.
public List<E>

Returns:

the new sublist
subList
(final int
the index to start from
fromIndexInclusive
,
final int
the index to end at
toIndexExclusive
)

Implements java.util.List.subList.

Gets a sublist of the main list.
public Object[]
toArray()

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element).
public <T> T[]
toArray(T[]
the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
array
)

Implements java.util.List.toArray.

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
protected void
updateNode(final AbstractLinkedList.Node<E>
node to update
node
,
final E
new value of the node
value
)

Updates the node with a new value.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait