Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 33498 invoked from network); 16 May 2008 08:10:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 May 2008 08:10:07 -0000 Received: (qmail 54745 invoked by uid 500); 16 May 2008 08:10:08 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 54673 invoked by uid 500); 16 May 2008 08:10:08 -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 54664 invoked by uid 99); 16 May 2008 08:10:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 May 2008 01:10:08 -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.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 May 2008 08:09:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BE8CF23889F3; Fri, 16 May 2008 01:09:42 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r656960 - in /commons/proper/collections/trunk: data/test/ src/java/org/apache/commons/collections/map/ src/test/org/apache/commons/collections/map/ Date: Fri, 16 May 2008 08:09:42 -0000 To: commits@commons.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080516080942.BE8CF23889F3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bayard Date: Fri May 16 01:09:42 2008 New Revision: 656960 URL: http://svn.apache.org/viewvc?rev=656960&view=rev Log: Making MultiValueMap serializable as per COLLECTIONS-240 Added: commons/proper/collections/trunk/data/test/MultiValueMap.emptyCollection.version3.3.obj (with props) commons/proper/collections/trunk/data/test/MultiValueMap.fullCollection.version3.3.obj (with props) Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java Added: commons/proper/collections/trunk/data/test/MultiValueMap.emptyCollection.version3.3.obj URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/data/test/MultiValueMap.emptyCollection.version3.3.obj?rev=656960&view=auto ============================================================================== Binary file - no diff available. Propchange: commons/proper/collections/trunk/data/test/MultiValueMap.emptyCollection.version3.3.obj ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: commons/proper/collections/trunk/data/test/MultiValueMap.fullCollection.version3.3.obj URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/data/test/MultiValueMap.fullCollection.version3.3.obj?rev=656960&view=auto ============================================================================== Binary file - no diff available. Propchange: commons/proper/collections/trunk/data/test/MultiValueMap.fullCollection.version3.3.obj ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java?rev=656960&r1=656959&r2=656960&view=diff ============================================================================== --- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java (original) +++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/MultiValueMap.java Fri May 16 01:09:42 2008 @@ -16,6 +16,11 @@ */ package org.apache.commons.collections.map; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + import java.util.AbstractCollection; import java.util.ArrayList; import java.util.Collection; @@ -61,7 +66,10 @@ * @version $Revision$ $Date$ * @since Commons Collections 3.2 */ -public class MultiValueMap extends AbstractMapDecorator implements MultiMap { +public class MultiValueMap extends AbstractMapDecorator implements MultiMap, Serializable { + + /** Serialization version */ + private static final long serialVersionUID = -2214159910087182007L; /** The factory for creating value collections. */ private final Factory collectionFactory; @@ -126,6 +134,32 @@ //----------------------------------------------------------------------- /** + * Write the map out using a custom routine. + * + * @param out the output stream + * @throws IOException + * @since Commons Collections 3.3 + */ + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + out.writeObject(map); + } + + /** + * Read the map in using a custom routine. + * + * @param in the input stream + * @throws IOException + * @throws ClassNotFoundException + * @since Commons Collections 3.3 + */ + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + map = (Map) in.readObject(); + } + + //----------------------------------------------------------------------- + /** * Clear the map. */ public void clear() { @@ -424,7 +458,7 @@ /** * Inner class that provides a simple reflection factory. */ - private static class ReflectionFactory implements Factory { + private static class ReflectionFactory implements Factory, Serializable { private final Class clazz; public ReflectionFactory(Class clazz) { Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java?rev=656960&r1=656959&r2=656960&view=diff ============================================================================== --- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java (original) +++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiValueMap.java Fri May 16 01:09:42 2008 @@ -32,6 +32,8 @@ import org.apache.commons.collections.IteratorUtils; import org.apache.commons.collections.MultiMap; +import org.apache.commons.collections.AbstractTestObject; + /** * TestMultiValueMap. * @@ -39,7 +41,7 @@ * @author Stephen Colebourne * @since Commons Collections 3.2 */ -public class TestMultiValueMap extends TestCase { +public class TestMultiValueMap extends AbstractTestObject { public TestMultiValueMap(String testName) { super(testName); @@ -353,4 +355,55 @@ assertEquals(new MultiValueMap(), map); } + //----------------------------------------------------------------------- + // Manual serialization testing as this class cannot easily + // extend the AbstractTestMap + //----------------------------------------------------------------------- + + public String getCompatibilityVersion() { + return "3.3"; + } + + public Object makeObject() { + Map m = makeEmptyMap(); + m.put("a", "1"); + m.put("a", "1b"); + m.put("b", "2"); + m.put("c", "3"); + m.put("c", "3b"); + m.put("d", "4"); + return m; + } + + private Map makeEmptyMap() { + return new MultiValueMap(); + } + +// public void testCreate() throws Exception { +// writeExternalFormToDisk( +// (java.io.Serializable) makeEmptyMap(), +// "/tmp/MultiValueMap.emptyCollection.version3.3.obj"); +// +// writeExternalFormToDisk( +// (java.io.Serializable) makeObject(), +// "/tmp/MultiValueMap.fullCollection.version3.3.obj"); +// } + + public void testEmptyMapCompatibility() throws Exception { + Map map = makeEmptyMap(); + Map map2 = (Map) readExternalFormFromDisk(getCanonicalEmptyCollectionName(map)); + assertEquals("Map is empty", 0, map2.size()); + } + public void testFullMapCompatibility() throws Exception { + Map map = (Map) makeObject(); + Map map2 = (Map) readExternalFormFromDisk(getCanonicalFullCollectionName(map)); + assertEquals("Map is the right size", map.size(), map2.size()); + for (Iterator it = map.keySet().iterator(); it.hasNext();) { + Object key = it.next(); + assertEquals( "Map had inequal elements", map.get(key), map2.get(key) ); + map2.remove(key); + } + assertEquals("Map had extra values", 0, map2.size()); + } + }