[COLLECTIONS-706] Set Entry count to 0 after remove.

This commit is contained in:
Bobby Wertman 2019-01-20 09:07:01 -05:00 committed by Gary Gregory
parent 441dbb2e25
commit ea11bf98b0
3 changed files with 20 additions and 0 deletions

View File

@ -45,6 +45,9 @@
<action issue="COLLECTIONS-706" dev="ggregory" type="fix" due-to="Richard Eckart de Castilho, Gary Gregory">
Add SetUtils.unmodifiableSet(T... items) method.
</action>
<action issue="COLLECTIONS-709" dev="ggregory" type="fix" due-to="Robert Wertman">
MultiSet.Entry::getCount() isn't 0 after removing the last element.
</action>
</release>
<release version="4.2" date="2018-07-11" description="Update from Java 6 to Java 7, bug fixes, and small changes.">
<action issue="COLLECTIONS-681" dev="kinow" type="add" due-to="Stephan Fuhrmann">

View File

@ -265,6 +265,7 @@ public abstract class AbstractMapMultiSet<E> extends AbstractMultiSet<E> {
} else {
map.remove(object);
size -= mut.value;
mut.value = 0;
}
}
return oldCount;

View File

@ -462,6 +462,22 @@ public abstract class AbstractMultiSetTest<T> extends AbstractCollectionTest<T>
assertEquals(false, it2.hasNext());
}
@SuppressWarnings("unchecked")
public void testMultiSetEntrySetUpdatedToZero() {
if (!isAddSupported()) {
return;
}
final MultiSet<T> multiset = makeObject();
multiset.add((T) "A");
multiset.add((T) "A");
final MultiSet.Entry<T> entry = multiset.entrySet().iterator().next();
assertEquals(2, entry.getCount());
multiset.remove((T) "A");
assertEquals(1, entry.getCount());
multiset.remove((T) "A");
assertEquals(0, entry.getCount());
}
@SuppressWarnings("unchecked")
public void testMultiSetToArray() {
if (!isAddSupported()) {