A Queue that ensure uniqueness of the elements?

前端 未结 8 1294
甜味超标
甜味超标 2020-12-13 08:25

I\'m looking for a implementation of java.util.Queue or something in the Google collection who behave like a Queue, but also ensure that each element of the queue is unique.

8条回答
  •  轮回少年
    2020-12-13 08:56

    Unfortunately it doesn't exist. Since I needed such a Queue I have developed a Blocking Queue backed by a set, inspired by java.util.concurrent.LinkedBlockingQueue.

    You can find it here :

    https://github.com/bvanalderweireldt/concurrent-unique-queue

    Example :

    final BlockingQueue queue = new ConcurrentSetBlockingQueue<>(1);
    queue.offer(new Integer(1)); //True
    queue.offer(new Integer(1)); //False
    

    You can use it with Maven :

    
      com.hybhub
      concurrent-util
      0.1
    
    

提交回复
热议问题