scolebourne 2004/04/27 14:35:23
Modified: collections/src/test/org/apache/commons/collections/map
TestReferenceMap.java
collections/src/java/org/apache/commons/collections/map
ReferenceMap.java
Added: collections/data/test
ReferenceMap.emptyCollection.version3.1.obj
ReferenceMap.fullCollection.version3.1.obj
Log:
Make ReferenceMap serializable
Revision Changes Path
1.6 +2 -2
jakarta-commons/collections/src/test/org/apache/commons/collections/map/TestReferenceMap.java
Index: TestReferenceMap.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/map/TestReferenceMap.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestReferenceMap.java 9 Apr 2004 22:18:17 -0000 1.5
+++ TestReferenceMap.java 27 Apr 2004 21:35:23 -0000 1.6
@@ -184,7 +184,7 @@
public String getCompatibilityVersion() {
- return "2.1"; // previously in main package
+ return "3.1";
}
/** Tests whether purge values setting works */
1.1
jakarta-commons/collections/data/test/ReferenceMap.emptyCollection.version3.1.obj
<<Binary file>>
1.1
jakarta-commons/collections/data/test/ReferenceMap.fullCollection.version3.1.obj
<<Binary file>>
1.13 +32 -3
jakarta-commons/collections/src/java/org/apache/commons/collections/map/ReferenceMap.java
Index: ReferenceMap.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/ReferenceMap.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ReferenceMap.java 9 Apr 2004 22:18:18 -0000 1.12
+++ ReferenceMap.java 27 Apr 2004 21:35:23 -0000 1.13
@@ -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 <code>Map</code> implementation that allows mappings to be
@@ -35,17 +39,22 @@
* weak values, or any other combination. The default constructor uses
* hard keys and soft values, providing a memory-sensitive cache.
* <p>
+ * This map is similar to
+ * [EMAIL PROTECTED] org.apache.commons.collections.map.ReferenceIdentityMap
ReferenceIdentityMap}.
+ * It differs in that keys and values in this class are compared using
<code>equals()</code>.
+ * <p>
* This [EMAIL PROTECTED] Map} implementation does <i>not</i> allow null elements.
* Attempting to add a null key or value to the map will raise a
<code>NullPointerException</code>.
* <p>
* This implementation is not synchronized.
* You can use [EMAIL PROTECTED] java.util.Collections#synchronizedMap} to
* provide synchronized access to a <code>ReferenceMap</code>.
+ * Remember that synchronization will not stop the garbage collecter removing
entries.
* <p>
* All the available iterators can be reset back to the start by casting to
* <code>ResettableIterator</code> and calling <code>reset()</code>.
* <p>
- * NOTE: As from Commons Collections 3.1 this map extends
<code>AbstractHashedMap</code>
+ * NOTE: As from Commons Collections 3.1 this map extends
<code>AbstractReferenceMap</code>
* (previously it extended AbstractMap). As a result, the implementation is now
* extensible and provides a <code>MapIterator</code>.
*
@@ -57,7 +66,10 @@
* @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 <code>ReferenceMap</code> that will
@@ -128,6 +140,23 @@
public ReferenceMap(int keyType, int valueType, int capacity,
float loadFactor, boolean purgeValues) {
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);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]