Class AbstractLinkedList<E,​T extends LinkedListEntry<E,​T>>

    • Constructor Detail

      • AbstractLinkedList

        public AbstractLinkedList()
    • Method Detail

      • getFrontEntry

        protected @Nullable T getFrontEntry()
        Retrieves the first entry in the list, or null if the list is empty.
        Returns:
        the first entry or null.
      • getBackEntry

        protected @Nullable T getBackEntry()
        Retrieves the last entry in the list, or null if the list is empty.
        Returns:
        the first entry or null.
      • concat

        public void concat​(AbstractLinkedList<? extends E,​? extends T> other)
        Concatenates two linked lists. All elements of the specified list (which will be empty afterward) are added at the end of this list. This operation runs in constant time.
        Parameters:
        other - the list to append,
      • get

        public E get​(ElementReference ref)
        Description copied from interface: SmartCollection
        Retrieves an element by its reference.

        If the reference belongs to another collection, the behavior is undefined.

        Specified by:
        get in interface SmartCollection<E>
        Parameters:
        ref - the element's reference.
        Returns:
        the element.
      • referencedAdd

        public ElementReference referencedAdd​(E elem)
        Description copied from interface: SmartCollection
        Adds an element to the collection, returning a reference to the newly added element. If the collection does not support containing the same element multiple times, a reference to the previously existing element is returned.
        Specified by:
        referencedAdd in interface SmartCollection<E>
        Parameters:
        elem - the element to be added.
        Returns:
        a reference to this element in the collection.
      • remove

        public void remove​(ElementReference elem)
        Description copied from interface: SmartCollection
        Removes an element (by its reference) from the collection.

        If the reference does not belong to this collection, the behavior is undefined.

        Specified by:
        remove in interface SmartCollection<E>
        Parameters:
        elem - the reference to the element to be removed.
      • removeEntry

        protected void removeEntry​(T entry)
        Removes an entry from the list.
        Parameters:
        entry - the entry to remove.
      • replace

        public void replace​(ElementReference ref,
                            E newElement)
        Description copied from interface: SmartCollection
        Replaces the element referenced by the given reference with the specified element.
        Specified by:
        replace in interface SmartCollection<E>
        Parameters:
        ref - the reference of the element to be replaced.
        newElement - the replacement.
      • replaceEntry

        protected void replaceEntry​(T oldEntry,
                                    T newEntry)
        Replaces an entry in the list.
        Parameters:
        oldEntry - the entry to be replaced.
        newEntry - the replacement entry.
      • makeEntry

        protected abstract T makeEntry​(E element)
        Creates (if necessary) a LinkedListEntry for the given element. For intrusive linked lists, e.g., the argument itself is returned.
        Parameters:
        element - the element for which to retrieve an entry.
        Returns:
        the entry for the given element.
      • pushBackEntry

        protected void pushBackEntry​(T e)
        Adds an entry at the end of the list.
        Parameters:
        e - the entry to add.
      • getBack

        public E getBack()
        Retrieves the last element in the list. If the list is empty, a NoSuchElementException will be thrown.
        Returns:
        the last element in the list.
      • getBackReference

        public @Nullable ElementReference getBackReference()
        Retrieves a reference to the last element in the list. If the list is empty, null is returned.
        Returns:
        a reference to the last element, or null.
      • getFront

        public E getFront()
        Retrieves the first element in the list. If the list is empty, a NoSuchElementException will be thrown
        Returns:
        the first element in the list.
      • getFrontReference

        public @Nullable ElementReference getFrontReference()
        Retrieves a reference to the first element in the list. If the list is empty, null is returned.
        Returns:
        a reference to the first element, or null.
      • popBack

        public E popBack()
        Retrieves and removes the last element in the list. If the list is empty, a NullPointerException may be thrown.
        Returns:
        the formerly last element in the list.
      • popBackEntry

        protected @Nullable T popBackEntry()
        Removes and returns the last entry in the list. If the list is empty, it remains unmodified and null is returned.
        Returns:
        the previously first entry in the list, or null.
      • popFront

        public E popFront()
        Retrieves and removes the first element in the list. If the list is empty, a NullPointerException may be thrown.
        Returns:
        the formerly first element in the list.
      • popFrontEntry

        protected @Nullable T popFrontEntry()
        Removes and returns the first entry in the list. If the list is empty, it remains unmodified and null is returned.
        Returns:
        the previously first entry in the list, or null.
      • pushBack

        public ElementReference pushBack​(E element)
        Adds an element at the end of the list.
        Parameters:
        element - the element to add.
        Returns:
        a reference to the newly added element.
      • pushFront

        public ElementReference pushFront​(E element)
        Adds an element at the beginning of the list.
        Parameters:
        element - the element to add.
        Returns:
        a reference to the newly added element.
      • pushFrontEntry

        protected void pushFrontEntry​(T e)
        Adds an entry at the beginning of the list.
        Parameters:
        e - the entry to add.
      • pred

        public @Nullable ElementReference pred​(ElementReference ref)
        Description copied from interface: SmartSequence
        Retrieves the reference to the preceding element, or null if the given reference references the first element in the list.
        Specified by:
        pred in interface SmartSequence<E>
        Parameters:
        ref - the reference
        Returns:
        the reference to the preceding element
      • castRef

        protected T castRef​(ElementReference ref)
        Helper function for casting a general ElementReference to the specific linked list entry type.
        Parameters:
        ref - the reference.
        Returns:
        the argument cast to the entry type.
      • succ

        public @Nullable ElementReference succ​(ElementReference ref)
        Description copied from interface: SmartSequence
        Retrieves the reference to the succeeding element, or null if the given reference references the last element in the list.
        Specified by:
        succ in interface SmartSequence<E>
        Parameters:
        ref - the reference
        Returns:
        the reference to the succeeding element
      • insertBefore

        public ElementReference insertBefore​(E element,
                                             ElementReference ref)
        Description copied from interface: SmartSequence
        Inserts the given element before the element referenced by the specified reference.
        Specified by:
        insertBefore in interface SmartSequence<E>
        Parameters:
        element - the element to be added.
        ref - reference to the element before which the new element is to be inserted.
        Returns:
        reference to the newly added element.
      • insertBeforeEntry

        protected void insertBeforeEntry​(T e,
                                         T insertPos)
        Inserts a new entry before a given one.
        Parameters:
        e - the entry to add.
        insertPos - the entry before which to add the new one.
      • insertAfter

        public ElementReference insertAfter​(E element,
                                            ElementReference ref)
        Description copied from interface: SmartSequence
        Inserts the given element after the element referenced by the specified reference.
        Specified by:
        insertAfter in interface SmartSequence<E>
        Parameters:
        element - the element to be added.
        ref - reference to the element after which the new element is to be inserted.
        Returns:
        reference to the newly added element.
      • insertAfterEntry

        protected void insertAfterEntry​(T e,
                                        T insertPos)
        Inserts a new entry after a given one.
        Parameters:
        e - the entry to add.
        insertPos - the entry before which to add the new one.
      • swap

        public void swap​(AbstractLinkedList<E,​T> other)
        Swaps the contents of two linked lists with the same entry types. This method runs in constant time.
        Parameters:
        other - the other list to swap contents with.