title: java.util.Queue implementation that provides equal elements at most once
body: <p>I'm looking for a <code>java.util.Queue</code> implementation that queues up equal elements at most once.</p>
  
  <p>E.g., such a <code>specialQueue</code> should behave like so:</p>
  
  <pre><code>E e1;
  E e2;
  E e3;
  //...
  assertThat( e1, is(e2) );
  assertThat( e1, is(not(e3)) );
  
  Queue&lt;E&gt; specialQueue;
  //...
  specialQueue.offer(e1);
  specialQueue.offer(e2);
  specialQueue.offer(e3);
  
  
  assertThat( specialQueue.poll(), is(e1) );
  assertThat( specialQueue.poll(), is(e3) );
  assertThat( specialQueue.poll(), is(null) );
  // FIFO semantics are not relevant to the question
  
  specialQueue.offer(e3)
  assertThat( specialQueue.poll(), is(null) );
  </code></pre>
  
  <p>I came up with an implementation that manages an internal <code>Set&lt;E&gt; alreadySeenElements</code>, and guards against adding elements to a delegate queue by checking against that set. I was wondering if there already exists a "battle-tested" implementation.</p>