Class AbstractLinkedList<E>

  • All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>
    Direct Known Subclasses:
    CursorableLinkedList, NodeCachingLinkedList

    public abstract class AbstractLinkedList<E>
    extends java.lang.Object
    implements java.util.List<E>
    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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, E value)  
      boolean add​(E value)  
      boolean addAll​(int index, java.util.Collection<? extends E> coll)  
      boolean addAll​(java.util.Collection<? extends E> coll)  
      boolean addFirst​(E o)  
      boolean addLast​(E o)  
      void clear()  
      boolean contains​(java.lang.Object value)  
      boolean containsAll​(java.util.Collection<?> coll)  
      boolean equals​(java.lang.Object obj)  
      E get​(int index)  
      E getFirst()  
      E getLast()  
      int hashCode()  
      int indexOf​(java.lang.Object value)  
      boolean isEmpty()  
      java.util.Iterator<E> iterator()  
      int lastIndexOf​(java.lang.Object value)  
      java.util.ListIterator<E> listIterator()  
      java.util.ListIterator<E> listIterator​(int fromIndex)  
      E remove​(int index)  
      boolean remove​(java.lang.Object value)  
      boolean removeAll​(java.util.Collection<?> coll)
      E removeFirst()  
      E removeLast()  
      boolean retainAll​(java.util.Collection<?> coll)
      E set​(int index, E value)  
      int size()  
      java.util.List<E> subList​(int fromIndexInclusive, int toIndexExclusive)
      Gets a sublist of the main list.
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] array)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        replaceAll, sort, spliterator
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.List<E>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.List<E>
      • get

        public E get​(int index)
        Specified by:
        get in interface java.util.List<E>
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.List<E>
      • listIterator

        public java.util.ListIterator<E> listIterator()
        Specified by:
        listIterator in interface java.util.List<E>
      • listIterator

        public java.util.ListIterator<E> listIterator​(int fromIndex)
        Specified by:
        listIterator in interface java.util.List<E>
      • indexOf

        public int indexOf​(java.lang.Object value)
        Specified by:
        indexOf in interface java.util.List<E>
      • lastIndexOf

        public int lastIndexOf​(java.lang.Object value)
        Specified by:
        lastIndexOf in interface java.util.List<E>
      • contains

        public boolean contains​(java.lang.Object value)
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.List<E>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> coll)
        Specified by:
        containsAll in interface java.util.Collection<E>
        Specified by:
        containsAll in interface java.util.List<E>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
      • toArray

        public <T> T[] toArray​(T[] array)
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
      • subList

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

        public boolean add​(E value)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.List<E>
      • add

        public void add​(int index,
                        E value)
        Specified by:
        add in interface java.util.List<E>
      • addAll

        public boolean addAll​(java.util.Collection<? extends E> coll)
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface java.util.List<E>
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection<? extends E> coll)
        Specified by:
        addAll in interface java.util.List<E>
      • remove

        public E remove​(int index)
        Specified by:
        remove in interface java.util.List<E>
      • remove

        public boolean remove​(java.lang.Object value)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.List<E>
      • removeAll

        public boolean removeAll​(java.util.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.contains(Object).

        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface java.util.List<E>
      • retainAll

        public boolean retainAll​(java.util.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.contains(Object).

        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.List<E>
      • set

        public E set​(int index,
                     E value)
        Specified by:
        set in interface java.util.List<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<E>
      • getFirst

        public E getFirst()
      • getLast

        public E getLast()
      • addFirst

        public boolean addFirst​(E o)
      • addLast

        public boolean addLast​(E o)
      • removeFirst

        public E removeFirst()
      • removeLast

        public E removeLast()
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Collection<E>
        Specified by:
        equals in interface java.util.List<E>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface java.util.List<E>
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object