Make unmodifiable maps Serializable [18815]

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131637 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2004-04-09 10:46:32 +00:00
parent ac6c18f090
commit 3c1749c51b
9 changed files with 117 additions and 17 deletions

View File

@ -15,6 +15,10 @@
*/ */
package org.apache.commons.collections.map; 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.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -30,14 +34,20 @@ import org.apache.commons.collections.set.UnmodifiableSet;
/** /**
* Decorates another <code>OrderedMap</code> to ensure it can't be altered. * Decorates another <code>OrderedMap</code> to ensure it can't be altered.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.7 $ $Date: 2004/02/18 01:13:19 $ * @version $Revision: 1.8 $ $Date: 2004/04/09 10:46:32 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class UnmodifiableOrderedMap public final class UnmodifiableOrderedMap
extends AbstractOrderedMapDecorator implements Unmodifiable { extends AbstractOrderedMapDecorator
implements Unmodifiable, Serializable {
/** Serialization version */
private static final long serialVersionUID = 8136428161720526266L;
/** /**
* Factory method to create an unmodifiable sorted map. * Factory method to create an unmodifiable sorted map.
@ -63,6 +73,32 @@ public final class UnmodifiableOrderedMap
super(map); super(map);
} }
//-----------------------------------------------------------------------
/**
* Write the map out using a custom routine.
*
* @param out the output stream
* @throws IOException
* @since Commons Collections 3.1
*/
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.1
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map) in.readObject();
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public MapIterator mapIterator() { public MapIterator mapIterator() {
MapIterator it = getOrderedMap().mapIterator(); MapIterator it = getOrderedMap().mapIterator();

View File

@ -15,6 +15,10 @@
*/ */
package org.apache.commons.collections.map; 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.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map; import java.util.Map;
@ -27,14 +31,20 @@ import org.apache.commons.collections.set.UnmodifiableSet;
/** /**
* Decorates another <code>SortedMap</code> to ensure it can't be altered. * Decorates another <code>SortedMap</code> to ensure it can't be altered.
* <p>
* This class is Serializable from Commons Collections 3.1.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/02/18 01:13:19 $ * @version $Revision: 1.7 $ $Date: 2004/04/09 10:46:32 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class UnmodifiableSortedMap public final class UnmodifiableSortedMap
extends AbstractSortedMapDecorator implements Unmodifiable { extends AbstractSortedMapDecorator
implements Unmodifiable, Serializable {
/** Serialization version */
private static final long serialVersionUID = 5805344239827376360L;
/** /**
* Factory method to create an unmodifiable sorted map. * Factory method to create an unmodifiable sorted map.
@ -60,6 +70,32 @@ public final class UnmodifiableSortedMap
super(map); super(map);
} }
//-----------------------------------------------------------------------
/**
* Write the map out using a custom routine.
*
* @param out the output stream
* @throws IOException
* @since Commons Collections 3.1
*/
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.1
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map) in.readObject();
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void clear() { public void clear() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@ -28,7 +28,7 @@ import org.apache.commons.collections.Unmodifiable;
* {@link UnmodifiableMap} implementation. * {@link UnmodifiableMap} implementation.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.9 $ $Date: 2004/04/09 10:32:25 $ * @version $Revision: 1.10 $ $Date: 2004/04/09 10:46:32 $
* *
* @author Phil Steitz * @author Phil Steitz
*/ */
@ -91,14 +91,14 @@ public class TestUnmodifiableMap extends AbstractTestIterableMap{
return "3.1"; return "3.1";
} }
public void testCreate() throws Exception { // public void testCreate() throws Exception {
resetEmpty(); // resetEmpty();
writeExternalFormToDisk( // writeExternalFormToDisk(
(java.io.Serializable) map, // (java.io.Serializable) map,
"D:/dev/collections/data/test/UnmodifiableMap.emptyCollection.version3.1.obj"); // "D:/dev/collections/data/test/UnmodifiableMap.emptyCollection.version3.1.obj");
resetFull(); // resetFull();
writeExternalFormToDisk( // writeExternalFormToDisk(
(java.io.Serializable) map, // (java.io.Serializable) map,
"D:/dev/collections/data/test/UnmodifiableMap.fullCollection.version3.1.obj"); // "D:/dev/collections/data/test/UnmodifiableMap.fullCollection.version3.1.obj");
} // }
} }

View File

@ -29,7 +29,7 @@ import org.apache.commons.collections.Unmodifiable;
* {@link UnmodifiableOrderedMap} implementation. * {@link UnmodifiableOrderedMap} implementation.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2004/02/18 01:20:38 $ * @version $Revision: 1.5 $ $Date: 2004/04/09 10:46:32 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -88,4 +88,18 @@ public class TestUnmodifiableOrderedMap extends AbstractTestOrderedMap {
} catch (IllegalArgumentException ex) {} } catch (IllegalArgumentException ex) {}
} }
public String getCompatibilityVersion() {
return "3.1";
}
// public void testCreate() throws Exception {
// resetEmpty();
// writeExternalFormToDisk(
// (java.io.Serializable) map,
// "D:/dev/collections/data/test/UnmodifiableOrderedMap.emptyCollection.version3.1.obj");
// resetFull();
// writeExternalFormToDisk(
// (java.io.Serializable) map,
// "D:/dev/collections/data/test/UnmodifiableOrderedMap.fullCollection.version3.1.obj");
// }
} }

View File

@ -29,7 +29,7 @@ import org.apache.commons.collections.Unmodifiable;
* {@link UnmodifiableSortedMap} implementation. * {@link UnmodifiableSortedMap} implementation.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2004/02/18 01:20:37 $ * @version $Revision: 1.4 $ $Date: 2004/04/09 10:46:32 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -88,4 +88,18 @@ public class TestUnmodifiableSortedMap extends AbstractTestSortedMap {
} catch (IllegalArgumentException ex) {} } catch (IllegalArgumentException ex) {}
} }
public String getCompatibilityVersion() {
return "3.1";
}
// public void testCreate() throws Exception {
// resetEmpty();
// writeExternalFormToDisk(
// (java.io.Serializable) map,
// "D:/dev/collections/data/test/UnmodifiableSortedMap.emptyCollection.version3.1.obj");
// resetFull();
// writeExternalFormToDisk(
// (java.io.Serializable) map,
// "D:/dev/collections/data/test/UnmodifiableSortedMap.fullCollection.version3.1.obj");
// }
} }