Class CircularBlockingDeque<T>

java.lang.Object
org.ros.concurrent.CircularBlockingDeque<T>
All Implemented Interfaces:
Iterable<T>

public class CircularBlockingDeque<T> extends Object implements Iterable<T>
A deque that removes head or tail elements when the number of elements exceeds the limit and blocks on takeFirst() and takeLast() when there are no elements available.
Author:
damonkohler@google.com (Damon Kohler)
  • Constructor Summary

    Constructors
    Constructor
    Description
    CircularBlockingDeque(int capacity)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    addFirst(T entry)
    Adds the specified entry to the tail of the queue, overwriting older entries if necessary.
    boolean
    addLast(T entry)
    Adds the specified entry to the tail of the queue, overwriting older entries if necessary.
    boolean
     
    Returns an iterator over the queue.
    Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.
    Retrieves, but does not remove, the tail of this queue, returning null if this queue is empty.
    Retrieves the head of the queue, blocking if necessary until an entry is available.
    Retrieves the tail of the queue, blocking if necessary until an entry is available.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • CircularBlockingDeque

      public CircularBlockingDeque(int capacity)
      Parameters:
      capacity - the maximum number of elements allowed in the queue
  • Method Details

    • addLast

      public boolean addLast(T entry)
      Adds the specified entry to the tail of the queue, overwriting older entries if necessary.
      Parameters:
      entry - the entry to add
      Returns:
      true
    • addFirst

      public boolean addFirst(T entry)
      Adds the specified entry to the tail of the queue, overwriting older entries if necessary.
      Parameters:
      entry - the entry to add
      Returns:
      true
    • takeFirst

      public T takeFirst() throws InterruptedException
      Retrieves the head of the queue, blocking if necessary until an entry is available.
      Returns:
      the head of the queue
      Throws:
      InterruptedException
    • peekFirst

      public T peekFirst()
      Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.
      Returns:
      the head of this queue, or null if this queue is empty
    • takeLast

      public T takeLast() throws InterruptedException
      Retrieves the tail of the queue, blocking if necessary until an entry is available.
      Returns:
      the tail of the queue
      Throws:
      InterruptedException
    • peekLast

      public T peekLast()
      Retrieves, but does not remove, the tail of this queue, returning null if this queue is empty.
      Returns:
      the tail of this queue, or null if this queue is empty
    • isEmpty

      public boolean isEmpty()
    • iterator

      public Iterator<T> iterator()
      Returns an iterator over the queue.

      Note that this is not thread-safe and that Iterator.remove() is unsupported.

      Specified by:
      iterator in interface Iterable<T>
      See Also: