Class LinkedList<E>

Type Parameters:
E - is the type of the elements of a LinkedList.
All Implemented Interfaces:
Filterable<E>, Groupable<E>, IContainer<E>, IFilteringContainerViewProvider<E>, IIntervallContainerViewProvider<E>, IMappingContainerViewProvider<E>, Mappable<E>, AggregationRequestable<E>, ArrayMappable<E>, CountRequestable<E>, IndexRequestable<E>, IterableWithCopyableIterator<E>, SingleSearchable<E>, StoringRequestable<E>, StringMappable, ILinkedList<E>, Copyable<ILinkedList<E>>, Clearable, EmptinessRequestable, MaterializationRequestable, Iterable<E>

public final class LinkedList<E> extends AbstractExtendedContainer<E> implements ILinkedList<E>
A LinkedList is a AbstractContainer that can add elements at the begin or end. A LinkedList is clearable.
Author:
Silvan Wyss
  • Method Details

    • createEmpty

      public static <T> LinkedList<T> createEmpty()
      Type Parameters:
      T - is the type of the elements of the created LinkedList.
      Returns:
      a new empty LinkedList.
    • fromArray

      public static <T> LinkedList<T> fromArray(T[] array)
      Type Parameters:
      T - is the type of the elements of the given array.
      Parameters:
      array -
      Returns:
      a new LinkedList with the elements in the given array.
      Throws:
      RuntimeException - if the given array is null.
      RuntimeException - if one of the elements in the given array is null.
    • fromIterable

      public static <T> LinkedList<T> fromIterable(Iterable<T> container)
      Type Parameters:
      T - is the type of the elements of the given container.
      Parameters:
      container -
      Returns:
      a new LinkedList with the elements in the given container.
      Throws:
      RuntimeException - if the given container is null.
      RuntimeException - if one of the elements in the given container is null.
    • withElement

      public static <T> LinkedList<T> withElement(T... element)
      Type Parameters:
      T - is the type of the given element.
      Parameters:
      element -
      Returns:
      a new LinkedList with the given element.
      Throws:
      RuntimeException - if one of the given element is null.
    • withElements

      public static <T> LinkedList<T> withElements(T... elements)
      Type Parameters:
      T - is the type of the given elements.
      Parameters:
      elements -
      Returns:
      a new LinkedList with the given elements.
      Throws:
      RuntimeException - if one of the given elements is null.
    • addAtBegin

      public void addAtBegin(E element)
      Adds the given element at the begin of the current ILinkedList.
      Specified by:
      addAtBegin in interface ILinkedList<E>
      Parameters:
      element -
    • addAtBegin

      public void addAtBegin(E element, E... elements)
      Adds the given element and the given elements at the begin of the current ILinkedList. The elements will be added in the given order.
      Specified by:
      addAtBegin in interface ILinkedList<E>
      Parameters:
      element -
      elements -
    • addAtBegin

      public void addAtBegin(E[] elements)
      The time complexity of this implementation is O(n) if n elements are given. Adds the given elements at the begin of the current ILinkedList. The elements will be added in the given order.
      Specified by:
      addAtBegin in interface ILinkedList<E>
      Parameters:
      elements -
    • addAtBegin

      public void addAtBegin(Iterable<? extends E> elements)
      Adds the given elements at the begin of the current ILinkedList. The elements will be added in the given order.
      Specified by:
      addAtBegin in interface ILinkedList<E>
      Parameters:
      elements -
    • addAtEnd

      public void addAtEnd(E element)
      The time complexity of this implementation is O(1). Adds the given element at the end of the current ILinkedList.
      Specified by:
      addAtEnd in interface ILinkedList<E>
      Parameters:
      element -
    • addAtEnd

      @SafeVarargs public final void addAtEnd(E element, E... elements)
      The time complexity of this implementation is O(n) if n elements are given. Adds the given element and the given elements at the end of the current ILinkedList. The elements will be added in the given order.
      Specified by:
      addAtEnd in interface ILinkedList<E>
      Parameters:
      element -
      elements -
    • addAtEnd

      public void addAtEnd(E[] elements)
      The time complexity of this implementation is O(n) if n elements are given. Adds the given elements at the end of the current ILinkedList. The elements will be added in the given order.
      Specified by:
      addAtEnd in interface ILinkedList<E>
      Parameters:
      elements -
    • addAtEnd

      public void addAtEnd(Iterable<? extends E> elements)
      Adds the given elements at the end of the current LinkedList. The complexity of this implementation is O(n) if n elements are given.
      Specified by:
      addAtEnd in interface ILinkedList<E>
      Parameters:
      elements -
      Throws:
      RuntimeException - if one of the given elements is null.
    • clear

      public void clear()
      Removes all elements of the current LinkedList. The complexity of this implementation is O(n) when the current LinkedList contains n elements.
      Specified by:
      clear in interface Clearable
    • equals

      public boolean equals(Object object)
      An object equals a list if it is a list containing exactly the same elements.
      Overrides:
      equals in class Object
    • getCopy

      public ILinkedList<E> getCopy()
      The time complexity of this implementation is O(n) if the current LinkedList contains n elements.
      Specified by:
      getCopy in interface Copyable<E>
      Returns:
      a new copy of the current Copyable.
    • getCount

      public int getCount()
      The time complexity of this implementation is O(1).
      Specified by:
      getCount in interface CountRequestable<E>
      Returns:
      the number of elements of the current LinkedList.
    • getStoredAtOneBasedIndex

      public E getStoredAtOneBasedIndex(int oneBasedIndex)
      The time complexity of this implementation is O(n) if the current AbstractContainer contains n elements.
      Specified by:
      getStoredAtOneBasedIndex in interface SingleSearchable<E>
      Parameters:
      oneBasedIndex -
      Returns:
      the element at the given index.
      Throws:
      RuntimeException - if the given index is not positive.
      ArgumentDoesNotHaveAttributeException - if the current AbstractContainer does not contain an element at the given index.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isMaterialized

      public boolean isMaterialized()
      The time complexity of this implementation is O(1).
      Specified by:
      isMaterialized in interface MaterializationRequestable
      Returns:
      true if the current MaterializationRequestable is materialized, false otherwise.
    • iterator

      public CopyableIterator<E> iterator()
      The time complexity of this implementation is O(1).
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface IterableWithCopyableIterator<E>
      Returns:
      a new iterator of the current LinkedList.
    • removeAll

      public void removeAll(Predicate<E> selector)
      The time complexity of this implementation is O(n) if the current LinkedList contains n elements. Removes all elements from the current ILinkedList the given selector selects.
      Specified by:
      removeAll in interface ILinkedList<E>
      Parameters:
      selector -
    • removeAllOccurrencesOf

      public void removeAllOccurrencesOf(Object element)
      The time complexity of this implementation is O(n) if the current LinkedList contains n elements. Removes all occurrences of the given element from the current ILinkedList.
      Specified by:
      removeAllOccurrencesOf in interface ILinkedList<E>
      Parameters:
      element -
    • removeAndGetStoredFirst

      public E removeAndGetStoredFirst()
      The time complexity of this implementation is O(1). Removes and returns the first element of the current ILinkedList.
      Specified by:
      removeAndGetStoredFirst in interface ILinkedList<E>
      Returns:
      the first element of the current ILinkedList.
    • removeAndGetStoredFirst

      public E removeAndGetStoredFirst(Predicate<E> selector)
      The time complexity of this implementation is O(n) if the current LinkedList contains n elements. Removes and returns the first element the given selector selects from the current ILinkedList.
      Specified by:
      removeAndGetStoredFirst in interface ILinkedList<E>
      Parameters:
      selector -
      Returns:
      the first element the given selector selects from the current ILinkedList.
    • removeAndGetStoredLast

      public E removeAndGetStoredLast()
      The time complexity of this implementation is O(1). Removes and returns the last element of the current ILinkedList.
      Specified by:
      removeAndGetStoredLast in interface ILinkedList<E>
      Returns:
      the last element of the current ILinkedList.
    • removeFirst

      public void removeFirst()
      The time complexity of this implementation is O(1). Removes the first element from the current ILinkedList.
      Specified by:
      removeFirst in interface ILinkedList<E>
    • removeFirstStrictly

      public void removeFirstStrictly()
      The time complexity of this implementation is O(1). Removes the first element from the current ILinkedList.
      Specified by:
      removeFirstStrictly in interface ILinkedList<E>
    • removeFirst

      public void removeFirst(Predicate<E> selector)
      The time complexity of this implementation is O(n) if the current LinkedList contains n elements. Removes the first element the given selector selects from the current ILinkedList
      Specified by:
      removeFirst in interface ILinkedList<E>
      Parameters:
      selector -
    • removeFirstOccurrenceOf

      public void removeFirstOccurrenceOf(Object element)
      The time complexity of this implementation is O(n) if the current LinkedList contains n elements. Removes the first occurrence of the given element from the current ILinkedList.
      Specified by:
      removeFirstOccurrenceOf in interface ILinkedList<E>
      Parameters:
      element -
    • removeLast

      public void removeLast()
      The time complexity of this implementation is O(n). Removes the last element from the current ILinkedList.
      Specified by:
      removeLast in interface ILinkedList<E>
    • removeLastStrictly

      public void removeLastStrictly()
      The time complexity of this implementation is O(n). Removes the last element from the current ILinkedList.
      Specified by:
      removeLastStrictly in interface ILinkedList<E>
    • removeStrictlyFirstOccurrenceOf

      public void removeStrictlyFirstOccurrenceOf(Object element)
      The time complexity of this implementation is O(n). Removes the first occurrence of the given element from the current ILinkedList.
      Specified by:
      removeStrictlyFirstOccurrenceOf in interface ILinkedList<E>
      Parameters:
      element -
    • replaceFirst

      public void replaceFirst(Predicate<E> selector, E element)
      The time complexity of this implementation is O(n) if the current LinkedList contains n elements. Replaces the first element the given selector selects from the current ILinkedList with the given element.
      Specified by:
      replaceFirst in interface ILinkedList<E>
      Parameters:
      selector -
      element -
    • toString

      public String toString()
      The time complexity of this implementation is O(n) if the current LinkedList contains n elements.
      Overrides:
      toString in class Object