Class LinkedList<E>

    • Constructor Detail

      • LinkedList

        public LinkedList()
        Creates a new LinkedList that is empty. The complexity of this implementation is O(1).
    • Method Detail

      • fromArray

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

        public static <E2> LinkedList<E2> fromIterable​(java.lang.Iterable<E2> container)
        Type Parameters:
        E2 - is the type of the elements of the given container.
        Parameters:
        container -
        Returns:
        a new LinkedList with the elements in the given container.
        Throws:
        ArgumentIsNullException - if the given container is null.
        ArgumentIsNullException - if one of the elements in the given container is null.
      • withElements

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

        public void addAtBegin​(E element)
        Adds the given element at the begin of the current LinkedList. The complexity of this implementation is O(1).
        Parameters:
        element -
        Throws:
        ArgumentIsNullException - if the given element is null.
      • addAtBegin

        public void addAtBegin​(E... elements)
        Adds the given elements at the begin of the current LinkedList. The complexity of this implementation is O(n) if n elements are given.
        Parameters:
        elements -
        Throws:
        ArgumentIsNullException - if the given elements is null.
        ArgumentIsNullException - if one of the given elements is null.
      • addAtBegin

        public <E2 extends E> void addAtBegin​(java.lang.Iterable<E2> elements)
        Adds the given elements at the begin of the current LinkedList. The complexity of this implementation is O(n) if n elements are given.
        Type Parameters:
        E2 - is the type of the given elements.
        Parameters:
        elements -
        Throws:
        ArgumentIsNullException - if the given element container is null.
        ArgumentIsNullException - if one of the given elements is null.
      • addAtBeginIfNotContained

        public void addAtBeginIfNotContained​(E element)
        Adds the given element at the begin of the current LinkedList if the current LinkedList does not contain it. The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Parameters:
        element -
        Throws:
        ArgumentIsNullException - if the given element is null.
      • addAtBeginIfNotContained

        public void addAtBeginIfNotContained​(E... elements)
        Adds all of the given elements, the current LinkedList does not contain, at the begin of the current LinkedList. The complexity of this implementation is O(m*n) if: -The current LinkedList contains m elements. -n elements are given.
        Parameters:
        elements -
        Throws:
        ArgumentIsNullException - if one of the given elements is null.
      • addAtBeginRegardingSingularity

        public void addAtBeginRegardingSingularity​(E element)
        Adds the given element at the begin of the current LinkedList with regarding singularity. The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Parameters:
        element -
        Throws:
        ArgumentIsNullException - if the given element is null.
        InvalidArgumentException - if the current LinkedList contains already the given element.
      • addAtEnd

        public void addAtEnd​(E element)
        Adds the given element at the end of the current LinkedList. The complexity of this implementation is O(1).
        Parameters:
        element -
        Throws:
        ArgumentIsNullException - if the given element is null.
      • addAtEnd

        public void addAtEnd​(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.
        Parameters:
        elements -
        Throws:
        ArgumentIsNullException - if the given element container is null.
        ArgumentIsNullException - if one of the given elements is null.
      • addAtEnd

        public <E2 extends E> void addAtEnd​(java.lang.Iterable<E2> 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.
        Type Parameters:
        E2 - is the type of the given elements.
        Parameters:
        elements -
        Throws:
        ArgumentIsNullException - if one of the given elements is null.
      • addAtEnd

        public <E2> void addAtEnd​(java.lang.Iterable<E2> elements,
                                  IElementTakerElementGetter<E2,​E> extractor)
        Adds the elements the given extractor extracts from the given elements at the end of the current LinkedList. The complexity of this implementation is O(n) if n elements are given.
        Type Parameters:
        E2 - is the type of the given elements.
        Parameters:
        elements -
        extractor -
      • addAtEndIfNotContained

        public void addAtEndIfNotContained​(E element)
        Adds the given element at the end of the current LinkedList if the current LinkedList does not contain it. The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Parameters:
        element -
        Throws:
        ArgumentIsNullException - if the given element is null.
      • addAtEndIfNotContained

        public void addAtEndIfNotContained​(E... elements)
        Adds all of the given elements, the current LinkedList does not contain, at the end of the current LinkedList. The complexity of this implementation is O(m*n) if: -The current LinkedList contains m elements. -n elements are given.
        Parameters:
        elements -
        Throws:
        ArgumentIsNullException - if one of the given elements is null.
      • addAtEndRegardingSingularity

        public void addAtEndRegardingSingularity​(E element)
        Adds the given element at the begin of the current LinkedList with regarding singularity. The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Parameters:
        element -
        Throws:
        ArgumentIsNullException - if the given element is null.
        InvalidArgumentException - if the current LinkedList contains already the given element.
      • 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​(java.lang.Object object)
        An object equals a list if it is a list containing exactly the same elements.
        Overrides:
        equals in class java.lang.Object
        Returns:
        true if the given object equals the current LinkedList.
      • forEachAndGetList

        public void forEachAndGetList​(IElementTaker<E> runner)
        Runs the given runner on each element of the current LinkedList. The complexity of this implementation is O(n) when the current LinkedList contains n elements.
        Parameters:
        runner -
      • getCopy

        public LinkedList<E> getCopy()
        The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Returns:
        a new list with the elements of the current LinkedList.
      • getGroups

        public <E2> LinkedList<LinkedList<E>> getGroups​(IElementTakerElementGetter<E,​E2> norm)
        The complexity of this implementation is O(n^2) if the current LinkedList contains n elements.
        Type Parameters:
        E2 - is the type of the elements the given norm returns.
        Parameters:
        norm -
        Returns:
        a new list of groups of the elements of the current LinkedList whereas the value of the given norm is equal for all elements of a group.
      • getRatio

        public double getRatio​(SequencePattern<E> sequencePattern)
        The complexity of this implementation is O((n-m)*m) if: -This list contains n elements. -The sequences that matches the given sequence pattern contain m elements.
        Parameters:
        sequencePattern -
        Returns:
        the ratio of the sequences from the current LinkedList that match the given sequence pattern.
        Throws:
        EmptyArgumentException - if the current LinkedList is empty.
      • getRefLastOrNull

        public E getRefLastOrNull()
        The complexity of this implementation is O(1).
        Returns:
        the last element of the current LinkedList or null.
      • getRefSecondLast

        public E getRefSecondLast()
        The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Returns:
        the second last element of the current LinkedList.
        Throws:
        InvalidArgumentException - if the current LinkedList contains less than 2 elements.
      • getSequenceCount

        public int getSequenceCount​(SequencePattern<E> sequencePattern)
        The complexity of this implementation is O((n-m)*m) if: -This list contains n elements. -The sequences that matches the given sequence pattern contain m elements.
        Parameters:
        sequencePattern -
        Returns:
        the number of sequences from the current LinkedList that match the given sequence pattern.
      • getSequences

        public LinkedList<LinkedList<E>> getSequences​(SequencePattern<E> sequencePattern)
        The complexity of this implementation is O((n-m)*m) if: -This list contains n elements. -The sequences that matches the given sequence pattern contain m elements.
        Parameters:
        sequencePattern -
        Returns:
        the sequences from the current LinkedList that match the given sequence pattern.
      • getElementCount

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

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • iterator

        public ch.nolix.common.container.LinkedListIterator<E> iterator()
        The complexity of this implementation is O(1).
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Returns:
        a new iterator of the current LinkedList.
      • matches

        public boolean matches​(SequencePattern<E> sequencePattern)
        The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Parameters:
        sequencePattern -
        Returns:
        true if the current LinkedList matches the given sequence pattern.
      • refill

        public void refill​(java.lang.Iterable<E> elements)
        Removes all elements from the current LinkedList and adds the given elements at the end of the current LinkedList. The complexity of this implementation is O(m + n) if: -The current LinkedList contains m elements. -There are given n elements.
        Parameters:
        elements -
        Throws:
        ArgumentIsNullException - if the given elements is null.
        ArgumentIsNullException - if one of the given elements is null.
      • removeAll

        public void removeAll​(IElementTakerBooleanGetter<E> selector)
        Removes all elements the given selector selects from the current LinkedList. The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Parameters:
        selector -
      • removeAndGetRefFirst

        public E removeAndGetRefFirst()
        Removes and returns the first element of the current LinkedList. The complexity of this implementation is O(1).
        Returns:
        the first element of the current LinkedList.
        Throws:
        EmptyArgumentException - if the current LinkedList is empty.
      • removeAndGetRefFirst

        public E removeAndGetRefFirst​(IElementTakerBooleanGetter<E> selector)
        Removes and returns the first element the given selector selects from the current LinkedList. The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Parameters:
        selector -
        Returns:
        the first element the given selector selects from the current LinkedList.
        Throws:
        InvalidArgumentException - if the current LinkedList does not contain an element the given selector selects.
      • removeAndGetRefLast

        public E removeAndGetRefLast()
        Removes and returns the last element of the current LinkedList. The complexity of this implementation is O(1).
        Returns:
        the last element of the current LinkedList.
        Throws:
        EmptyArgumentException - if the current LinkedList is empty.
      • removeFirst

        public void removeFirst()
        Removes the first element of the current LinkedList. The complexity of this implementation is O(1).
        Throws:
        EmptyArgumentException - if the current LinkedList is empty.
      • removeFirst

        public <E2> void removeFirst​(java.lang.Iterable<E2> elements)
        Removes the first appearance of all of the given elements from the current LinkedList. The complexity of this implementation is O(m * n) if: -There are given m elements. -This list contains n elements.
        Type Parameters:
        E2 - is the type of the given elements.
        Parameters:
        elements -
        Throws:
        InvalidArgumentException - if the current LinkedList does not contain one of the given elements.
      • removeFirst

        public void removeFirst​(java.lang.Object element)
        Removes the first appearance of the given element from the current LinkedList. The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Parameters:
        element -
        Throws:
        InvalidArgumentException - if the current LinkedList does not contain the given element.
      • removeRegardingSingularity

        public void removeRegardingSingularity​(E element)
        Removes the given element from the current LinkedList.
        Parameters:
        element -
        Throws:
        InvalidArgumentException - if the current LinkedList does not contain the given element once.
      • reverse

        public void reverse()
        Reverses the elements of the current LinkedList. The complexity of this implementation is O(n) if the current LinkedList contains n elements.
      • toOrderedList

        public <E2> LinkedList<E> toOrderedList​(IElementTakerComparableGetter<E,​E2> norm)
        This implementation uses the merge sort algorithm. The complexity of this implementation is O(n*log(n)) if the current IContainer contains n elements.
        Specified by:
        toOrderedList in interface IContainer<E>
        Type Parameters:
        E2 - is the type of the elements of the Comparable the given norm returns.
        Returns:
        a new LinkedList with the elements of the current IContainer ordered from the smallest to the biggest element according to the given norm.
      • toString

        public java.lang.String toString()
        The complexity of this implementation is O(n) if the current LinkedList contains n elements.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the current LinkedList.