java.lang.Iterable<E>
, java.util.Collection<E>
, java.util.List<E>
CursorableLinkedList
, NodeCachingLinkedList
public abstract class AbstractLinkedList<E>
extends java.lang.Object
implements java.util.List<E>
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.
Modifier and Type | Class | 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.
|
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractLinkedList() |
Constructor that does nothing intended for deserialization.
|
protected |
AbstractLinkedList(java.util.Collection<? extends E> coll) |
Constructs a list copying data from the specified collection.
|
Modifier and Type | Method | Description |
---|---|---|
void |
add(int index,
E value) |
|
boolean |
add(E value) |
|
boolean |
addAll(int index,
java.util.Collection<? extends E> coll) |
|
boolean |
addAll(java.util.Collection<? extends E> coll) |
|
boolean |
addFirst(E o) |
|
boolean |
addLast(E o) |
|
protected void |
addNode(AbstractLinkedList.Node<E> nodeToInsert,
AbstractLinkedList.Node<E> insertBeforeNode) |
Inserts a new node into the list.
|
protected void |
addNodeAfter(AbstractLinkedList.Node<E> node,
E value) |
Creates a new node with the specified object as its
value and inserts it after node . |
protected void |
addNodeBefore(AbstractLinkedList.Node<E> node,
E value) |
Creates a new node with the specified object as its
value and inserts it before node . |
void |
clear() |
|
boolean |
contains(java.lang.Object value) |
|
boolean |
containsAll(java.util.Collection<?> coll) |
|
protected AbstractLinkedList.Node<E> |
createHeaderNode() |
Creates a new node with previous, next and element all set to null.
|
protected AbstractLinkedList.Node<E> |
createNode(E value) |
Creates a new node with the specified properties.
|
protected java.util.Iterator<E> |
createSubListIterator(AbstractLinkedList.LinkedSubList<E> subList) |
Creates an iterator for the sublist.
|
protected java.util.ListIterator<E> |
createSubListListIterator(AbstractLinkedList.LinkedSubList<E> subList,
int fromIndex) |
Creates a list iterator for the sublist.
|
protected void |
doReadObject(java.io.ObjectInputStream inputStream) |
Deserializes the data held in this object to the stream specified.
|
protected void |
doWriteObject(java.io.ObjectOutputStream outputStream) |
Serializes the data held in this object to the stream specified.
|
boolean |
equals(java.lang.Object obj) |
|
E |
get(int index) |
|
E |
getFirst() |
|
E |
getLast() |
|
protected AbstractLinkedList.Node<E> |
getNode(int index,
boolean endMarkerAllowed) |
Gets the node at a particular index.
|
int |
hashCode() |
|
int |
indexOf(java.lang.Object value) |
|
protected void |
init() |
The equivalent of a default constructor, broken out so it can be called
by any constructor and by
readObject . |
boolean |
isEmpty() |
|
protected boolean |
isEqualValue(java.lang.Object value1,
java.lang.Object value2) |
Compares two values for equals.
|
java.util.Iterator<E> |
iterator() |
|
int |
lastIndexOf(java.lang.Object value) |
|
java.util.ListIterator<E> |
listIterator() |
|
java.util.ListIterator<E> |
listIterator(int fromIndex) |
|
E |
remove(int index) |
|
boolean |
remove(java.lang.Object value) |
|
boolean |
removeAll(java.util.Collection<?> coll) |
|
protected void |
removeAllNodes() |
Removes all nodes by resetting the circular list marker.
|
E |
removeFirst() |
|
E |
removeLast() |
|
protected void |
removeNode(AbstractLinkedList.Node<E> node) |
Removes the specified node from the list.
|
boolean |
retainAll(java.util.Collection<?> coll) |
|
E |
set(int index,
E value) |
|
int |
size() |
|
java.util.List<E> |
subList(int fromIndexInclusive,
int toIndexExclusive) |
Gets a sublist of the main list.
|
java.lang.Object[] |
toArray() |
|
<T> T[] |
toArray(T[] array) |
|
java.lang.String |
toString() |
|
protected void |
updateNode(AbstractLinkedList.Node<E> node,
E value) |
Updates the node with a new value.
|
protected AbstractLinkedList()
If this constructor is used by a serializable subclass then the init() method must be called.
protected AbstractLinkedList(java.util.Collection<? extends E> coll)
coll
- the collection to copyprotected void init()
readObject
.
Subclasses which override this method should make sure they call super,
so the list is initialised properly.public int size()
public boolean isEmpty()
public java.util.Iterator<E> iterator()
public java.util.ListIterator<E> listIterator()
listIterator
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator(int fromIndex)
listIterator
in interface java.util.List<E>
public int indexOf(java.lang.Object value)
indexOf
in interface java.util.List<E>
public int lastIndexOf(java.lang.Object value)
lastIndexOf
in interface java.util.List<E>
public boolean contains(java.lang.Object value)
public boolean containsAll(java.util.Collection<?> coll)
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] array)
public java.util.List<E> subList(int fromIndexInclusive, int toIndexExclusive)
subList
in interface java.util.List<E>
fromIndexInclusive
- the index to start fromtoIndexExclusive
- the index to end atpublic boolean add(E value)
public boolean addAll(java.util.Collection<? extends E> coll)
public boolean addAll(int index, java.util.Collection<? extends E> coll)
addAll
in interface java.util.List<E>
public boolean remove(java.lang.Object value)
public boolean removeAll(java.util.Collection<?> coll)
This implementation iterates over the elements of this list, checking each element in
turn to see if it's contained in coll
. If it's contained, it's removed
from this list. As a consequence, it is advised to use a collection type for
coll
that provides a fast (e.g. O(1)) implementation of
Collection.contains(Object)
.
public boolean retainAll(java.util.Collection<?> coll)
This implementation iterates over the elements of this list, checking each element in
turn to see if it's contained in coll
. If it's not contained, it's removed
from this list. As a consequence, it is advised to use a collection type for
coll
that provides a fast (e.g. O(1)) implementation of
Collection.contains(Object)
.
public void clear()
public E getFirst()
public E getLast()
public boolean addFirst(E o)
public boolean addLast(E o)
public E removeFirst()
public E removeLast()
public boolean equals(java.lang.Object obj)
public int hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
protected boolean isEqualValue(java.lang.Object value1, java.lang.Object value2)
value1
- the first value to compare, may be nullvalue2
- the second value to compare, may be nullprotected void updateNode(AbstractLinkedList.Node<E> node, E value)
node
- node to updatevalue
- new value of the nodeprotected AbstractLinkedList.Node<E> createHeaderNode()
protected AbstractLinkedList.Node<E> createNode(E value)
value
- value of the new nodeprotected void addNodeBefore(AbstractLinkedList.Node<E> node, E value)
value
and inserts it before node
.
This implementation uses createNode(Object)
and
addNode(AbstractLinkedList.Node,AbstractLinkedList.Node)
.
node
- node to insert beforevalue
- value of the newly added nodejava.lang.NullPointerException
- if node
is nullprotected void addNodeAfter(AbstractLinkedList.Node<E> node, E value)
value
and inserts it after node
.
This implementation uses createNode(Object)
and
addNode(AbstractLinkedList.Node,AbstractLinkedList.Node)
.
node
- node to insert aftervalue
- value of the newly added nodejava.lang.NullPointerException
- if node
is nullprotected void addNode(AbstractLinkedList.Node<E> nodeToInsert, AbstractLinkedList.Node<E> insertBeforeNode)
nodeToInsert
- new node to insertinsertBeforeNode
- node to insert beforejava.lang.NullPointerException
- if either node is nullprotected void removeNode(AbstractLinkedList.Node<E> node)
node
- the node to removejava.lang.NullPointerException
- if node
is nullprotected void removeAllNodes()
protected AbstractLinkedList.Node<E> getNode(int index, boolean endMarkerAllowed) throws java.lang.IndexOutOfBoundsException
index
- the index, starting from 0endMarkerAllowed
- whether or not the end marker can be returned if
startIndex is set to the list's sizejava.lang.IndexOutOfBoundsException
- 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 listprotected java.util.Iterator<E> createSubListIterator(AbstractLinkedList.LinkedSubList<E> subList)
subList
- the sublist to get an iterator forprotected java.util.ListIterator<E> createSubListListIterator(AbstractLinkedList.LinkedSubList<E> subList, int fromIndex)
subList
- the sublist to get an iterator forfromIndex
- the index to start from, relative to the sublistprotected void doWriteObject(java.io.ObjectOutputStream outputStream) throws java.io.IOException
The first serializable subclass must call this method from
writeObject
.
outputStream
- the stream to write the object tojava.io.IOException
- if anything goes wrongprotected void doReadObject(java.io.ObjectInputStream inputStream) throws java.io.IOException, java.lang.ClassNotFoundException
The first serializable subclass must call this method from
readObject
.
inputStream
- the stream to read the object fromjava.io.IOException
- if any error occurs while reading from the streamjava.lang.ClassNotFoundException
- if a class read from the stream can not be loadedCopyright © 2001-2019 - Apache Software Foundation