UpdateablePriorityQueue implements Iterable<E>, Serializable { public boolean remove(final ElementRef qe) { int i = qe.index; if (i == -1) { return false; } else { removeAt(i); return true; } } UpdateablePriorityQueue();  UpdateablePriorityQueue(final int initialCapacity);  UpdateablePriorityQueue(final int initialCapacity,
            final Comparator<? super E> comparator); ElementRef add(@Nonnull final E e); @Nullable E peek(); @Nullable ElementRef peekEntry(); boolean remove(final ElementRef qe); boolean remove(final E o); boolean isEmpty(); boolean contains(final E o); Object[] toArray(); @SuppressWarnings("unchecked") T[] toArray(final T[] a); @Override Iterator<E> iterator(); int size(); void clear(); @Nullable @SuppressFBWarnings("BAS_BLOATED_ASSIGNMENT_SCOPE") E poll(); Comparator<? super E> comparator(); void heapify(); @Override String toString();  }
@Test public void testRemove() { UpdateablePriorityQueue<MutableHolder<Integer>> queue = new UpdateablePriorityQueue<>(0); final MutableHolder<Integer> value = MutableHolder.of(3); UpdateablePriorityQueue.ElementRef ref = queue.add(value); final MutableHolder<Integer> four = MutableHolder.of(4); queue.add(four); final MutableHolder<Integer> five = MutableHolder.of(5); queue.add(five); final MutableHolder<Integer> six = MutableHolder.of(6); queue.add(six); MutableHolder<Integer> poll = queue.poll(); Assert.assertEquals(value, poll); Assert.assertFalse(ref.remove()); Iterator<MutableHolder<Integer>> iterator = queue.iterator(); iterator.next(); iterator.next(); iterator.remove(); iterator.next(); Assert.assertFalse(iterator.hasNext()); Assert.assertEquals(2, queue.size()); }