Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 37972 invoked from network); 16 Mar 2008 02:37:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Mar 2008 02:37:46 -0000 Received: (qmail 79384 invoked by uid 500); 16 Mar 2008 02:37:43 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 79330 invoked by uid 500); 16 Mar 2008 02:37:42 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 79321 invoked by uid 99); 16 Mar 2008 02:37:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 15 Mar 2008 19:37:42 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Mar 2008 02:37:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 37FA91A9832; Sat, 15 Mar 2008 19:37:22 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080316023722.37FA91A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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();