diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 69031daaa..e06564d64 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -30,6 +30,10 @@ "SetUniqueList.addAll(int, Collection)" now correctly add the collection at the provided index. + + "MultiValueMap#put(Object, Object)" and "MultiValueMap#putAll(Object, Collection)" + now correctly return if the map has changed by this operation. + "CollectionUtils#removeAll" wrongly called "ListUtils#retainAll". @@ -78,10 +82,6 @@ "Flat3Map#remove(Object)" will now return the correct value mapped to the removed key if the size of the map is less or equal 3. - - "MultiValueMap#put(Object, Object)" and "MultiValueMap#putAll(Object, Collection)" - now correctly return if the map has changed by this operation. - Calling "setValue(Object)" on any Entry returned by a "Flat3Map" will now correctly set the value for the current entry. diff --git a/src/java/org/apache/commons/collections/map/MultiValueMap.java b/src/java/org/apache/commons/collections/map/MultiValueMap.java index cc74fd751..7b7afb55a 100644 --- a/src/java/org/apache/commons/collections/map/MultiValueMap.java +++ b/src/java/org/apache/commons/collections/map/MultiValueMap.java @@ -211,7 +211,7 @@ public class MultiValueMap extends AbstractMapDecorator implements MultiMap { if (coll.size() > 0) { // only add if non-zero size to maintain class state getMap().put(key, coll); - result = false; + result = true; // map definitely changed } } else { result = coll.add(value); @@ -308,19 +308,20 @@ public class MultiValueMap extends AbstractMapDecorator implements MultiMap { if (values == null || values.size() == 0) { return false; } + boolean result = false; Collection coll = getCollection(key); if (coll == null) { coll = createCollection(values.size()); - boolean result = coll.addAll(values); + coll.addAll(values); if (coll.size() > 0) { // only add if non-zero size to maintain class state getMap().put(key, coll); - result = false; + result = true; // map definitely changed } - return result; } else { - return coll.addAll(values); + result = coll.addAll(values); } + return result; } /** diff --git a/src/test/org/apache/commons/collections/map/TestMultiValueMap.java b/src/test/org/apache/commons/collections/map/TestMultiValueMap.java index 7b322dc02..b9a5ac850 100644 --- a/src/test/org/apache/commons/collections/map/TestMultiValueMap.java +++ b/src/test/org/apache/commons/collections/map/TestMultiValueMap.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.Map; import junit.framework.Test; @@ -250,6 +251,16 @@ public class TestMultiValueMap extends TestCase { assertEquals(false, map.containsValue("A", "AB")); } + public void testPut_ReturnValue() { + MultiValueMap test = new MultiValueMap(); + assertNotNull(test.put("key", "object1")); + assertNotNull(test.put("key", "object2")); + + List coll = Arrays.asList(new String[]{"uno", "un"}); + assertTrue(test.putAll("key", coll)); + assertFalse(test.putAll("key", new ArrayList())); + } + public void testPutAll_Map1() { MultiMap original = new MultiValueMap(); original.put("key", "object1");