commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r637512 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/map/ListOrderedMap.java test/org/apache/commons/collections/map/TestListOrderedMap.java
Date Sun, 16 Mar 2008 02:37:21 GMT
Author: bayard
Date: Sat Mar 15 19:37:19 2008
New Revision: 637512

URL: http://svn.apache.org/viewvc?rev=637512&view=rev
Log:
Adding a putAll method to ListOrderedMap as per COLLECTIONS-226 and Dave Meikle's patch

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ListOrderedMap.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ListOrderedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ListOrderedMap.java?rev=637512&r1=637511&r2=637512&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ListOrderedMap.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/ListOrderedMap.java
Sat Mar 15 19:37:19 2008
@@ -66,6 +66,7 @@
  * 
  * @author Stephen Colebourne
  * @author Matt Benson
+ * @author Dave Meikle
  */
 public class ListOrderedMap
         extends AbstractMapDecorator
@@ -220,6 +221,21 @@
         for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
             Map.Entry entry = (Map.Entry) it.next();
             put(entry.getKey(), entry.getValue());
+        }
+    }
+
+    /**
+     * Puts the values contained in a supplied Map into the Map starting at
+     * the specified index.
+     *
+     * @param index the index in the Map to start at.
+     * @param map the Map containing the values to be added.
+     */
+    public void putAll(int index, Map map) {
+        for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
+            Map.Entry entry = (Map.Entry) it.next();
+            put(index, entry.getKey(), entry.getValue());
+            index++;
         }
     }
 

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java?rev=637512&r1=637511&r2=637512&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java
Sat Mar 15 19:37:19 2008
@@ -299,6 +299,32 @@
         assertEquals("One", lom.getValue(2));
     }
 
+    public void testPutAllWithIndex() {
+        resetEmpty();
+        ListOrderedMap lom = (ListOrderedMap) map;
+
+        // Create Initial Data
+        lom.put("testInsert0", "testInsert0v");
+        lom.put("testInsert1", "testInsert1v");
+        lom.put("testInsert2", "testInsert2v");
+        assertEquals("testInsert0v", lom.getValue(0));
+        assertEquals("testInsert1v", lom.getValue(1));
+        assertEquals("testInsert2v", lom.getValue(2));
+
+        // Create New Test Map and Add using putAll(int, Object, Object)
+        Map values = new HashMap();
+        values.put("NewInsert0", "NewInsert0v");
+        values.put("NewInsert1", "NewInsert1v");
+        lom.putAll(1, values);
+
+        // Perform Asserts
+        assertEquals("testInsert0v", lom.getValue(0));
+        assertEquals("NewInsert0v", lom.getValue(1));
+        assertEquals("NewInsert1v", lom.getValue(2));
+        assertEquals("testInsert1v", lom.getValue(3));
+        assertEquals("testInsert2v", lom.getValue(4));
+    }
+
     //-----------------------------------------------------------------------
     public void testValueList_getByIndex() {
         resetFull();



Mime
View raw message