public abstract class AbstractLinkedList extends Object implements List
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 and Description |
---|---|
protected static class |
AbstractLinkedList.LinkedListIterator
A list iterator over the linked list.
|
protected static class |
AbstractLinkedList.LinkedSubList
The sublist implementation for AbstractLinkedList.
|
protected static class |
AbstractLinkedList.LinkedSubListIterator
A list iterator over the linked sub list.
|
protected static class |
AbstractLinkedList.Node
A node within the linked list.
|
Modifier and Type | Field and Description |
---|---|
protected AbstractLinkedList.Node |
header
A
AbstractLinkedList.Node which indicates the start and end of the list and does not
hold a value. |
protected int |
modCount
Modification count for iterators
|
protected int |
size
The size of the list
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractLinkedList()
Constructor that does nothing intended for deserialization.
|
protected |
AbstractLinkedList(Collection coll)
Constructs a list copying data from the specified collection.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
Object value) |
boolean |
add(Object value) |
boolean |
addAll(Collection coll) |
boolean |
addAll(int index,
Collection coll) |
boolean |
addFirst(Object o) |
boolean |
addLast(Object o) |
protected void |
addNode(AbstractLinkedList.Node nodeToInsert,
AbstractLinkedList.Node insertBeforeNode)
Inserts a new node into the list.
|
protected void |
addNodeAfter(AbstractLinkedList.Node node,
Object value)
Creates a new node with the specified object as its
value and inserts it after node . |
protected 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) |
protected AbstractLinkedList.Node |
createHeaderNode()
Creates a new node with previous, next and element all set to null.
|
protected AbstractLinkedList.Node |
createNode(Object value)
Creates a new node with the specified properties.
|
protected Iterator |
createSubListIterator(AbstractLinkedList.LinkedSubList subList)
Creates an iterator for the sublist.
|
protected ListIterator |
createSubListListIterator(AbstractLinkedList.LinkedSubList subList,
int fromIndex)
Creates a list iterator for the sublist.
|
protected void |
doReadObject(ObjectInputStream inputStream)
Deserializes the data held in this object to the stream specified.
|
protected 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() |
protected AbstractLinkedList.Node |
getNode(int index,
boolean endMarkerAllowed)
Gets the node at a particular index.
|
int |
hashCode() |
int |
indexOf(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(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) |
protected void |
removeAllNodes()
Removes all nodes by resetting the circular list marker.
|
Object |
removeFirst() |
Object |
removeLast() |
protected 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() |
protected void |
updateNode(AbstractLinkedList.Node node,
Object value)
Updates the node with a new value.
|
protected transient AbstractLinkedList.Node header
AbstractLinkedList.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.protected transient int size
protected transient int modCount
protected AbstractLinkedList()
If this constructor is used by a serializable subclass then the init() method must be called.
protected AbstractLinkedList(Collection 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()
size
in interface Collection
size
in interface List
public boolean isEmpty()
isEmpty
in interface Collection
isEmpty
in interface List
public Iterator iterator()
public ListIterator listIterator()
listIterator
in interface List
public ListIterator listIterator(int fromIndex)
listIterator
in interface List
public int lastIndexOf(Object value)
lastIndexOf
in interface List
public boolean contains(Object value)
contains
in interface Collection
contains
in interface List
public boolean containsAll(Collection coll)
containsAll
in interface Collection
containsAll
in interface List
public Object[] toArray()
toArray
in interface Collection
toArray
in interface List
public Object[] toArray(Object[] array)
toArray
in interface Collection
toArray
in interface List
public List subList(int fromIndexInclusive, int toIndexExclusive)
public boolean add(Object value)
add
in interface Collection
add
in interface List
public boolean addAll(Collection coll)
addAll
in interface Collection
addAll
in interface List
public boolean addAll(int index, Collection coll)
public boolean remove(Object value)
remove
in interface Collection
remove
in interface List
public boolean removeAll(Collection coll)
removeAll
in interface Collection
removeAll
in interface List
public boolean retainAll(Collection coll)
retainAll
in interface Collection
retainAll
in interface List
public void clear()
clear
in interface Collection
clear
in interface List
public Object getFirst()
public Object getLast()
public boolean addFirst(Object o)
public boolean addLast(Object o)
public Object removeFirst()
public Object removeLast()
public boolean equals(Object obj)
public int hashCode()
protected boolean isEqualValue(Object value1, Object value2)
value1
- the first value to compare, may be nullvalue2
- the second value to compare, may be nullprotected void updateNode(AbstractLinkedList.Node node, Object value)
node
- node to updatevalue
- new value of the nodeprotected AbstractLinkedList.Node createHeaderNode()
protected AbstractLinkedList.Node createNode(Object value)
value
- value of the new nodeprotected void addNodeBefore(AbstractLinkedList.Node node, Object 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 nodeNullPointerException
- if node
is nullprotected void addNodeAfter(AbstractLinkedList.Node node, Object 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 nodeNullPointerException
- if node
is nullprotected void addNode(AbstractLinkedList.Node nodeToInsert, AbstractLinkedList.Node insertBeforeNode)
nodeToInsert
- new node to insertinsertBeforeNode
- node to insert beforeNullPointerException
- if either node is nullprotected void removeNode(AbstractLinkedList.Node node)
node
- the node to removeNullPointerException
- if node
is nullprotected void removeAllNodes()
protected AbstractLinkedList.Node getNode(int index, boolean endMarkerAllowed) throws IndexOutOfBoundsException
index
- the index, starting from 0endMarkerAllowed
- whether or not the end marker can be returned if
startIndex is set to the list's sizeIndexOutOfBoundsException
- 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 Iterator createSubListIterator(AbstractLinkedList.LinkedSubList subList)
subList
- the sublist to get an iterator forprotected ListIterator createSubListListIterator(AbstractLinkedList.LinkedSubList subList, int fromIndex)
subList
- the sublist to get an iterator forfromIndex
- the index to start from, relative to the sublistprotected void doWriteObject(ObjectOutputStream outputStream) throws IOException
The first serializable subclass must call this method from
writeObject
.
IOException
protected void doReadObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException
The first serializable subclass must call this method from
readObject
.
IOException
ClassNotFoundException
Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.