From 6bb40f40862ab8fbeb2ba1de32e1e202072dc5bb Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 22 Feb 2002 03:17:40 +0000 Subject: [PATCH] Implement Externalizable in SequencedHashMap git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130555 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/collections/SequencedHashMap.java | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/commons/collections/SequencedHashMap.java b/src/java/org/apache/commons/collections/SequencedHashMap.java index 41cf6158f..4a377be93 100644 --- a/src/java/org/apache/commons/collections/SequencedHashMap.java +++ b/src/java/org/apache/commons/collections/SequencedHashMap.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SequencedHashMap.java,v 1.6 2002/02/22 02:37:56 mas Exp $ - * $Revision: 1.6 $ - * $Date: 2002/02/22 02:37:56 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SequencedHashMap.java,v 1.7 2002/02/22 03:17:40 mas Exp $ + * $Revision: 1.7 $ + * $Date: 2002/02/22 03:17:40 $ * * ==================================================================== * @@ -60,6 +60,11 @@ */ package org.apache.commons.collections; +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -91,7 +96,7 @@ import java.util.NoSuchElementException; * @author Daniel Rall * @author Henning P. Schmiedehausen */ -public class SequencedHashMap implements Map, Cloneable { +public class SequencedHashMap implements Map, Cloneable, Externalizable { /** * {@link java.util.Map.Entry} that doubles as a node in the linked list @@ -879,4 +884,29 @@ public class SequencedHashMap implements Map, Cloneable { return remove(get(index)); } + // per Externalizable.readExternal(ObjectInput) + public void readExternal( ObjectInput in ) + throws IOException, ClassNotFoundException + { + int size = in.readInt(); + for(int i = 0; i < size; i++) { + Object key = in.readObject(); + Object value = in.readObject(); + put(key, value); + } + } + + // per Externalizable.writeExternal(ObjectOutput) + public void writeExternal( ObjectOutput out ) throws IOException { + out.writeInt(size()); + for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) { + out.writeObject(pos.getKey()); + out.writeObject(pos.getValue()); + } + } + + // add a serial version uid, so that if we change things in the future + // without changing the format, we can still deserialize properly. + private static final long serialVersionUID = 3380552487888102930L; + }