public abstract class AbstractLinkedList<E> extends Objectimplements 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 and Description |
|---|---|
protected static class |
AbstractLinkedList
A list iterator over the linked list.
|
protected static class |
AbstractLinkedList
The sublist implementation for AbstractLinkedList.
|
protected static class |
AbstractLinkedList
A list iterator over the linked sub list.
|
protected static class |
AbstractLinkedList
A node within the linked list.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractLinkedList()
Constructor that does nothing intended for deserialization.
|
protected |
AbstractLinkedList(Collection
Constructs a list copying data from the specified collection.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E value)
|
void |
add(int index, E value)
|
boolean |
addAll(Collection
|
boolean |
addAll(int index, Collection
|
boolean |
addFirst(E o)
|
boolean |
addLast(E o)
|
protected void |
addNode(AbstractLinkedList
Inserts a new node into the list.
|
protected void |
addNodeAfter(AbstractLinkedList
Creates a new node with the specified object as its
value and inserts it after
node.
|
protected void |
addNodeBefore(AbstractLinkedList
Creates a new node with the specified object as its
value and inserts it before
node.
|
void |
clear()
|
boolean |
contains(Object
|
boolean |
containsAll(Collection
|
protected AbstractLinkedList |
createHeaderNode()
Creates a new node with previous, next and element all set to null.
|
protected AbstractLinkedList |
createNode(E value)
Creates a new node with the specified properties.
|
protected Iterator |
createSubListIterator(AbstractLinkedList
Creates an iterator for the sublist.
|
protected ListIterator |
createSubListListIterator(AbstractLinkedList
Creates a list iterator for the sublist.
|
protected void |
doReadObject(ObjectInputStream
Deserializes the data held in this object to the stream specified.
|
protected void |
doWriteObject(ObjectOutputStream
Serializes the data held in this object to the stream specified.
|
boolean |
equals(Object
|
E |
get(int index)
|
E |
getFirst()
|
E |
getLast()
|
protected AbstractLinkedList |
getNode(int index, boolean endMarkerAllowed)
Gets the node at a particular index.
|
int |
hashCode()
|
int |
indexOf(Object
|
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
Compares two values for equals.
|
Iterator |
iterator()
|
int |
lastIndexOf(Object
|
ListIterator |
listIterator()
|
ListIterator |
listIterator(int fromIndex)
|
E |
remove(int index)
|
boolean |
remove(Object
|
boolean |
removeAll(Collection
|
protected void |
removeAllNodes()
Removes all nodes by resetting the circular list marker.
|
E |
removeFirst()
|
E |
removeLast()
|
protected void |
removeNode(AbstractLinkedList
Removes the specified node from the list.
|
boolean |
retainAll(Collection
|
E |
set(int index, E value)
|
int |
size()
|
List |
subList(int fromIndexInclusive, int toIndexExclusive)
Gets a sublist of the main list.
|
Object |
toArray()
|
<T> T[] |
toArray(T[] array)
|
String |
toString()
|
protected void |
updateNode(AbstractLinkedList
Updates the node with a new value.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitreplaceAll, sort, spliteratorparallelStream, removeIf, streamprotected AbstractLinkedList()
If this constructor is used by a serializable subclass then the init() method must be called.
protected AbstractLinkedList(Collection<? extends E> coll)
coll - the collection to copy
protected 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 E get(int index)
public ListIterator<E> listIterator()
public ListIterator<E> listIterator(int fromIndex)
public int indexOf(Objectvalue)
public int lastIndexOf(Objectvalue)
public boolean contains(Objectvalue)
public boolean containsAll(Collection<?> coll)
public Object[] toArray()
public <T> T[] toArray(T[] array)
public List<E> subList(int fromIndexInclusive, int toIndexExclusive)
public boolean add(E value)
public void add(int index,
E value)public boolean addAll(Collection<? extends E> coll)
public boolean addAll(int index,
Collection<? extends E> coll) public E remove(int index)
public boolean remove(Objectvalue)
public boolean removeAll(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.
public boolean retainAll(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.
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(Objectobj)
public int hashCode()
public StringtoString()
protected boolean isEqualValue(Objectvalue1, Object value2)
value1 - the first value to compare, may be null
value2 - the second value to compare, may be null
protected void updateNode(AbstractLinkedList.Node <E> node, E value)
node - node to update
value - new value of the node
protected AbstractLinkedList.Node <E> createHeaderNode()
protected AbstractLinkedList.Node <E> createNode(E value)
value - value of the new node
protected 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 before
value - value of the newly added node
NullPointerException - if
node is null
protected 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 after
value - value of the newly added node
NullPointerException - if
node is null
protected void addNode(AbstractLinkedList.Node <E> nodeToInsert, AbstractLinkedList .Node <E> insertBeforeNode)
nodeToInsert - new node to insert
insertBeforeNode - node to insert before
NullPointerException - if either node is null
protected void removeNode(AbstractLinkedList.Node <E> node)
node - the node to remove
NullPointerException - if
node is null
protected void removeAllNodes()
protected AbstractLinkedList.Node <E> getNode(int index, boolean endMarkerAllowed) throws IndexOutOfBoundsException
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
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 list
protected Iterator<E> createSubListIterator(AbstractLinkedList .LinkedSubList <E> subList)
subList - the sublist to get an iterator for
protected ListIterator<E> createSubListListIterator(AbstractLinkedList .LinkedSubList <E> subList, int fromIndex)
subList - the sublist to get an iterator for
fromIndex - the index to start from, relative to the sublist
protected void doWriteObject(ObjectOutputStreamoutputStream) throws IOException
The first serializable subclass must call this method from writeObject.
outputStream - the stream to write the object to
IOException - if anything goes wrong
protected void doReadObject(ObjectInputStreaminputStream) throws IOException , ClassNotFoundException
The first serializable subclass must call this method from readObject.
inputStream - the stream to read the object from
IOException - if any error occurs while reading from the stream
ClassNotFoundException - if a class read from the stream can not be loaded