Implement Externalizable in SequencedHashMap

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130555 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Smith 2002-02-22 03:17:40 +00:00
parent 2af7a322ef
commit 6bb40f4086
1 changed files with 34 additions and 4 deletions

View File

@ -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 <a href="mailto:dlr@collab.net">Daniel Rall</a>
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
*/
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;
}