Class ConcurrentIntrusiveList<T extends ConcurrentIntrusiveList.Element<T>>


  • @ThreadSafe
    public final class ConcurrentIntrusiveList<T extends ConcurrentIntrusiveList.Element<T>>
    extends java.lang.Object
    An ConcurrentIntrusiveList<T> is a doubly-linked list where the link pointers are embedded in the elements. This makes insertion and removal into a known position constant time.

    Elements must derive from the Element<T extends Element<T>> interface:

    
     class MyClass implements Element<MyClass> {
       private MyClass next = null;
       private MyClass prev = null;
    
      @Override
       MyClass getNext() {
         return next;
       }
    
      @Override
       void setNext(MyClass element) {
         next = element;
       }
    
      @Override
       MyClass getPrev() {
         return prev;
       }
    
      @Override
       void setPrev(MyClass element) {
         prev = element;
       }
     }
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int capacity  
      private T head  
      private int size  
    • Constructor Summary

      Constructors 
      Constructor Description
      ConcurrentIntrusiveList​(int capacity)
      Constructs a new ConcurrentIntrusiveList.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addElement​(T element)
      Adds the given element to the list.
      void clear()
      Clears all the elements from the list.
      java.util.Collection<T> getAll()
      Returns all the elements from this list.
      boolean removeElement​(T element)
      Removes the given element from the list.
      int size()
      Returns the number of elements in this list.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConcurrentIntrusiveList

        public ConcurrentIntrusiveList​(int capacity)
        Constructs a new ConcurrentIntrusiveList.
        Parameters:
        capacity - must be greater than 0.
    • Method Detail

      • addElement

        public boolean addElement​(T element)
        Adds the given element to the list. If the number of elements will be larger than the capacity then the oldest element in the list will be removed.
        Parameters:
        element - the element to add.
        Returns:
        false if the element is already in the list or if adding this element will exceed capacity.
      • removeElement

        public boolean removeElement​(T element)
        Removes the given element from the list.
        Parameters:
        element - the element to remove.
      • size

        public int size()
        Returns the number of elements in this list.
        Returns:
        the number of elements in this list.
      • clear

        public void clear()
        Clears all the elements from the list.
      • getAll

        public java.util.Collection<T> getAll()
        Returns all the elements from this list.
        Returns:
        all the elements from this list.