Package com.complexible.common.collect

# Class SingletonQueue<T>

java.lang.Object
com.complexible.common.collect.SingletonQueue<T>

public class SingletonQueue<T> extends Object
A simple queue that can hold at most one element while in addition provides a function to `close()` the queue. The queue is either empty (`take()` calls will block) or full (`calls will block`.A closed queue will not block on any `put` call but will silently ignore the value. Calling `take()` on a closed queue will always return the special end element.

Since:
  2.0
Version:
  2.0
Author:
  Evren Sirin

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SingletonQueue(T eoq)`
  Creates a new queue with the specific End-Of-Queue element.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Closes the queue causing all blocked threads to be unblocked.
  `T`
  `getEOQ()`
  Returns the special end of queue (EOQ) value.
  `boolean`
  `isEmpty()`
  `boolean`
  `isFull()`
  `void`
  `put(T x)`
  Puts a value to the queue waiting indefinitely if the queue is full.
  `T`
  `take()`
  Take a value from the queue waiting indefinitely if it is empty.

  ### Methods inherited from class java.lang.Object

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

- ## Constructor Details

  - ### SingletonQueue

    public SingletonQueue(T eoq)
    Creates a new queue with the specific End-Of-Queue element.

- ## Method Details

  - ### isFull

    public boolean isFull()

  - ### isEmpty

    public boolean isEmpty()

  - ### getEOQ

    public T getEOQ()
    Returns the special end of queue (EOQ) value.

  - ### put

    public void put(T x) throws InterruptedException
    Puts a value to the queue waiting indefinitely if the queue is full. If another thread closes the queue, this function will immediately return and the value will be ignored.
    Throws:
      `InterruptedException`

  - ### take

    public T take() throws InterruptedException
    Take a value from the queue waiting indefinitely if it is empty. If another thread closes the queue, this function will immediately return the `end element`.
    Throws:
      `InterruptedException`

  - ### close

    public void close() throws InterruptedException
    Closes the queue causing all blocked threads to be unblocked. All values `put(Object)` after this call will be ignored.
    Throws:
      `InterruptedException`