Class LifoBlockingDeque<E>

Type Parameters:
E - The element type of the queue.
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingDeque<E>, BlockingQueue<E>, Deque<E>, Queue<E>

public class LifoBlockingDeque<E> extends LinkedBlockingDeque<E>
A LinkedBlockingDeque of which the non ordered element addition methods add elements at the start of the queue rather than the end. When used as a Queue this will result in a LIFO (last in first out) queue.

Note: that this means it breaks the contract of Deque.

See Also:
  • Constructor Details

    • LifoBlockingDeque

      public LifoBlockingDeque()
  • Method Details

    • add

      public boolean add(E e)
      Add an element to the start of the queue.
      Specified by:
      add in interface BlockingDeque<E>
      Specified by:
      add in interface BlockingQueue<E>
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Deque<E>
      Specified by:
      add in interface Queue<E>
      Overrides:
      add in class LinkedBlockingDeque<E>
      Parameters:
      e - The element to add.
      Returns:
      true
      Throws:
      IllegalStateException - If there is no space on the queue.
    • offer

      public boolean offer(E e)
      Add an element to the start of the queue, if there is space, without blocking.
      Specified by:
      offer in interface BlockingDeque<E>
      Specified by:
      offer in interface BlockingQueue<E>
      Specified by:
      offer in interface Deque<E>
      Specified by:
      offer in interface Queue<E>
      Overrides:
      offer in class LinkedBlockingDeque<E>
      Parameters:
      e - The element to add.
      Returns:
      true if the element was added or false if there was no space.
    • offer

      public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
      Add an element to the start of the queue, if there is space, waiting for the specified amount of time if necessary for space to become available.
      Specified by:
      offer in interface BlockingDeque<E>
      Specified by:
      offer in interface BlockingQueue<E>
      Overrides:
      offer in class LinkedBlockingDeque<E>
      Parameters:
      e - The element to add.
      timeout - The maximum amount of time to wait for space to become available.
      unit - The unit of timeout.
      Returns:
      true if the element was added or false if there was no space after waiting the specified amount of time.
      Throws:
      InterruptedException - If the thread was interrupted while waiting for space to become available.
    • put

      public void put(E e) throws InterruptedException
      Add an element to the start of the queue, waiting indefinitely for space to become available if necessary.
      Specified by:
      put in interface BlockingDeque<E>
      Specified by:
      put in interface BlockingQueue<E>
      Overrides:
      put in class LinkedBlockingDeque<E>
      Parameters:
      e - The element to add.
      Throws:
      InterruptedException - If the thread was interrupted while waiting for space to become available.