Class UniqueLinkedList<T>

  • Type Parameters:
    T - type of elements in the list.


    public class UniqueLinkedList<T>
    extends Object
    A doubly linked list with unique entries. Uniqueness is in terms of Map lookup semantic, i.e. Object.hashCode() and Object.equals(Object). This list supports insertion and removal at head and tail as well as a move-to-front and move-to-tail operation. The uniqueness of its elements is not explicitly enforced by the implementation, i.e. you have to expect strange results if adding the same element more than once. If you don't know whether an element is in the data structure because of your usage pattern anyway, use the contains(Object) method to find out whether an element is already present.
    • Method Summary

      Modifier and Type Method and Description
      void addFirst(T element)
      Add an element to the front of the list.
      void addLast(T element)
      Add an element to the end of the list.
      void clear()
      Remove all elements from the list.
      boolean contains(T element)
      Find out whether the specified element is currently contained within the list.
      T getFirst()
      Get the first element in the list.
      T getLast()
      Get the last element in the list.
      void moveToFront(T element)
      Move the denoted element to the front.
      void moveToTail(T element)
      Move the denoted element to the tail.
      T removeFirst()
      Remove the first element from the list.
      T removeLast()
      Remove the last element from the list.
      int size()
      Get the number of elements currently stored in this list.
    • Constructor Detail

      • UniqueLinkedList

        public UniqueLinkedList()
    • Method Detail

      • addFirst

        public void addFirst(T element)
        Add an element to the front of the list.
        Parameters:
        element - the element to add.
      • addLast

        public void addLast(T element)
        Add an element to the end of the list.
        Parameters:
        element - the element to add.
      • size

        public int size()
        Get the number of elements currently stored in this list.
        Returns:
        the size of this list.
      • contains

        public boolean contains(T element)
        Find out whether the specified element is currently contained within the list.
        Parameters:
        element - the element to check.
        Returns:
        whether the element is contained within the list.
      • getFirst

        public T getFirst()
        Get the first element in the list.
        Returns:
        the first element.
      • getLast

        public T getLast()
        Get the last element in the list.
        Returns:
        the last element.
      • clear

        public void clear()
        Remove all elements from the list.
      • removeFirst

        public T removeFirst()
        Remove the first element from the list.
        Returns:
        the element removed.
      • removeLast

        public T removeLast()
        Remove the last element from the list.
        Returns:
        the element removed.
      • moveToFront

        public void moveToFront(T element)
        Move the denoted element to the front.
        Parameters:
        element - the element to move to the front.
      • moveToTail

        public void moveToTail(T element)
        Move the denoted element to the tail.
        Parameters:
        element - the element to move to the tail.