Make ReferenceMap serializable

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131682 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2004-04-27 21:35:23 +00:00
parent c748ff1b56
commit 6f10e417e1
4 changed files with 34 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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,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.
* <p>
* 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 <code>equals()</code>.
* <p>
* This {@link 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 {@link 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>.
*
* @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 <code>ReferenceMap</code> 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);
}
}

View File

@ -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 */