[COLLECTIONS-500] Renamed MultiMap.remove(K, V) to boolean removeMapping(K, V).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1542763 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
04af9bc8ee
commit
4f296da76c
|
@ -47,6 +47,8 @@ Major changes since 3.2.1
|
|||
Changes since 4.0-alpha1
|
||||
------------------------
|
||||
|
||||
o [COLLECTIONS-500] Renamed "V MultiMap#remove(K, V)" to "boolean MultiMap#removeMapping(K, V)"
|
||||
to avoid future conflicts with a default method of the Map interface in Java 8.
|
||||
o [COLLECTIONS-499] Refactored the test framework for Bag implementations to extend from
|
||||
"AbstractCollectionTest" by decorating the concrete Bag instance with
|
||||
a CollectionBag or CollectionSortedBag.
|
||||
|
@ -171,6 +173,8 @@ New features
|
|||
Changed classes / methods
|
||||
-------------------------
|
||||
|
||||
o [COLLECTIONS-500] Renamed "V MultiMap#remove(K, V)" to "boolean MultiMap#removeMapping(K, V)"
|
||||
to avoid future conflicts with a default method of the Map interface in Java 8.
|
||||
o [COLLECTIONS-499] Refactored the test framework for Bag implementations to extend from
|
||||
"AbstractCollectionTest" by decorating the concrete Bag instance with
|
||||
a CollectionBag or CollectionSortedBag.
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
</properties>
|
||||
<body>
|
||||
|
||||
<release version="4.0" date="2013-11-15" description="
|
||||
<release version="4.0" date="2013-11-18" description="
|
||||
This is a major release: It combines bug fixes, new features and
|
||||
changes to existing features.
|
||||
|
||||
|
@ -38,6 +38,10 @@ Commons Collections is Java 5.
|
|||
Users are encouraged to upgrade to this version as, in addition to new
|
||||
features, this release includes numerous bug fixes.
|
||||
">
|
||||
<action issue="COLLECTIONS-500" dev="tn" type="update">
|
||||
Renamed "V MultiMap#remove(K, V)" to "boolean MultiMap#removeMapping(K, V)"
|
||||
to avoid future conflicts with a default method of the Map interface in Java 8.
|
||||
</action>
|
||||
<action issue="COLLECTIONS-499" dev="tn" type="update">
|
||||
Refactored the test framework for Bag implementations to extend from
|
||||
"AbstractCollectionTest" by decorating the concrete Bag instance with
|
||||
|
|
|
@ -56,12 +56,13 @@ public interface MultiMap<K, V> extends IterableMap<K, Object> {
|
|||
*
|
||||
* @param key the key to remove from
|
||||
* @param item the item to remove
|
||||
* @return the value removed (which was passed in), null if nothing removed
|
||||
* @return {@code true} if the mapping was removed, {@code false} otherwise
|
||||
* @throws UnsupportedOperationException if the map is unmodifiable
|
||||
* @throws ClassCastException if the key or value is of an invalid type
|
||||
* @throws NullPointerException if the key or value is null and null is invalid
|
||||
* @since 4.0 (signature in previous releases: V remove(K, V))
|
||||
*/
|
||||
public V remove(K key, V item);
|
||||
boolean removeMapping(K key, V item);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
|
|
|
@ -205,22 +205,21 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
|
|||
*
|
||||
* @param key the key to remove from
|
||||
* @param value the value to remove
|
||||
* @return the value removed (which was passed in), null if nothing removed
|
||||
* @return {@code true} if the mapping was removed, {@code false} otherwise
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public V remove(final Object key, final Object value) {
|
||||
public boolean removeMapping(final Object key, final Object value) {
|
||||
final Collection<V> valuesForKey = getCollection(key);
|
||||
if (valuesForKey == null) {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
final boolean removed = valuesForKey.remove(value);
|
||||
if (removed == false) {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
if (valuesForKey.isEmpty()) {
|
||||
remove(key);
|
||||
}
|
||||
return (V) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -156,6 +156,8 @@ have changed.
|
|||
|
||||
<center><h3>Changed classes / methods</h3></center>
|
||||
<ul>
|
||||
<li>Renamed "V MultiMap#remove(K, V)" to "boolean MultiMap#removeMapping(K, V)"
|
||||
to avoid future conflicts with a default method of the Map interface in Java 8.</li>
|
||||
<li>Refactored the test framework for Bag implementations to extend from "AbstractCollectionTest" by decorating
|
||||
the concrete Bag instance with a CollectionBag or CollectionSortedBag.</li>
|
||||
<li>"UnmodifiableBoundedCollection" does now also implement the marker interface "Unmodifiable"
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import org.apache.commons.collections4.AbstractObjectTest;
|
||||
import org.apache.commons.collections4.IteratorUtils;
|
||||
import org.apache.commons.collections4.MultiMap;
|
||||
|
@ -179,7 +178,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||
final MultiValueMap<K, V> one = new MultiValueMap<K, V>();
|
||||
final Integer value = Integer.valueOf(1);
|
||||
one.put((K) "One", value);
|
||||
one.remove("One", value);
|
||||
one.removeMapping("One", value);
|
||||
|
||||
final MultiValueMap<K, V> two = new MultiValueMap<K, V>();
|
||||
assertEquals(two, one);
|
||||
|
@ -207,7 +206,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||
assertEquals(4, map.totalSize());
|
||||
map.remove("A");
|
||||
assertEquals(3, map.totalSize());
|
||||
map.remove("B", "BC");
|
||||
map.removeMapping("B", "BC");
|
||||
assertEquals(2, map.totalSize());
|
||||
}
|
||||
|
||||
|
@ -225,7 +224,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||
assertEquals(2, map.size());
|
||||
map.remove("A");
|
||||
assertEquals(1, map.size());
|
||||
map.remove("B", "BC");
|
||||
map.removeMapping("B", "BC");
|
||||
assertEquals(1, map.size());
|
||||
}
|
||||
|
||||
|
@ -249,7 +248,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||
map.remove("A");
|
||||
assertEquals(0, map.size("A"));
|
||||
assertEquals(3, map.size("B"));
|
||||
map.remove("B", "BC");
|
||||
map.removeMapping("B", "BC");
|
||||
assertEquals(0, map.size("A"));
|
||||
assertEquals(2, map.size("B"));
|
||||
}
|
||||
|
@ -377,11 +376,11 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||
map.put((K) "A", "AA");
|
||||
map.put((K) "A", "AB");
|
||||
map.put((K) "A", "AC");
|
||||
assertEquals(null, map.remove("C", "CA"));
|
||||
assertEquals(null, map.remove("A", "AD"));
|
||||
assertEquals("AC", map.remove("A", "AC"));
|
||||
assertEquals("AB", map.remove("A", "AB"));
|
||||
assertEquals("AA", map.remove("A", "AA"));
|
||||
assertEquals(false, map.removeMapping("C", "CA"));
|
||||
assertEquals(false, map.removeMapping("A", "AD"));
|
||||
assertEquals(true, map.removeMapping("A", "AC"));
|
||||
assertEquals(true, map.removeMapping("A", "AB"));
|
||||
assertEquals(true, map.removeMapping("A", "AA"));
|
||||
assertEquals(new MultiValueMap<K, V>(), map);
|
||||
}
|
||||
|
||||
|
@ -397,7 +396,8 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||
|
||||
@Override
|
||||
public Object makeObject() {
|
||||
final Map m = makeEmptyMap();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, String> m = makeEmptyMap();
|
||||
m.put("a", "1");
|
||||
m.put("a", "1b");
|
||||
m.put("b", "2");
|
||||
|
@ -407,6 +407,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||
return m;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Map makeEmptyMap() {
|
||||
return new MultiValueMap();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue