Class AbstractLinkedListJava21<E>
- Type Parameters:
- E- the type of elements in this list
- All Implemented Interfaces:
- Iterable<E>,- Collection<E>,- 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.
This is a copy of AbstractLinkedList, modified to be compatible with Java 21 (see COLLECTIONS-842 for details).
- Since:
- 4.5.0-M3
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classA list iterator over the linked list.protected static classThe sublist implementation for AbstractLinkedListJava21.protected static classA list iterator over the linked sub list.protected static classA node within the linked list.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstructor that does nothing (intended for deserialization).protectedAbstractLinkedListJava21(Collection<? extends E> coll) Constructs a list copying data from the specified collection.
- 
Method SummaryModifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> coll) booleanaddAll(Collection<? extends E> coll) voidvoidprotected voidaddNode(AbstractLinkedListJava21.Node<E> nodeToInsert, AbstractLinkedListJava21.Node<E> insertBeforeNode) Inserts a new node into the list.protected voidaddNodeAfter(AbstractLinkedListJava21.Node<E> node, E value) Creates a new node with the specified object as itsvalueand inserts it afternode.protected voidaddNodeBefore(AbstractLinkedListJava21.Node<E> node, E value) Creates a new node with the specified object as itsvalueand inserts it beforenode.voidclear()booleanbooleancontainsAll(Collection<?> coll) protected AbstractLinkedListJava21.Node<E> Creates a new node with previous, next and element all set to null.protected AbstractLinkedListJava21.Node<E> createNode(E value) Creates a new node with the specified properties.Creates an iterator for the sublist.protected ListIterator<E> createSubListListIterator(AbstractLinkedListJava21.LinkedSubList<E> subList, int fromIndex) Creates a list iterator for the sublist.protected voiddoReadObject(ObjectInputStream inputStream) Deserializes the data held in this object to the stream specified.protected voiddoWriteObject(ObjectOutputStream outputStream) Serializes the data held in this object to the stream specified.booleanget(int index) getFirst()getLast()protected AbstractLinkedListJava21.Node<E> getNode(int index, boolean endMarkerAllowed) Gets the node at a particular index.inthashCode()intprotected voidinit()The equivalent of a default constructor, broken out so it can be called by any constructor and byreadObject.booleanisEmpty()protected booleanisEqualValue(Object value1, Object value2) Compares two values for equals.iterator()intlastIndexOf(Object value) listIterator(int fromIndex) remove(int index) booleanbooleanremoveAll(Collection<?> coll) protected voidRemoves all nodes by resetting the circular list marker.protected voidRemoves the specified node from the list.booleanretainAll(Collection<?> coll) intsize()subList(int fromIndexInclusive, int toIndexExclusive) Gets a sublist of the main list.Object[]toArray()<T> T[]toArray(T[] array) toString()protected voidupdateNode(AbstractLinkedListJava21.Node<E> node, E value) Updates the node with a new value.Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, removeIf, streamMethods inherited from interface java.util.ListreplaceAll, sort, spliterator
- 
Constructor Details- 
AbstractLinkedListJava21protected AbstractLinkedListJava21()Constructor that does nothing (intended for deserialization).If this constructor is used by a serializable subclass then the init() method must be called. 
- 
AbstractLinkedListJava21Constructs a list copying data from the specified collection.- Parameters:
- coll- the collection to copy
 
 
- 
- 
Method Details- 
add
- 
add
- 
addAll
- 
addAll
- 
addFirst
- 
addLast
- 
addNodeprotected void addNode(AbstractLinkedListJava21.Node<E> nodeToInsert, AbstractLinkedListJava21.Node<E> insertBeforeNode) 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
 
- 
addNodeAfterCreates a new node with the specified object as itsvalueand inserts it afternode.This implementation uses createNode(Object)andaddNode(AbstractLinkedListJava21.Node,AbstractLinkedListJava21.Node).- Parameters:
- node- node to insert after
- value- value of the newly added node
- Throws:
- NullPointerException- if- nodeis null
 
- 
addNodeBeforeCreates a new node with the specified object as itsvalueand inserts it beforenode.This implementation uses createNode(Object)andaddNode(AbstractLinkedListJava21.Node,AbstractLinkedListJava21.Node).- Parameters:
- node- node to insert before
- value- value of the newly added node
- Throws:
- NullPointerException- if- nodeis null
 
- 
clear
- 
contains
- 
containsAll- Specified by:
- containsAllin interface- Collection<E>
- Specified by:
- containsAllin interface- List<E>
 
- 
createHeaderNodeCreates 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
 
- 
createNodeCreates 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
 
- 
createSubListIteratorCreates an iterator for the sublist.- Parameters:
- subList- the sublist to get an iterator for
- Returns:
- a new iterator on the given sublist
 
- 
createSubListListIteratorprotected ListIterator<E> createSubListListIterator(AbstractLinkedListJava21.LinkedSubList<E> subList, int fromIndex) 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
 
- 
doReadObjectprotected 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.- 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
 
- 
doWriteObjectSerializes 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
- 
get
- 
getFirst
- 
getLast
- 
getNodeprotected AbstractLinkedListJava21.Node<E> getNode(int index, boolean endMarkerAllowed) throws IndexOutOfBoundsException 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
- 
indexOf
- 
initThe 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
- 
isEqualValueCompares 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
- 
lastIndexOf- Specified by:
- lastIndexOfin interface- List<E>
 
- 
listIterator- Specified by:
- listIteratorin interface- List<E>
 
- 
listIterator- Specified by:
- listIteratorin interface- List<E>
 
- 
remove
- 
remove
- 
removeAllThis 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).
- 
removeAllNodesRemoves all nodes by resetting the circular list marker.
- 
removeFirst
- 
removeLast
- 
removeNodeRemoves the specified node from the list.- Parameters:
- node- the node to remove
- Throws:
- NullPointerException- if- nodeis null
 
- 
retainAllThis 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).
- 
set
- 
size
- 
subList
- 
toArray
- 
toArray
- 
toString
- 
updateNodeUpdates 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
 
 
-