Interface LinkedList<T>


  • public interface LinkedList<T>
    Linked List with user supplied storage for node. The user must create nodes by calling LinkedListCreate.createNode. A node can be put on any LinkedList but only on one list at a time. It is the users responsibility to synchronize access to the list.
    Author:
    mrk
    • Method Detail

      • getLength

        int getLength()
        Get the number of elements in the list.
        Returns:
        the number of elements
      • addTail

        void addTail​(LinkedListNode<T> listNode)
        Add a node to the end of the list.
        Parameters:
        listNode - the node to add to the list
        Throws:
        IllegalStateException - if the node is already on the list
      • addHead

        void addHead​(LinkedListNode<T> listNode)
        Add a node to the beginning of the list.
        Parameters:
        listNode - the node to add to the list
        Throws:
        IllegalStateException - if the node is already on the list
      • insertAfter

        void insertAfter​(LinkedListNode<T> listNode,
                         LinkedListNode<T> addNode)
        Add a node after a node that is already on the list.
        Parameters:
        listNode - The node that is on the list
        addNode - The node to add
        Throws:
        IllegalStateException - if listNode is not on list or addNode is already on list
      • insertBefore

        void insertBefore​(LinkedListNode<T> listNode,
                          LinkedListNode<T> addNode)
        Add a node before a node that is already on the list.
        Parameters:
        listNode - the node that is on the list
        addNode - the node to add
        Throws:
        IllegalStateException - if listNode is not on list or addNode is already on list
      • removeTail

        LinkedListNode<T> removeTail()
        Remove and return the LinkedListNode that is at the end of the list.
        Returns:
        the removed LinkedListNode or null if the list is empty
      • removeHead

        LinkedListNode<T> removeHead()
        Remove and return the LinkedListNode that is at the head of the list.
        Returns:
        the listNode or null if the list is empty
      • remove

        void remove​(LinkedListNode<T> listNode)
        Remove the listNode from the list.
        Parameters:
        listNode - the node to remove
      • remove

        void remove​(T object)
        Remove the object from the list.
        Parameters:
        object - the object to remove
      • getHead

        LinkedListNode<T> getHead()
        Get the node at the head of the list. The node is not removed from the list
        Returns:
        the node or null if the list is empty
      • getTail

        LinkedListNode<T> getTail()
        Get the node at the end of the list. The node is not removed from the list.
        Returns:
        the node or null if the list is empty
      • getNext

        LinkedListNode<T> getNext​(LinkedListNode<T> listNode)
        Get the node after listNode.
        Parameters:
        listNode - the current node
        Returns:
        the node or null if listNode is the last node on the list
        Throws:
        IllegalStateException - if listNode is not on the list
      • getPrev

        LinkedListNode<T> getPrev​(LinkedListNode<T> listNode)
        Get the node before listNode.
        Parameters:
        listNode - the current node
        Returns:
        the node or null if listNode is the first node on the list
        Throws:
        IllegalStateException - if listNode is not on the list
      • isEmpty

        boolean isEmpty()
        Is the list empty?
        Returns:
        (false,true) if the list (is not,is) empty
      • contains

        boolean contains​(T object)
        Is the object on the list?
        Parameters:
        object - the object.
        Returns:
        (false,true) if the object (is not, is) on the list