Package org.apache.commons.collections4.list

# 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:
  `Iterable<E>`, `Collection<E>`, `List<E>`

Direct Known Subclasses:
  `CursorableLinkedList`, `NodeCachingLinkedList`

@Deprecated public abstract class AbstractLinkedList<E> extends Object implements List<E>
Deprecated.
Use `AbstractLinkedListJava21` instead
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.

Since:
  3.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected static class`
  `AbstractLinkedList.LinkedListIterator<E>`
  Deprecated.
  A list iterator over the linked list.
  `protected static class`
  `AbstractLinkedList.LinkedSubList<E>`
  Deprecated.
  The sublist implementation for AbstractLinkedList.
  `protected static class`
  `AbstractLinkedList.LinkedSubListIterator<E>`
  Deprecated.
  A list iterator over the linked sub list.
  `protected static class`
  `AbstractLinkedList.Node<E>`
  Deprecated.
  A node within the linked list.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractLinkedList()`
  Deprecated.
  Constructor that does nothing (intended for deserialization).
  `protected`
  `AbstractLinkedList(Collection<? extends E> coll)`
  Deprecated.
  Constructs a list copying data from the specified collection.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(int index, E value)`
  Deprecated.
  `boolean`
  `add(E value)`
  Deprecated.
  `boolean`
  `addAll(int index, Collection<? extends E> coll)`
  Deprecated.
  `boolean`
  `addAll(Collection<? extends E> coll)`
  Deprecated.
  `boolean`
  `addFirst(E e)`
  Deprecated.
  Adds an element at the beginning.
  `boolean`
  `addLast(E e)`
  Deprecated.
  Adds an element at the end.
  `protected void`
  `addNode(AbstractLinkedList.Node<E> nodeToInsert, AbstractLinkedList.Node<E> insertBeforeNode)`
  Deprecated.
  Inserts a new node into the list.
  `protected void`
  `addNodeAfter(AbstractLinkedList.Node<E> node, E value)`
  Deprecated.
  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)`
  Deprecated.
  Creates a new node with the specified object as its `value` and inserts it before `node`.
  `void`
  `clear()`
  Deprecated.
  `boolean`
  `contains(Object value)`
  Deprecated.
  `boolean`
  `containsAll(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 Iterator<E>`
  `createSubListIterator(AbstractLinkedList.LinkedSubList<E> subList)`
  Deprecated.
  Creates an iterator for the sublist.
  `protected ListIterator<E>`
  `createSubListListIterator(AbstractLinkedList.LinkedSubList<E> subList, int fromIndex)`
  Deprecated.
  Creates a list iterator for the sublist.
  `protected void`
  `doReadObject(ObjectInputStream inputStream)`
  Deprecated.
  Deserializes the data held in this object to the stream specified.
  `protected void`
  `doWriteObject(ObjectOutputStream outputStream)`
  Deprecated.
  Serializes the data held in this object to the stream specified.
  `boolean`
  `equals(Object obj)`
  Deprecated.
  `E`
  `get(int index)`
  Deprecated.
  `E`
  `getFirst()`
  Deprecated.
  Gets the first element.
  `E`
  `getLast()`
  Deprecated.
  Gets the last element.
  `protected AbstractLinkedList.Node<E>`
  `getNode(int index, boolean endMarkerAllowed)`
  Deprecated.
  Gets the node at a particular index.
  `int`
  `hashCode()`
  Deprecated.
  `int`
  `indexOf(Object value)`
  Deprecated.
  `protected void`
  `init()`
  Deprecated.
  The equivalent of a default constructor, broken out so it can be called by any constructor and by `readObject`.
  `boolean`
  `isEmpty()`
  Deprecated.
  `protected boolean`
  `isEqualValue(Object value1, Object value2)`
  Deprecated.
  Compares two values for equals.
  `Iterator<E>`
  `iterator()`
  Deprecated.
  `int`
  `lastIndexOf(Object value)`
  Deprecated.
  `ListIterator<E>`
  `listIterator()`
  Deprecated.
  `ListIterator<E>`
  `listIterator(int fromIndex)`
  Deprecated.
  `E`
  `remove(int index)`
  Deprecated.
  `boolean`
  `remove(Object value)`
  Deprecated.
  `boolean`
  `removeAll(Collection<?> coll)`
  Deprecated.
  `protected void`
  `removeAllNodes()`
  Deprecated.
  Removes all nodes by resetting the circular list marker.
  `E`
  `removeFirst()`
  Deprecated.
  Removes the first element.
  `E`
  `removeLast()`
  Deprecated.
  Removes the last element.
  `protected void`
  `removeNode(AbstractLinkedList.Node<E> node)`
  Deprecated.
  Removes the specified node from the list.
  `boolean`
  `retainAll(Collection<?> coll)`
  Deprecated.
  `E`
  `set(int index, E value)`
  Deprecated.
  `int`
  `size()`
  Deprecated.
  `List<E>`
  `subList(int fromIndexInclusive, int toIndexExclusive)`
  Deprecated.
  Gets a sublist of the main list.
  `Object[]`
  `toArray()`
  Deprecated.
  `<T> T[]`
  `toArray(T[] array)`
  Deprecated.
  `String`
  `toString()`
  Deprecated.
  `protected void`
  `updateNode(AbstractLinkedList.Node<E> node, E value)`
  Deprecated.
  Updates the node with a new value.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.util.Collection

  `parallelStream, removeIf, stream`

  ### Methods inherited from interface java.lang.Iterable

  `forEach`

  ### Methods inherited from interface java.util.List

  `replaceAll, sort, spliterator`

- ## Constructor Details

  - ### 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(Collection<? extends E> coll)
    Deprecated.
    Constructs a list copying data from the specified collection.
    Parameters:
      `coll` - The collection to copy

- ## Method Details

  - ### add

    public boolean add(E value)
    Deprecated.
    Specified by:
      `add` in interface `Collection<E>`
    Specified by:
      `add` in interface `List<E>`

  - ### add

    public void add(int index, E value)
    Deprecated.
    Specified by:
      `add` in interface `List<E>`

  - ### addAll

    public boolean addAll(Collection<? extends E> coll)
    Deprecated.
    Specified by:
      `addAll` in interface `Collection<E>`
    Specified by:
      `addAll` in interface `List<E>`

  - ### addAll

    public boolean addAll(int index, Collection<? extends E> coll)
    Deprecated.
    Specified by:
      `addAll` in interface `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 insert
      `insertBeforeNode` - node to insert before
    Throws:
      `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 its `value` and inserts it after `node`.

    This implementation uses `createNode(Object)` and `addNode(AbstractLinkedList.Node,AbstractLinkedList.Node)`.

    Parameters:
      `node` - node to insert after
      `value` - value of the newly added node
    Throws:
      `NullPointerException` - if `node` is null

  - ### addNodeBefore

    protected void addNodeBefore(AbstractLinkedList.Node<E> node, E value)
    Deprecated.
    Creates a new node with the specified object as its `value` and inserts it before `node`.

    This implementation uses `createNode(Object)` and `addNode(AbstractLinkedList.Node,AbstractLinkedList.Node)`.

    Parameters:
      `node` - node to insert before
      `value` - value of the newly added node
    Throws:
      `NullPointerException` - if `node` is null

  - ### clear

    public void clear()
    Deprecated.
    Specified by:
      `clear` in interface `Collection<E>`
    Specified by:
      `clear` in interface `List<E>`

  - ### contains

    public boolean contains(Object value)
    Deprecated.
    Specified by:
      `contains` in interface `Collection<E>`
    Specified by:
      `contains` in interface `List<E>`

  - ### containsAll

    public boolean containsAll(Collection<?> coll)
    Deprecated.
    Specified by:
      `containsAll` in interface `Collection<E>`
    Specified by:
      `containsAll` in interface `List<E>`

  - ### 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 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 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 for
      `fromIndex` - The index to start from, relative to the sublist
    Returns:
      A new list iterator on the given sublist

  - ### doReadObject

    protected void doReadObject(ObjectInputStream inputStream) throws IOException, 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:
      `IOException` - if any error occurs while reading from the stream
      `ClassNotFoundException` - if a class read from the stream cannot be loaded

  - ### doWriteObject

    protected void doWriteObject(ObjectOutputStream outputStream) throws 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:
      `IOException` - if anything goes wrong

  - ### equals

    public boolean equals(Object obj)
    Deprecated.
    Specified by:
      `equals` in interface `Collection<E>`
    Specified by:
      `equals` in interface `List<E>`
    Overrides:
      `equals` in class `Object`

  - ### get

    public E get(int index)
    Deprecated.
    Specified by:
      `get` in interface `List<E>`

  - ### getFirst

    public E getFirst()
    Deprecated.
    Gets the first element.
    Returns:
      The first element.

  - ### getLast

    public E getLast()
    Deprecated.
    Gets the last element.
    Returns:
      The last element.

  - ### getNode

    protected AbstractLinkedList.Node<E> getNode(int index, boolean endMarkerAllowed) throws IndexOutOfBoundsException
    Deprecated.
    Gets the node at a particular index.
    Parameters:
      `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
    Returns:
      The node at the given index
    Throws:
      `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.
    Specified by:
      `hashCode` in interface `Collection<E>`
    Specified by:
      `hashCode` in interface `List<E>`
    Overrides:
      `hashCode` in class `Object`

  - ### indexOf

    public int indexOf(Object value)
    Deprecated.
    Specified by:
      `indexOf` in interface `List<E>`

  - ### init

    protected void init()
    Deprecated.
    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 initialized properly.

  - ### isEmpty

    public boolean isEmpty()
    Deprecated.
    Specified by:
      `isEmpty` in interface `Collection<E>`
    Specified by:
      `isEmpty` in interface `List<E>`

  - ### isEqualValue

    protected boolean isEqualValue(Object value1, 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 null
      `value2` - The second value to compare, may be null
    Returns:
      true if equal

  - ### iterator

    public Iterator<E> iterator()
    Deprecated.
    Specified by:
      `iterator` in interface `Collection<E>`
    Specified by:
      `iterator` in interface `Iterable<E>`
    Specified by:
      `iterator` in interface `List<E>`

  - ### lastIndexOf

    public int lastIndexOf(Object value)
    Deprecated.
    Specified by:
      `lastIndexOf` in interface `List<E>`

  - ### listIterator

    public ListIterator<E> listIterator()
    Deprecated.
    Specified by:
      `listIterator` in interface `List<E>`

  - ### listIterator

    public ListIterator<E> listIterator(int fromIndex)
    Deprecated.
    Specified by:
      `listIterator` in interface `List<E>`

  - ### remove

    public E remove(int index)
    Deprecated.
    Specified by:
      `remove` in interface `List<E>`

  - ### remove

    public boolean remove(Object value)
    Deprecated.
    Specified by:
      `remove` in interface `Collection<E>`
    Specified by:
      `remove` in interface `List<E>`

  - ### removeAll

    public boolean removeAll(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 for `coll` that provides a fast (for example O(1)) implementation of `Collection.contains(Object)`.

    Specified by:
      `removeAll` in interface `Collection<E>`
    Specified by:
      `removeAll` in interface `List<E>`

  - ### 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:
      `NullPointerException` - if `node` is null

  - ### retainAll

    public boolean retainAll(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 for `coll` that provides a fast (for example O(1)) implementation of `Collection.contains(Object)`.

    Specified by:
      `retainAll` in interface `Collection<E>`
    Specified by:
      `retainAll` in interface `List<E>`

  - ### set

    public E set(int index, E value)
    Deprecated.
    Specified by:
      `set` in interface `List<E>`

  - ### size

    public int size()
    Deprecated.
    Specified by:
      `size` in interface `Collection<E>`
    Specified by:
      `size` in interface `List<E>`

  - ### subList

    public List<E> subList(int fromIndexInclusive, int toIndexExclusive)
    Deprecated.
    Gets a sublist of the main list.
    Specified by:
      `subList` in interface `List<E>`
    Parameters:
      `fromIndexInclusive` - The index to start from
      `toIndexExclusive` - The index to end at
    Returns:
      The new sublist

  - ### toArray

    public Object[] toArray()
    Deprecated.
    Specified by:
      `toArray` in interface `Collection<E>`
    Specified by:
      `toArray` in interface `List<E>`

  - ### toArray

    public <T> T[] toArray(T[] array)
    Deprecated.
    Specified by:
      `toArray` in interface `Collection<E>`
    Specified by:
      `toArray` in interface `List<E>`

  - ### toString

    public String toString()
    Deprecated.
    Overrides:
      `toString` in class `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 update
      `value` - new value of the node