[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
|
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
|
o [COLLECTIONS-499] Refactored the test framework for Bag implementations to extend from
|
||||||
"AbstractCollectionTest" by decorating the concrete Bag instance with
|
"AbstractCollectionTest" by decorating the concrete Bag instance with
|
||||||
a CollectionBag or CollectionSortedBag.
|
a CollectionBag or CollectionSortedBag.
|
||||||
|
@ -171,6 +173,8 @@ New features
|
||||||
Changed classes / methods
|
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
|
o [COLLECTIONS-499] Refactored the test framework for Bag implementations to extend from
|
||||||
"AbstractCollectionTest" by decorating the concrete Bag instance with
|
"AbstractCollectionTest" by decorating the concrete Bag instance with
|
||||||
a CollectionBag or CollectionSortedBag.
|
a CollectionBag or CollectionSortedBag.
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
</properties>
|
</properties>
|
||||||
<body>
|
<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
|
This is a major release: It combines bug fixes, new features and
|
||||||
changes to existing features.
|
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
|
Users are encouraged to upgrade to this version as, in addition to new
|
||||||
features, this release includes numerous bug fixes.
|
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">
|
<action issue="COLLECTIONS-499" dev="tn" type="update">
|
||||||
Refactored the test framework for Bag implementations to extend from
|
Refactored the test framework for Bag implementations to extend from
|
||||||
"AbstractCollectionTest" by decorating the concrete Bag instance with
|
"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 key the key to remove from
|
||||||
* @param item the item to remove
|
* @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 UnsupportedOperationException if the map is unmodifiable
|
||||||
* @throws ClassCastException if the key or value is of an invalid type
|
* @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
|
* @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 key the key to remove from
|
||||||
* @param value the value to remove
|
* @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 boolean removeMapping(final Object key, final Object value) {
|
||||||
public V remove(final Object key, final Object value) {
|
|
||||||
final Collection<V> valuesForKey = getCollection(key);
|
final Collection<V> valuesForKey = getCollection(key);
|
||||||
if (valuesForKey == null) {
|
if (valuesForKey == null) {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
final boolean removed = valuesForKey.remove(value);
|
final boolean removed = valuesForKey.remove(value);
|
||||||
if (removed == false) {
|
if (removed == false) {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
if (valuesForKey.isEmpty()) {
|
if (valuesForKey.isEmpty()) {
|
||||||
remove(key);
|
remove(key);
|
||||||
}
|
}
|
||||||
return (V) value;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -156,6 +156,8 @@ have changed.
|
||||||
|
|
||||||
<center><h3>Changed classes / methods</h3></center>
|
<center><h3>Changed classes / methods</h3></center>
|
||||||
<ul>
|
<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
|
<li>Refactored the test framework for Bag implementations to extend from "AbstractCollectionTest" by decorating
|
||||||
the concrete Bag instance with a CollectionBag or CollectionSortedBag.</li>
|
the concrete Bag instance with a CollectionBag or CollectionSortedBag.</li>
|
||||||
<li>"UnmodifiableBoundedCollection" does now also implement the marker interface "Unmodifiable"
|
<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.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.commons.collections4.AbstractObjectTest;
|
import org.apache.commons.collections4.AbstractObjectTest;
|
||||||
import org.apache.commons.collections4.IteratorUtils;
|
import org.apache.commons.collections4.IteratorUtils;
|
||||||
import org.apache.commons.collections4.MultiMap;
|
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 MultiValueMap<K, V> one = new MultiValueMap<K, V>();
|
||||||
final Integer value = Integer.valueOf(1);
|
final Integer value = Integer.valueOf(1);
|
||||||
one.put((K) "One", value);
|
one.put((K) "One", value);
|
||||||
one.remove("One", value);
|
one.removeMapping("One", value);
|
||||||
|
|
||||||
final MultiValueMap<K, V> two = new MultiValueMap<K, V>();
|
final MultiValueMap<K, V> two = new MultiValueMap<K, V>();
|
||||||
assertEquals(two, one);
|
assertEquals(two, one);
|
||||||
|
@ -207,7 +206,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
||||||
assertEquals(4, map.totalSize());
|
assertEquals(4, map.totalSize());
|
||||||
map.remove("A");
|
map.remove("A");
|
||||||
assertEquals(3, map.totalSize());
|
assertEquals(3, map.totalSize());
|
||||||
map.remove("B", "BC");
|
map.removeMapping("B", "BC");
|
||||||
assertEquals(2, map.totalSize());
|
assertEquals(2, map.totalSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +224,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
||||||
assertEquals(2, map.size());
|
assertEquals(2, map.size());
|
||||||
map.remove("A");
|
map.remove("A");
|
||||||
assertEquals(1, map.size());
|
assertEquals(1, map.size());
|
||||||
map.remove("B", "BC");
|
map.removeMapping("B", "BC");
|
||||||
assertEquals(1, map.size());
|
assertEquals(1, map.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +248,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
||||||
map.remove("A");
|
map.remove("A");
|
||||||
assertEquals(0, map.size("A"));
|
assertEquals(0, map.size("A"));
|
||||||
assertEquals(3, map.size("B"));
|
assertEquals(3, map.size("B"));
|
||||||
map.remove("B", "BC");
|
map.removeMapping("B", "BC");
|
||||||
assertEquals(0, map.size("A"));
|
assertEquals(0, map.size("A"));
|
||||||
assertEquals(2, map.size("B"));
|
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", "AA");
|
||||||
map.put((K) "A", "AB");
|
map.put((K) "A", "AB");
|
||||||
map.put((K) "A", "AC");
|
map.put((K) "A", "AC");
|
||||||
assertEquals(null, map.remove("C", "CA"));
|
assertEquals(false, map.removeMapping("C", "CA"));
|
||||||
assertEquals(null, map.remove("A", "AD"));
|
assertEquals(false, map.removeMapping("A", "AD"));
|
||||||
assertEquals("AC", map.remove("A", "AC"));
|
assertEquals(true, map.removeMapping("A", "AC"));
|
||||||
assertEquals("AB", map.remove("A", "AB"));
|
assertEquals(true, map.removeMapping("A", "AB"));
|
||||||
assertEquals("AA", map.remove("A", "AA"));
|
assertEquals(true, map.removeMapping("A", "AA"));
|
||||||
assertEquals(new MultiValueMap<K, V>(), map);
|
assertEquals(new MultiValueMap<K, V>(), map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +396,8 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object makeObject() {
|
public Object makeObject() {
|
||||||
final Map m = makeEmptyMap();
|
@SuppressWarnings("unchecked")
|
||||||
|
final Map<String, String> m = makeEmptyMap();
|
||||||
m.put("a", "1");
|
m.put("a", "1");
|
||||||
m.put("a", "1b");
|
m.put("a", "1b");
|
||||||
m.put("b", "2");
|
m.put("b", "2");
|
||||||
|
@ -407,6 +407,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
private Map makeEmptyMap() {
|
private Map makeEmptyMap() {
|
||||||
return new MultiValueMap();
|
return new MultiValueMap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue