commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections MultiHashMap.java
Date Wed, 09 Jun 2004 22:11:54 GMT
scolebourne    2004/06/09 15:11:54

  Modified:    collections/src/test/org/apache/commons/collections
                        TestMultiHashMap.java
               collections/src/java/org/apache/commons/collections
                        MultiHashMap.java
  Log:
  Fix copy constructor to work on JDK1.3
  
  Revision  Changes    Path
  1.20      +29 -2     jakarta-commons/collections/src/test/org/apache/commons/collections/TestMultiHashMap.java
  
  Index: TestMultiHashMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TestMultiHashMap.java	14 May 2004 22:33:58 -0000	1.19
  +++ TestMultiHashMap.java	9 Jun 2004 22:11:54 -0000	1.20
  @@ -18,6 +18,7 @@
   import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.Collection;
  +import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
   
  @@ -368,7 +369,7 @@
           assertEquals(2, clonedColl.size());
       }
   
  -    public void testConstructor() {
  +    public void testConstructorCopy1() {
           MultiHashMap map = new MultiHashMap();
           map.put("A", "1");
           map.put("A", "2");
  @@ -384,10 +385,36 @@
           assertEquals(2, coll.size());
           assertEquals(1, newMap.size());
           assertEquals(2, newColl.size());
  +        
           map.put("A", "3");
           assertEquals(1, map.size());
           assertEquals(3, coll.size());
           assertEquals(1, newMap.size());
           assertEquals(2, newColl.size());
       }
  +
  +    public void testConstructorCopy2() {
  +        Map map = new HashMap();
  +        map.put("A", "1");
  +        map.put("B", "2");
  +        assertEquals(2, map.size());
  +        
  +        MultiHashMap newMap = new MultiHashMap(map);
  +        Collection newColl = (Collection) newMap.get("A");
  +        assertNotSame(map, newMap);
  +        assertEquals(2, map.size());
  +        assertEquals(2, newMap.size());
  +        assertEquals(1, newColl.size());
  +        
  +        map.put("A", "3");
  +        assertEquals(2, map.size());
  +        assertEquals(2, newMap.size());
  +        assertEquals(1, newColl.size());
  +        
  +        map.put("C", "4");
  +        assertEquals(3, map.size());
  +        assertEquals(2, newMap.size());
  +        assertEquals(1, newColl.size());
  +    }
  +
   }
  
  
  
  1.20      +7 -4      jakarta-commons/collections/src/java/org/apache/commons/collections/MultiHashMap.java
  
  Index: MultiHashMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MultiHashMap.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- MultiHashMap.java	26 May 2004 21:56:05 -0000	1.19
  +++ MultiHashMap.java	9 Jun 2004 22:11:54 -0000	1.20
  @@ -109,14 +109,17 @@
        * @param mapToCopy  a Map to copy
        */
       public MultiHashMap(Map mapToCopy) {
  -        super(mapToCopy);
  +        // be careful of JDK 1.3 vs 1.4 differences
  +        super((int) (mapToCopy.size() * 1.4f));
           if (mapToCopy instanceof MultiMap) {
  -            for (Iterator it = entrySet().iterator(); it.hasNext();) {
  +            for (Iterator it = mapToCopy.entrySet().iterator(); it.hasNext();) {
                   Map.Entry entry = (Map.Entry) it.next();
                   Collection coll = (Collection) entry.getValue();
                   Collection newColl = createCollection(coll);
  -                entry.setValue(newColl);
  +                super.put(entry.getKey(), newColl);
               }
  +        } else {
  +            putAll(mapToCopy);
           }
       }
   
  
  
  

---------------------------------------------------------------------
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