scolebourne 2003/10/09 13:21:32 Modified: collections/src/test/org/apache/commons/collections TestBidiMap.java collections/src/java/org/apache/commons/collections DualHashBidiMap.java AbstractDualBidiMap.java Log: Make DualHashBidiMap serialiizable Revision Changes Path 1.7 +29 -3 jakarta-commons/collections/src/test/org/apache/commons/collections/TestBidiMap.java Index: TestBidiMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBidiMap.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- TestBidiMap.java 7 Oct 2003 22:20:57 -0000 1.6 +++ TestBidiMap.java 9 Oct 2003 20:21:32 -0000 1.7 @@ -132,6 +132,13 @@ return false; } + /** + * Override as DualHashBidiMap didn't exist until version 3. + */ + protected String getCompatibilityVersion() { + return "3"; + } + // BidiPut //----------------------------------------------------------------------- public void testBidiPut() { @@ -338,10 +345,29 @@ 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(); + } + } } 1.2 +35 -7 jakarta-commons/collections/src/java/org/apache/commons/collections/DualHashBidiMap.java Index: DualHashBidiMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/DualHashBidiMap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DualHashBidiMap.java 6 Oct 2003 23:47:17 -0000 1.1 +++ DualHashBidiMap.java 9 Oct 2003 20:21:32 -0000 1.2 @@ -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; @@ -69,13 +73,16 @@ * @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 <code>HashBidiMap</code> */ public DualHashBidiMap() { - super(new HashMap(), new HashMap()); + super(); } /** @@ -85,10 +92,10 @@ * @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 <code>HashBidiMap</code> that decorates the specified maps. * @@ -99,7 +106,16 @@ 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 @@ 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); + } } 1.2 +19 -13 jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractDualBidiMap.java Index: AbstractDualBidiMap.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractDualBidiMap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractDualBidiMap.java 6 Oct 2003 23:47:17 -0000 1.1 +++ AbstractDualBidiMap.java 9 Oct 2003 20:21:32 -0000 1.2 @@ -99,22 +99,19 @@ protected transient Set entrySet = null; /** - * Creates an empty map. + * Creates an empty map, initialised by <code>createMap</code>. * <p> - * 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 <code>createBidiMap</code> implementation. * * @param normalMap the normal direction map * @param reverseMap the reverse direction map @@ -126,7 +123,16 @@ maps[1] = reverseMap; this.inverseBidiMap = inverseBidiMap; } - + + /** + * Creates a new instance of the map used by the subclass to store data. + * <p> + * 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. *
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]