PriorityCollection extends AbstractCollection<T> { @Override public synchronized boolean remove(Object o) { boolean result = removeInternal(o); calcSize(); return result; } PriorityCollection(Supplier<Collection<T>> supplier); @Override int size(); @Override boolean isEmpty(); Set<Integer> getPriorites(); @Override Iterator<T> iterator(); ResettableIterator<T> resettableIterator(); @Override void forEach(Consumer<? super T> action); @Override synchronized boolean add(T t); @Override synchronized boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override synchronized boolean addAll(Collection<? extends T> c); @Override synchronized boolean removeAll(Collection<?> c); @Override synchronized boolean retainAll(Collection<?> c); @Override synchronized void clear(); @Override boolean contains(Object o); boolean contains(PriorityAware priorityAware);  }
@Test public void testRemove() { PriorityCollection<TestPriorityAware> set = new PriorityCollection<>(CopyOnWriteArraySet::new); assertTrue(set.isEmpty()); assertTrue(set.add(new TestPriorityAware(1))); assertFalse(set.isEmpty()); assertFalse(set.remove(new TestPriorityAware(0))); assertFalse(set.isEmpty()); assertTrue(set.remove(new TestPriorityAware(1))); assertTrue(set.isEmpty()); }