Class AbstractLinkedList<E>
- java.lang.Object
-
- org.apache.commons.collections4.list.AbstractLinkedList<E>
-
- Type Parameters:
E- the type of elements in this list
- All Implemented Interfaces:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>
- Direct Known Subclasses:
CursorableLinkedList,NodeCachingLinkedList
@Deprecated public abstract class AbstractLinkedList<E> extends java.lang.Object implements java.util.List<E>
Deprecated.useAbstractLinkedListJava21insteadAn 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 Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractLinkedList.LinkedListIterator<E>Deprecated.A list iterator over the linked list.protected static classAbstractLinkedList.LinkedSubList<E>Deprecated.The sublist implementation for AbstractLinkedList.protected static classAbstractLinkedList.LinkedSubListIterator<E>Deprecated.A list iterator over the linked sub list.protected static classAbstractLinkedList.Node<E>Deprecated.A node within the linked list.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractLinkedList()Deprecated.Constructor that does nothing (intended for deserialization).protectedAbstractLinkedList(java.util.Collection<? extends E> coll)Deprecated.Constructs a list copying data from the specified collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(int index, E value)Deprecated.booleanadd(E value)Deprecated.booleanaddAll(int index, java.util.Collection<? extends E> coll)Deprecated.booleanaddAll(java.util.Collection<? extends E> coll)Deprecated.booleanaddFirst(E e)Deprecated.Adds an element at the beginning.booleanaddLast(E e)Deprecated.Adds an element at the end.protected voidaddNode(AbstractLinkedList.Node<E> nodeToInsert, AbstractLinkedList.Node<E> insertBeforeNode)Deprecated.Inserts a new node into the list.protected voidaddNodeAfter(AbstractLinkedList.Node<E> node, E value)Deprecated.Creates a new node with the specified object as itsvalueand inserts it afternode.protected voidaddNodeBefore(AbstractLinkedList.Node<E> node, E value)Deprecated.Creates a new node with the specified object as itsvalueand inserts it beforenode.voidclear()Deprecated.booleancontains(java.lang.Object value)Deprecated.booleancontainsAll(java.util.Collection<?> coll)Deprecated.protected AbstractLinkedList.Node<E>createHeaderNode()Deprecated.Creates a new node with previous, next and element all set to null.protected AbstractLinkedList.Node<E>createNode(E value)Deprecated.Creates a new node with the specified properties.protected java.util.Iterator<E>createSubListIterator(AbstractLinkedList.LinkedSubList<E> subList)Deprecated.Creates an iterator for the sublist.protected java.util.ListIterator<E>createSubListListIterator(AbstractLinkedList.LinkedSubList<E> subList, int fromIndex)Deprecated.Creates a list iterator for the sublist.protected voiddoReadObject(java.io.ObjectInputStream inputStream)Deprecated.Deserializes the data held in this object to the stream specified.protected voiddoWriteObject(java.io.ObjectOutputStream outputStream)Deprecated.Serializes the data held in this object to the stream specified.booleanequals(java.lang.Object obj)Deprecated.Eget(int index)Deprecated.EgetFirst()Deprecated.Gets the first element.EgetLast()Deprecated.Gets the last element.protected AbstractLinkedList.Node<E>getNode(int index, boolean endMarkerAllowed)Deprecated.Gets the node at a particular index.inthashCode()Deprecated.intindexOf(java.lang.Object value)Deprecated.protected voidinit()Deprecated.The equivalent of a default constructor, broken out so it can be called by any constructor and byreadObject.booleanisEmpty()Deprecated.protected booleanisEqualValue(java.lang.Object value1, java.lang.Object value2)Deprecated.Compares two values for equals.java.util.Iterator<E>iterator()Deprecated.intlastIndexOf(java.lang.Object value)Deprecated.java.util.ListIterator<E>listIterator()Deprecated.java.util.ListIterator<E>listIterator(int fromIndex)Deprecated.Eremove(int index)Deprecated.booleanremove(java.lang.Object value)Deprecated.booleanremoveAll(java.util.Collection<?> coll)Deprecated.protected voidremoveAllNodes()Deprecated.Removes all nodes by resetting the circular list marker.EremoveFirst()Deprecated.Removes the first element.EremoveLast()Deprecated.Removes the last element.protected voidremoveNode(AbstractLinkedList.Node<E> node)Deprecated.Removes the specified node from the list.booleanretainAll(java.util.Collection<?> coll)Deprecated.Eset(int index, E value)Deprecated.intsize()Deprecated.java.util.List<E>subList(int fromIndexInclusive, int toIndexExclusive)Deprecated.Gets a sublist of the main list.java.lang.Object[]toArray()Deprecated.<T> T[]toArray(T[] array)Deprecated.java.lang.StringtoString()Deprecated.protected voidupdateNode(AbstractLinkedList.Node<E> node, E value)Deprecated.Updates the node with a new value.
-
-
-
Constructor Detail
-
AbstractLinkedList
protected AbstractLinkedList()
Deprecated.Constructor that does nothing (intended for deserialization).If this constructor is used by a serializable subclass then the init() method must be called.
-
AbstractLinkedList
protected AbstractLinkedList(java.util.Collection<? extends E> coll)
Deprecated.Constructs a list copying data from the specified collection.- Parameters:
coll- the collection to copy
-
-
Method Detail
-
add
public void add(int index, E value)
Deprecated.- Specified by:
addin interfacejava.util.List<E>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> coll)
Deprecated.- Specified by:
addAllin interfacejava.util.List<E>
-
addFirst
public boolean addFirst(E e)
Deprecated.Adds an element at the beginning.- Parameters:
e- the element to beginning.- Returns:
- true.
-
addLast
public boolean addLast(E e)
Deprecated.Adds an element at the end.- Parameters:
e- the element to add.- Returns:
- true.
-
addNode
protected void addNode(AbstractLinkedList.Node<E> nodeToInsert, AbstractLinkedList.Node<E> insertBeforeNode)
Deprecated.Inserts a new node into the list.- Parameters:
nodeToInsert- new node to insertinsertBeforeNode- node to insert before- Throws:
java.lang.NullPointerException- if either node is null
-
addNodeAfter
protected void addNodeAfter(AbstractLinkedList.Node<E> node, E value)
Deprecated.Creates a new node with the specified object as itsvalueand inserts it afternode.This implementation uses
createNode(Object)andaddNode(AbstractLinkedList.Node,AbstractLinkedList.Node).- Parameters:
node- node to insert aftervalue- value of the newly added node- Throws:
java.lang.NullPointerException- ifnodeis null
-
addNodeBefore
protected void addNodeBefore(AbstractLinkedList.Node<E> node, E value)
Deprecated.Creates a new node with the specified object as itsvalueand inserts it beforenode.This implementation uses
createNode(Object)andaddNode(AbstractLinkedList.Node,AbstractLinkedList.Node).- Parameters:
node- node to insert beforevalue- value of the newly added node- Throws:
java.lang.NullPointerException- ifnodeis null
-
clear
public void clear()
Deprecated.
-
contains
public boolean contains(java.lang.Object value)
Deprecated.
-
containsAll
public boolean containsAll(java.util.Collection<?> coll)
Deprecated.
-
createHeaderNode
protected AbstractLinkedList.Node<E> createHeaderNode()
Deprecated.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.- Returns:
- newly created node
-
createNode
protected AbstractLinkedList.Node<E> createNode(E value)
Deprecated.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.- Parameters:
value- value of the new node- Returns:
- a new node containing the value
-
createSubListIterator
protected java.util.Iterator<E> createSubListIterator(AbstractLinkedList.LinkedSubList<E> subList)
Deprecated.Creates an iterator for the sublist.- Parameters:
subList- the sublist to get an iterator for- Returns:
- a new iterator on the given sublist
-
createSubListListIterator
protected java.util.ListIterator<E> createSubListListIterator(AbstractLinkedList.LinkedSubList<E> subList, int fromIndex)
Deprecated.Creates a list iterator for the sublist.- Parameters:
subList- the sublist to get an iterator forfromIndex- the index to start from, relative to the sublist- Returns:
- a new list iterator on the given sublist
-
doReadObject
protected void doReadObject(java.io.ObjectInputStream inputStream) throws java.io.IOException, java.lang.ClassNotFoundException
Deprecated.Deserializes the data held in this object to the stream specified.The first serializable subclass must call this method from
readObject.- Parameters:
inputStream- the stream to read the object from- Throws:
java.io.IOException- if any error occurs while reading from the streamjava.lang.ClassNotFoundException- if a class read from the stream cannot be loaded
-
doWriteObject
protected void doWriteObject(java.io.ObjectOutputStream outputStream) throws java.io.IOException
Deprecated.Serializes the data held in this object to the stream specified.The first serializable subclass must call this method from
writeObject.- Parameters:
outputStream- the stream to write the object to- Throws:
java.io.IOException- if anything goes wrong
-
equals
public boolean equals(java.lang.Object obj)
Deprecated.
-
getNode
protected AbstractLinkedList.Node<E> getNode(int index, boolean endMarkerAllowed) throws java.lang.IndexOutOfBoundsException
Deprecated.Gets the node at a particular index.- Parameters:
index- the index, starting from 0endMarkerAllowed- whether or not the end marker can be returned if startIndex is set to the list's size- Returns:
- the node at the given index
- Throws:
java.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 list
-
hashCode
public int hashCode()
Deprecated.
-
indexOf
public int indexOf(java.lang.Object value)
Deprecated.- Specified by:
indexOfin interfacejava.util.List<E>
-
init
protected void init()
Deprecated.The equivalent of a default constructor, broken out so it can be called by any constructor and byreadObject. Subclasses which override this method should make sure they call super, so the list is initialized properly.
-
isEmpty
public boolean isEmpty()
Deprecated.
-
isEqualValue
protected boolean isEqualValue(java.lang.Object value1, java.lang.Object value2)
Deprecated.Compares two values for equals. This implementation uses the equals method. Subclasses can override this to match differently.- Parameters:
value1- the first value to compare, may be nullvalue2- the second value to compare, may be null- Returns:
- true if equal
-
lastIndexOf
public int lastIndexOf(java.lang.Object value)
Deprecated.- Specified by:
lastIndexOfin interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator()
Deprecated.- Specified by:
listIteratorin interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator(int fromIndex)
Deprecated.- Specified by:
listIteratorin interfacejava.util.List<E>
-
remove
public boolean remove(java.lang.Object value)
Deprecated.
-
removeAll
public boolean removeAll(java.util.Collection<?> coll)
Deprecated.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 forcollthat provides a fast (for example O(1)) implementation ofCollection.contains(Object).
-
removeAllNodes
protected void removeAllNodes()
Deprecated.Removes all nodes by resetting the circular list marker.
-
removeFirst
public E removeFirst()
Deprecated.Removes the first element.- Returns:
- The value removed.
-
removeLast
public E removeLast()
Deprecated.Removes the last element.- Returns:
- The value removed.
-
removeNode
protected void removeNode(AbstractLinkedList.Node<E> node)
Deprecated.Removes the specified node from the list.- Parameters:
node- the node to remove- Throws:
java.lang.NullPointerException- ifnodeis null
-
retainAll
public boolean retainAll(java.util.Collection<?> coll)
Deprecated.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 forcollthat provides a fast (for example O(1)) implementation ofCollection.contains(Object).
-
size
public int size()
Deprecated.
-
subList
public java.util.List<E> subList(int fromIndexInclusive, int toIndexExclusive)
Deprecated.Gets a sublist of the main list.- Specified by:
subListin interfacejava.util.List<E>- Parameters:
fromIndexInclusive- the index to start fromtoIndexExclusive- the index to end at- Returns:
- the new sublist
-
toArray
public java.lang.Object[] toArray()
Deprecated.
-
toArray
public <T> T[] toArray(T[] array)
Deprecated.
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toStringin classjava.lang.Object
-
updateNode
protected void updateNode(AbstractLinkedList.Node<E> node, E value)
Deprecated.Updates the node with a new value. This implementation sets the value on the node. Subclasses can override this to record the change.- Parameters:
node- node to updatevalue- new value of the node
-
-