@Test public void testConditionalRemove() { ExtendedSet<TestValue> set = new ExtendedSet<>(Maps.newConcurrentMap()); TestValue small = new TestValue("foo", 1); TestValue medium = new TestValue("foo", 2); assertTrue(set.add(small)); set.conditionalRemove(medium, existing -> existing.value2() < medium.value2); assertFalse(set.contains(small)); }
public boolean conditionalRemove(E entry, Predicate<E> entryTest) { AtomicBoolean updated = new AtomicBoolean(false); map.compute(entry, (k, v) -> { if (entryTest.test(v)) { updated.set(true); return null; } return v; }); return updated.get(); }
ExtendedSet implements Set<E> { public boolean conditionalRemove(E entry, Predicate<E> entryTest) { AtomicBoolean updated = new AtomicBoolean(false); map.compute(entry, (k, v) -> { if (entryTest.test(v)) { updated.set(true); return null; } return v; }); return updated.get(); } }
ExtendedSet implements Set<E> { public boolean conditionalRemove(E entry, Predicate<E> entryTest) { AtomicBoolean updated = new AtomicBoolean(false); map.compute(entry, (k, v) -> { if (entryTest.test(v)) { updated.set(true); return null; } return v; }); return updated.get(); } ExtendedSet(Map<E, E> map); }
ExtendedSet implements Set<E> { public boolean conditionalRemove(E entry, Predicate<E> entryTest) { AtomicBoolean updated = new AtomicBoolean(false); map.compute(entry, (k, v) -> { if (entryTest.test(v)) { updated.set(true); return null; } return v; }); return updated.get(); } ExtendedSet(Map<E, E> map); E get(Object o); boolean insertOrReplace(E entry, Predicate<E> entryTest); boolean conditionalRemove(E entry, Predicate<E> entryTest); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override boolean add(E e); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends E> c); @Override boolean retainAll(Collection<?> c); @Override boolean removeAll(Collection<?> c); @Override void clear(); }
ExtendedSet implements Set<E> { public boolean conditionalRemove(E entry, Predicate<E> entryTest) { AtomicBoolean updated = new AtomicBoolean(false); map.compute(entry, (k, v) -> { if (entryTest.test(v)) { updated.set(true); return null; } return v; }); return updated.get(); } ExtendedSet(Map<E, E> map); E get(Object o); boolean insertOrReplace(E entry, Predicate<E> entryTest); boolean conditionalRemove(E entry, Predicate<E> entryTest); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override boolean add(E e); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends E> c); @Override boolean retainAll(Collection<?> c); @Override boolean removeAll(Collection<?> c); @Override void clear();  }