Class LinkedList<E>

    • Constructor Detail

      • LinkedList

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

      • addAtBegin

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

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

        public LinkedList<E> 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 method is O(n) if the current LinkedList contains n elements.
        Parameters:
        element -
        Returns:
        the current LinkedList.
        Throws:
        ArgumentIsNullException - if the given element is null.
      • addAtBeginIfNotContained

        public LinkedList<E> 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 method is O(m*n) if: -The current LinkedList contains m elements. -n elements are given.
        Parameters:
        elements -
        Returns:
        the current LinkedList.
        Throws:
        ArgumentIsNullException - if one of the given elements is null.
      • addAtEnd

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

        public <E2 extends ELinkedList<E> addAtEnd​(java.lang.Iterable<E2> elements)
        Adds the given elements at the end of the current LinkedList. The complexity of this method is O(n) if n elements are given.
        Type Parameters:
        E2 - is the type of the given elements.
        Parameters:
        elements -
        Returns:
        the current LinkedList.
        Throws:
        ArgumentIsNullException - if one of the given elements is null.
      • addAtEnd

        public <E2> LinkedList<E> 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 method is O(n) if n elements are given.
        Type Parameters:
        E2 - is the type of the given elements.
        Parameters:
        elements -
        extractor -
        Returns:
        the current LinkedList.
      • addAtEndIfNotContained

        public LinkedList<E> 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 method is O(n) if the current LinkedList contains n elements.
        Parameters:
        element -
        Returns:
        the current LinkedList.
        Throws:
        ArgumentIsNullException - if the given element is null.
      • addAtEndIfNotContained

        public LinkedList<E> 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 method is O(m*n) if: -The current LinkedList contains m elements. -n elements are given.
        Parameters:
        elements -
        Returns:
        the current LinkedList.
        Throws:
        ArgumentIsNullException - if one of the given elements is null.
      • clear

        public void clear()
        Removes all elements of the current LinkedList. The complexity of this method 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 LinkedList<E> forEachAndGetList​(IElementTaker<E> runner)
        Runs the given runner on each element of the current LinkedList. The complexity of this method is O(n) when the current LinkedList contains n elements.
        Parameters:
        runner -
        Returns:
        the current LinkedList.
      • getCopy

        public LinkedList<E> getCopy()
        The complexity of this method 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 method 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 method 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 method is O(1).
        Returns:
        the last element of the current LinkedList or null.
      • getRefSecondLast

        public E getRefSecondLast()
        The complexity of this method 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 method 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 method 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 method 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 method 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 method 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 method 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.
      • removeAndGetRefFirst

        public E removeAndGetRefFirst()
        Removes and returns the first element of the current LinkedList. The complexity of this method 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 method 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 method is O(1).
        Returns:
        the last element of the current LinkedList.
        Throws:
        EmptyArgumentException - if the current LinkedList is empty.
      • removeFirst

        public <E2> LinkedList<E> removeFirst​(java.lang.Iterable<E2> elements)
        Removes the first appearance of all of the given elements from the current LinkedList. The complexity of this method 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 -
        Returns:
        the current LinkedList.
        Throws:
        InvalidArgumentException - if the current LinkedList does not contain one of the given elements.
      • removeFirst

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

        public LinkedList<E> reverse()
        Reverses the elements of the current LinkedList. The complexity of this method is O(n) if the current LinkedList contains n elements.
        Returns:
        the current LinkedList.
      • toOrderedList

        public <E2> LinkedList<E> toOrderedList​(IElementTakerComparableGetter<E,​E2> norm)
        This method uses the merge sort algorithm. The complexity of this method 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 method 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.