Class SetQueue<T>

  • Type Parameters:
    T - type of elements in the queue

    public class SetQueue<T>
    extends Object

    A generic queue-like implementation (supporting operations addIfNotPresent, poll, contains, and isEmpty) which restricts a queue element to appear at most once. If the element is already present addIfNotPresent(T) returns false.

    Elements must not be null.

    Concurrent Semantics

    This implementation is not thread-safe.
    • Constructor Detail

      • SetQueue

        public SetQueue()
    • Method Detail

      • addIfNotPresent

        public boolean addIfNotPresent​(T item)
        Add an element to the back of the queue and return true, or else return false.
        item - to add
        true if the element was added, false if it is already present.
      • poll

        public T poll()
        Remove the head of the queue and return it.
        head element of the queue, or null if the queue is empty.
      • contains

        public boolean contains​(T item)
        item - to look for in queue
        true if and only if item is in the queue.
      • isEmpty

        public boolean isEmpty()
        true if and only if the queue is empty.
      • remove

        public boolean remove​(T item)
        Remove item from queue, if present.
        item - to remove
        true if and only if item was initially present and was removed.
      • clear

        public void clear()
        Remove all items from the queue.