diff --git a/data/test/ReferenceMap.emptyCollection.version3.1.obj b/data/test/ReferenceMap.emptyCollection.version3.1.obj new file mode 100644 index 000000000..13e2efc99 Binary files /dev/null and b/data/test/ReferenceMap.emptyCollection.version3.1.obj differ diff --git a/data/test/ReferenceMap.fullCollection.version3.1.obj b/data/test/ReferenceMap.fullCollection.version3.1.obj new file mode 100644 index 000000000..d0824bbcb Binary files /dev/null and b/data/test/ReferenceMap.fullCollection.version3.1.obj differ diff --git a/src/java/org/apache/commons/collections/map/ReferenceMap.java b/src/java/org/apache/commons/collections/map/ReferenceMap.java index 008120723..e4b66ccd6 100644 --- a/src/java/org/apache/commons/collections/map/ReferenceMap.java +++ b/src/java/org/apache/commons/collections/map/ReferenceMap.java @@ -15,6 +15,10 @@ */ package org.apache.commons.collections.map; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; /** * A Map implementation that allows mappings to be @@ -35,29 +39,37 @@ package org.apache.commons.collections.map; * weak values, or any other combination. The default constructor uses * hard keys and soft values, providing a memory-sensitive cache. *

+ * This map is similar to + * {@link org.apache.commons.collections.map.ReferenceIdentityMap ReferenceIdentityMap}. + * It differs in that keys and values in this class are compared using equals(). + *

* This {@link Map} implementation does not allow null elements. * Attempting to add a null key or value to the map will raise a NullPointerException. *

* This implementation is not synchronized. * You can use {@link java.util.Collections#synchronizedMap} to * provide synchronized access to a ReferenceMap. + * Remember that synchronization will not stop the garbage collecter removing entries. *

* All the available iterators can be reset back to the start by casting to * ResettableIterator and calling reset(). *

- * NOTE: As from Commons Collections 3.1 this map extends AbstractHashedMap + * NOTE: As from Commons Collections 3.1 this map extends AbstractReferenceMap * (previously it extended AbstractMap). As a result, the implementation is now * extensible and provides a MapIterator. * * @see java.lang.ref.Reference * * @since Commons Collections 3.0 (previously in main package v2.1) - * @version $Revision: 1.12 $ $Date: 2004/04/09 22:18:18 $ + * @version $Revision: 1.13 $ $Date: 2004/04/27 21:35:23 $ * * @author Paul Jack * @author Stephen Colebourne */ -public class ReferenceMap extends AbstractReferenceMap { +public class ReferenceMap extends AbstractReferenceMap implements Serializable { + + /** Serialization version */ + private static final long serialVersionUID = 1555089888138299607L; /** * Constructs a new ReferenceMap that will @@ -130,4 +142,21 @@ public class ReferenceMap extends AbstractReferenceMap { super(keyType, valueType, capacity, loadFactor, purgeValues); } + //----------------------------------------------------------------------- + /** + * Write the map out using a custom routine. + */ + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + doWriteObject(out); + } + + /** + * Read the map in using a custom routine. + */ + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + doReadObject(in); + } + } diff --git a/src/test/org/apache/commons/collections/map/TestReferenceMap.java b/src/test/org/apache/commons/collections/map/TestReferenceMap.java index 2685dd766..73c7d37bd 100644 --- a/src/test/org/apache/commons/collections/map/TestReferenceMap.java +++ b/src/test/org/apache/commons/collections/map/TestReferenceMap.java @@ -25,7 +25,7 @@ import org.apache.commons.collections.BulkTest; /** * Tests for ReferenceMap. * - * @version $Revision: 1.5 $ $Date: 2004/04/09 22:18:17 $ + * @version $Revision: 1.6 $ $Date: 2004/04/27 21:35:23 $ * * @author Paul Jack */ @@ -184,7 +184,7 @@ public class TestReferenceMap extends AbstractTestIterableMap { public String getCompatibilityVersion() { - return "2.1"; // previously in main package + return "3.1"; } /** Tests whether purge values setting works */