Backport COLLECTIONS-228 to 3.2.2.

git-svn-id: 
https://svn.apache.org/repos/asf/commons/proper/collections/branches/COLLECTIONS_3_2_X@1713175
 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/commons-collections/commit/3afb3cb3
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/3afb3cb3
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/3afb3cb3

Branch: refs/heads/COLLECTIONS_3_2_X
Commit: 3afb3cb3452fa78d629facfb2d29d5d4f5b06dd7
Parents: 9876243
Author: Thomas Neidhart <t...@apache.org>
Authored: Sat Nov 7 20:47:04 2015 +0000
Committer: Thomas Neidhart <t...@apache.org>
Committed: Sat Nov 7 20:47:04 2015 +0000

----------------------------------------------------------------------
 src/changes/changes.xml                                  |  8 ++++----
 .../apache/commons/collections/map/MultiValueMap.java    | 11 ++++++-----
 .../commons/collections/map/TestMultiValueMap.java       | 11 +++++++++++
 3 files changed, 21 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-collections/blob/3afb3cb3/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 69031da..e06564d 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.
     </action>
+    <action issue="COLLECTIONS-228" dev="scolebourne" type="fix">
+      "MultiValueMap#put(Object, Object)" and "MultiValueMap#putAll(Object, 
Collection)"
+      now correctly return if the map has changed by this operation.
+    </action>
     <action issue="COLLECTIONS-219" dev="scolebourne" type="fix" due-to="Tom 
Leccese">
       "CollectionUtils#removeAll" wrongly called "ListUtils#retainAll".
     </action>
@@ -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.
     </action>
-    <action issue="COLLECTIONS-228" dev="scolebourne" type="fix">
-      "MultiValueMap#put(Object, Object)" and "MultiValueMap#putAll(Object, 
Collection)"
-      now correctly return if the map has changed by this operation.
-    </action>
     <action issue="COLLECTIONS-217" dev="scolebourne" type="fix" due-to="Matt 
Bishop">
       Calling "setValue(Object)" on any Entry returned by a "Flat3Map" will now
       correctly set the value for the current entry.

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/3afb3cb3/src/java/org/apache/commons/collections/map/MultiValueMap.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/map/MultiValueMap.java 
b/src/java/org/apache/commons/collections/map/MultiValueMap.java
index cc74fd7..7b7afb5 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;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/3afb3cb3/src/test/org/apache/commons/collections/map/TestMultiValueMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/map/TestMultiValueMap.java 
b/src/test/org/apache/commons/collections/map/TestMultiValueMap.java
index 7b322dc..b9a5ac8 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");

Reply via email to