Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.rabbitmq.client.impl;
 import java.util.Queue;
 import java.util.Set;

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(java.lang.Object) returns false.

Elements must not be null.

Concurrent Semantics
This implementation is not thread-safe.

<T> type of elements in the queue
public class SetQueue<T> {
    private final Set<T> members = new HashSet<T>();
    private final Queue<T> queue = new LinkedList<T>();

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.
    public boolean addIfNotPresent(T item) {
        if (this..contains(item)) {
            return false;
        return true;

Remove the head of the queue and return it.

head element of the queue, or null if the queue is empty.
    public T poll() {
        T item =  this..poll();
        if (item != null) {
        return item;


true if and only if item is in the queue
    public boolean contains(T item) {
        return this..contains(item);


true if and only if the queue is empty
    public boolean isEmpty() {
        return this..isEmpty();

Remove item from queue, if present.

true if and only if item was initially present and was removed.
    public boolean remove(T item) {
        this..remove(item); // there can only be one such item in the queue
        return this..remove(item);

Remove all items from the queue.
    public void clear() {
New to GrepCode? Check out our FAQ X