Make DualHashBidiMap serialiizable
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131267 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2f1df4d36c
commit
c676de25d3
|
@ -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
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -73,7 +73,7 @@ import org.apache.commons.collections.decorators.AbstractMapEntryDecorator;
|
||||||
* <code>createMap</code> method.
|
* <code>createMap</code> method.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @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 Matthew Hawthorne
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
|
@ -99,22 +99,19 @@ public abstract class AbstractDualBidiMap implements BidiMap {
|
||||||
protected transient Set entrySet = null;
|
protected transient Set entrySet = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty map.
|
* Creates an empty map, initialised by <code>createMap</code>.
|
||||||
* <p>
|
* <p>
|
||||||
* The maps passed in are not validated, so subclasses need to ensure
|
* The map array must be populated by the subclass.
|
||||||
* that they are non-null, empty and compatible.
|
|
||||||
*
|
|
||||||
* @param normalMap the normal direction map
|
|
||||||
* @param reverseMap the reverse direction map
|
|
||||||
*/
|
*/
|
||||||
protected AbstractDualBidiMap(Map normalMap, Map reverseMap) {
|
protected AbstractDualBidiMap() {
|
||||||
super();
|
super();
|
||||||
maps[0] = normalMap;
|
maps[0] = createMap();
|
||||||
maps[1] = reverseMap;
|
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 normalMap the normal direction map
|
||||||
* @param reverseMap the reverse direction map
|
* @param reverseMap the reverse direction map
|
||||||
|
@ -126,7 +123,16 @@ public abstract class AbstractDualBidiMap implements BidiMap {
|
||||||
maps[1] = reverseMap;
|
maps[1] = reverseMap;
|
||||||
this.inverseBidiMap = inverseBidiMap;
|
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.
|
* Creates a new instance of the subclass.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -57,6 +57,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.collections;
|
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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -64,18 +68,21 @@ import java.util.Map;
|
||||||
* Implementation of <code>BidiMap</code> that uses two <code>HashMap</code> instances.
|
* Implementation of <code>BidiMap</code> that uses two <code>HashMap</code> instances.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @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 Matthew Hawthorne
|
||||||
* @author Stephen Colebourne
|
* @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>
|
* Creates an empty <code>HashBidiMap</code>
|
||||||
*/
|
*/
|
||||||
public DualHashBidiMap() {
|
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
|
* @param map the map whose mappings are to be placed in this map
|
||||||
*/
|
*/
|
||||||
public DualHashBidiMap(Map map) {
|
public DualHashBidiMap(Map map) {
|
||||||
super(new HashMap(), new HashMap());
|
super();
|
||||||
putAll(map);
|
putAll(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a <code>HashBidiMap</code> that decorates the specified maps.
|
* Constructs a <code>HashBidiMap</code> that decorates the specified maps.
|
||||||
*
|
*
|
||||||
|
@ -99,7 +106,16 @@ public class DualHashBidiMap extends AbstractDualBidiMap {
|
||||||
protected DualHashBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
|
protected DualHashBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
|
||||||
super(normalMap, reverseMap, 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.
|
* Creates a new instance of this object.
|
||||||
*
|
*
|
||||||
|
@ -112,5 +128,17 @@ public class DualHashBidiMap extends AbstractDualBidiMap {
|
||||||
return new DualHashBidiMap(normalMap, reverseMap, inverseMap);
|
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,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
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -63,7 +63,7 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* JUnit tests.
|
* 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
|
* @author Matthew Hawthorne
|
||||||
*/
|
*/
|
||||||
|
@ -132,6 +132,13 @@ public abstract class TestBidiMap extends AbstractTestMap {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override as DualHashBidiMap didn't exist until version 3.
|
||||||
|
*/
|
||||||
|
protected String getCompatibilityVersion() {
|
||||||
|
return "3";
|
||||||
|
}
|
||||||
|
|
||||||
// BidiPut
|
// BidiPut
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testBidiPut() {
|
public void testBidiPut() {
|
||||||
|
@ -338,10 +345,29 @@ public abstract class TestBidiMap extends AbstractTestMap {
|
||||||
protected BidiMap makeEmptyBidiMap() {
|
protected BidiMap makeEmptyBidiMap() {
|
||||||
return main.makeEmptyBidiMap().inverseBidiMap();
|
return main.makeEmptyBidiMap().inverseBidiMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BidiMap makeFullBidiMap() {
|
protected BidiMap makeFullBidiMap() {
|
||||||
return main.makeFullBidiMap().inverseBidiMap();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue