BoundedPriorityQueue extends PriorityQueue<E> { public BoundedPriorityQueue(int maxQueueSize, Comparator<? super E> comparator) { super(11, comparator); this.maxQueueSize = maxQueueSize; if (this.maxQueueSize <= 0) { throw new IllegalArgumentException("Maximum queue size should be non negative"); } } BoundedPriorityQueue(int maxQueueSize, Comparator<? super E> comparator); int getMaxQueueSize(); @Override boolean add(E o); @Override boolean addAll(Collection<? extends E> c);  }
@Test public final void testBoundedPriorityQueue() { BoundedPriorityQueue<Integer> queue = new BoundedPriorityQueue<>(2, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return (int) Math.signum(o1 - o2); } }); queue.add(5); queue.add(4); assertEquals(queue.element(), new Integer(4)); queue.add(3); queue.add(2); assertEquals(queue.element(), new Integer(2)); }