Class AbstractLinkedList<E>

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

    public abstract class AbstractLinkedList<E>
    extends Object
    implements 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 Detail

      • get

        public E get​(int index)
        Specified by:
        get in interface List<E>
      • indexOf

        public int indexOf​(Object value)
        Specified by:
        indexOf in interface List<E>
      • subList

        public List<E> subList​(int fromIndexInclusive,
                               int toIndexExclusive)
        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
      • add

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

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

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

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

        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.contains(Object).

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

        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.contains(Object).

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

        public E set​(int index,
                     E value)
        Specified by:
        set in interface 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()