commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r468684 - in /jakarta/commons/proper/collections/trunk: RELEASE-NOTES.html src/java/org/apache/commons/collections/map/MultiValueMap.java src/test/org/apache/commons/collections/map/TestMultiValueMap.java
Date Sat, 28 Oct 2006 12:27:02 GMT
Author: scolebourne
Date: Sat Oct 28 05:27:01 2006
New Revision: 468684

URL: http://svn.apache.org/viewvc?view=rev&rev=468684
Log:
COLLECTIONS-228 - MultiValueMap put and putAll do not return the correct values

Modified:
    jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
    jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java
    jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java

Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html?view=diff&rev=468684&r1=468683&r2=468684
==============================================================================
--- jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html (original)
+++ jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html Sat Oct 28 05:27:01 2006
@@ -57,6 +57,7 @@
 <li>Flat3Map - Fix setValue in MapIterator and EntrySetIterator to work correctly [COLLECTIONS-217]</li>
 <li>ExtendedProperties - Include property name had confused static/instance semantics
[COLLECTIONS-214]</li>
 <li>CollectionUtils - Fix removeAll() method which was completely broken [COLLECTIONS-219]</li>
+<li>MultiValueMap - Fix put() and putAll() to return correct results [COLLECTIONS-228]</li>
 </ul>
 
 <center><h3>JAVADOC</h3></center>

Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java?view=diff&rev=468684&r1=468683&r2=468684
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java
Sat Oct 28 05:27:01 2006
@@ -205,12 +205,12 @@
         boolean result = false;
         Collection coll = getCollection(key);
         if (coll == null) {
-            coll = createCollection(1);
-            result = coll.add(value);
+            coll = createCollection(1);  // might produce a non-empty collection
+            coll.add(value);
             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);
@@ -307,19 +307,20 @@
         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 = createCollection(values.size());  // might produce a non-empty collection
+            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;
     }
 
     /**

Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java?view=diff&rev=468684&r1=468683&r2=468684
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java
Sat Oct 28 05:27:01 2006
@@ -30,7 +30,6 @@
 
 import org.apache.commons.collections.IteratorUtils;
 import org.apache.commons.collections.MultiMap;
-import org.apache.commons.collections.TestMultiHashMap;
 
 /**
  * TestMultiValueMap.
@@ -46,11 +45,11 @@
     }
 
     public static Test suite() {
-        return new TestSuite(TestMultiHashMap.class);
+        return new TestSuite(TestMultiValueMap.class);
     }
 
     public static void main(String args[]) {
-        String[] testCaseName = { TestMultiHashMap.class.getName()};
+        String[] testCaseName = { TestMultiValueMap.class.getName()};
         junit.textui.TestRunner.main(testCaseName);
     }
 
@@ -201,9 +200,9 @@
         map.put("B", "BC");
         assertEquals(2, map.size());
         map.remove("A");
-        assertEquals(2, map.size());
+        assertEquals(1, map.size());
         map.remove("B", "BC");
-        assertEquals(2, map.size());
+        assertEquals(1, map.size());
     }
     
     public void testSize_Key() {
@@ -247,6 +246,25 @@
         map.put("A", "AA");
         assertEquals(true, map.containsValue("A", "AA"));
         assertEquals(false, map.containsValue("A", "AB"));
+    }
+
+    public void testPutWithList() {
+        MultiValueMap test = MultiValueMap.decorate(new HashMap(), ArrayList.class);
+        assertEquals("a", test.put("A", "a"));
+        assertEquals("b", test.put("A", "b"));
+        assertEquals(1, test.size());
+        assertEquals(2, test.size("A"));
+        assertEquals(2, test.totalSize());
+    }
+
+    public void testPutWithSet() {
+        MultiValueMap test = MultiValueMap.decorate(new HashMap(), HashSet.class);
+        assertEquals("a", test.put("A", "a"));
+        assertEquals("b", test.put("A", "b"));
+        assertEquals(null, test.put("A", "a"));
+        assertEquals(1, test.size());
+        assertEquals(2, test.size("A"));
+        assertEquals(2, test.totalSize());
     }
 
     public void testPutAll_Map1() {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message