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.
add
public boolean add(Object value)
add
public void add(int index,
Object value)
addAll
public boolean addAll(Collection coll)
addAll
public boolean addAll(int index,
Collection coll)
addFirst
public boolean addFirst(Object o)
addLast
public boolean addLast(Object o)
addNodeAfter
protected void addNodeAfter(AbstractLinkedList.Node node,
Object value)
node
- node to insert aftervalue
- value of the newly added node
addNodeBefore
protected void addNodeBefore(AbstractLinkedList.Node node,
Object value)
node
- node to insert beforevalue
- value of the newly added node
contains
public boolean contains(Object value)
containsAll
public boolean containsAll(Collection 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.
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.
value
- value of the new node
createSubListIterator
protected Iterator createSubListIterator(AbstractLinkedList.LinkedSubList subList)
Creates an iterator for the sublist.
subList
- the sublist to get an iterator for
createSubListListIterator
protected ListIterator createSubListListIterator(AbstractLinkedList.LinkedSubList subList,
int fromIndex)
Creates a list iterator for the sublist.
subList
- the sublist to get an iterator forfromIndex
- the index to start from, relative to the sublist
doReadObject
protected void doReadObject(ObjectInputStream inputStream)
throws IOException,
ClassNotFoundException
Deserializes the data held in this object to the stream specified.
The first serializable subclass must call this method from
readObject
.
doWriteObject
protected void doWriteObject(ObjectOutputStream outputStream)
throws IOException
Serializes the data held in this object to the stream specified.
The first serializable subclass must call this method from
writeObject
.
equals
public boolean equals(Object obj)
get
public Object get(int index)
getFirst
public Object getFirst()
getLast
public Object getLast()
getNode
protected AbstractLinkedList.Node getNode(int index,
boolean endMarkerAllowed)
throws IndexOutOfBoundsException
Gets the node at a particular index.
index
- the index, starting from 0endMarkerAllowed
- whether or not the end marker can be returned if
startIndex is set to the list's size
hashCode
public int hashCode()
indexOf
public int indexOf(Object 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.
value1
- the first value to compare, may be nullvalue2
- the second value to compare, may be null
iterator
public Iterator iterator()
lastIndexOf
public int lastIndexOf(Object value)
listIterator
public ListIterator listIterator()
listIterator
public ListIterator listIterator(int fromIndex)
remove
public boolean remove(Object value)
remove
public Object remove(int index)
removeAll
public boolean removeAll(Collection 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.
node
- the node to remove
retainAll
public boolean retainAll(Collection coll)
set
public Object set(int index,
Object value)
subList
public List subList(int fromIndexInclusive,
int toIndexExclusive)
Gets a sublist of the main list.
fromIndexInclusive
- the index to start fromtoIndexExclusive
- the index to end at
toArray
public Object[] toArray()
toArray
public Object[] toArray(Object[] 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.
node
- node to updatevalue
- new value of the node