diff --git a/src/java/org/apache/commons/collections/AbstractDualBidiMap.java b/src/java/org/apache/commons/collections/AbstractDualBidiMap.java
index a8dfdd6d0..85b520554 100644
--- a/src/java/org/apache/commons/collections/AbstractDualBidiMap.java
+++ b/src/java/org/apache/commons/collections/AbstractDualBidiMap.java
@@ -1,5 +1,5 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/AbstractDualBidiMap.java,v 1.1 2003/10/06 23:47:17 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/AbstractDualBidiMap.java,v 1.2 2003/10/09 20:21:32 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -73,7 +73,7 @@ import org.apache.commons.collections.decorators.AbstractMapEntryDecorator;
* createMap
method.
*
* @since Commons Collections 3.0
- * @version $Id: AbstractDualBidiMap.java,v 1.1 2003/10/06 23:47:17 scolebourne Exp $
+ * @version $Id: AbstractDualBidiMap.java,v 1.2 2003/10/09 20:21:32 scolebourne Exp $
*
* @author Matthew Hawthorne
* @author Stephen Colebourne
@@ -99,22 +99,19 @@ public abstract class AbstractDualBidiMap implements BidiMap {
protected transient Set entrySet = null;
/**
- * Creates an empty map.
+ * Creates an empty map, initialised by createMap
.
*
- * The maps passed in are not validated, so subclasses need to ensure
- * that they are non-null, empty and compatible.
- *
- * @param normalMap the normal direction map
- * @param reverseMap the reverse direction map
+ * The map array must be populated by the subclass.
*/
- protected AbstractDualBidiMap(Map normalMap, Map reverseMap) {
+ protected AbstractDualBidiMap() {
super();
- maps[0] = normalMap;
- maps[1] = reverseMap;
+ maps[0] = createMap();
+ maps[1] = createMap();
}
/**
- * Constructs a map that decorates the specified maps.
+ * Constructs a map that decorates the specified maps,
+ * used by the subclass createBidiMap
implementation.
*
* @param normalMap the normal direction map
* @param reverseMap the reverse direction map
@@ -126,7 +123,16 @@ public abstract class AbstractDualBidiMap implements BidiMap {
maps[1] = reverseMap;
this.inverseBidiMap = inverseBidiMap;
}
-
+
+ /**
+ * Creates a new instance of the map used by the subclass to store data.
+ *
+ * Do not change any instance variables from this method.
+ *
+ * @return the map to be used for internal storage
+ */
+ protected abstract Map createMap();
+
/**
* Creates a new instance of the subclass.
*
diff --git a/src/java/org/apache/commons/collections/DualHashBidiMap.java b/src/java/org/apache/commons/collections/DualHashBidiMap.java
index 9338ff61c..58412fb63 100644
--- a/src/java/org/apache/commons/collections/DualHashBidiMap.java
+++ b/src/java/org/apache/commons/collections/DualHashBidiMap.java
@@ -1,5 +1,5 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/DualHashBidiMap.java,v 1.1 2003/10/06 23:47:17 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/DualHashBidiMap.java,v 1.2 2003/10/09 20:21:32 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -57,6 +57,10 @@
*/
package org.apache.commons.collections;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -64,18 +68,21 @@ import java.util.Map;
* Implementation of BidiMap
that uses two HashMap
instances.
*
* @since Commons Collections 3.0
- * @version $Id: DualHashBidiMap.java,v 1.1 2003/10/06 23:47:17 scolebourne Exp $
+ * @version $Id: DualHashBidiMap.java,v 1.2 2003/10/09 20:21:32 scolebourne Exp $
*
* @author Matthew Hawthorne
* @author Stephen Colebourne
*/
-public class DualHashBidiMap extends AbstractDualBidiMap {
+public class DualHashBidiMap extends AbstractDualBidiMap implements Serializable {
+
+ /** Ensure serialization compatability */
+ private static final long serialVersionUID = 721969328361808L;
/**
* Creates an empty HashBidiMap
*/
public DualHashBidiMap() {
- super(new HashMap(), new HashMap());
+ super();
}
/**
@@ -85,10 +92,10 @@ public class DualHashBidiMap extends AbstractDualBidiMap {
* @param map the map whose mappings are to be placed in this map
*/
public DualHashBidiMap(Map map) {
- super(new HashMap(), new HashMap());
+ super();
putAll(map);
}
-
+
/**
* Constructs a HashBidiMap
that decorates the specified maps.
*
@@ -99,7 +106,16 @@ public class DualHashBidiMap extends AbstractDualBidiMap {
protected DualHashBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
super(normalMap, reverseMap, inverseBidiMap);
}
-
+
+ /**
+ * Creates a new instance of the map used by the subclass to store data.
+ *
+ * @return the map to be used for internal storage
+ */
+ protected Map createMap() {
+ return new HashMap();
+ }
+
/**
* Creates a new instance of this object.
*
@@ -112,5 +128,17 @@ public class DualHashBidiMap extends AbstractDualBidiMap {
return new DualHashBidiMap(normalMap, reverseMap, inverseMap);
}
+ // Serialization
+ //-----------------------------------------------------------------------
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+ out.writeObject(maps[0]);
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ Map map = (Map) in.readObject();
+ putAll(map);
+ }
}
diff --git a/src/test/org/apache/commons/collections/TestBidiMap.java b/src/test/org/apache/commons/collections/TestBidiMap.java
index df14ba8f2..c64b98810 100755
--- a/src/test/org/apache/commons/collections/TestBidiMap.java
+++ b/src/test/org/apache/commons/collections/TestBidiMap.java
@@ -1,5 +1,5 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestBidiMap.java,v 1.6 2003/10/07 22:20:57 scolebourne Exp $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestBidiMap.java,v 1.7 2003/10/09 20:21:32 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -63,7 +63,7 @@ import java.util.Map;
/**
* JUnit tests.
*
- * @version $Revision: 1.6 $ $Date: 2003/10/07 22:20:57 $
+ * @version $Revision: 1.7 $ $Date: 2003/10/09 20:21:32 $
*
* @author Matthew Hawthorne
*/
@@ -132,6 +132,13 @@ public abstract class TestBidiMap extends AbstractTestMap {
return false;
}
+ /**
+ * Override as DualHashBidiMap didn't exist until version 3.
+ */
+ protected String getCompatibilityVersion() {
+ return "3";
+ }
+
// BidiPut
//-----------------------------------------------------------------------
public void testBidiPut() {
@@ -338,10 +345,29 @@ public abstract class TestBidiMap extends AbstractTestMap {
protected BidiMap makeEmptyBidiMap() {
return main.makeEmptyBidiMap().inverseBidiMap();
}
-
protected BidiMap makeFullBidiMap() {
return main.makeFullBidiMap().inverseBidiMap();
}
+
+ protected String getCompatibilityVersion() {
+ return main.getCompatibilityVersion();
+ }
+ protected boolean isAllowNullKey() {
+ return main.isAllowNullKey();
+ }
+ protected boolean isAllowNullValue() {
+ return main.isAllowNullValue();
+ }
+ protected boolean isPutAddSupported() {
+ return main.isPutAddSupported();
+ }
+ protected boolean isPutChangeSupported() {
+ return main.isPutChangeSupported();
+ }
+ protected boolean isRemoveSupported() {
+ return main.isRemoveSupported();
+ }
+
}
}