From 33ac6121a5f3925d761586e7c135561805fe465c Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Wed, 13 Mar 2002 04:36:18 +0000 Subject: [PATCH] Fixed bugs where methods failed when there is no bean set for the bean map. Fixed entrySet() to return a set containing Map.Entry objects with readable properties as keys. This fixes the test case error, and a couple of the test case failures (and uncovers a couple more test case failures) Fixed clone method to allow subclasses to clone properly. This requires a non-backwards compatible change where the clone method now declares it throws CloneNotSupportedException. See: http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html Seeing how BeanMap never directly implemented Cloneable anyway, and this is for a major revision, I don't see this changing being much of a problem. Since clone() declares it throws CloneNotSupportedException, that exception is now used to indicate a problem when attempting to clone (rather than UnsupportedOperationException, or other RuntimeException). Added a small test for testing BeanMap clone. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130638 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/collections/BeanMap.java | 125 +++++++++++++++--- .../commons/collections/TestBeanMap.java | 24 +++- 2 files changed, 129 insertions(+), 20 deletions(-) diff --git a/src/java/org/apache/commons/collections/BeanMap.java b/src/java/org/apache/commons/collections/BeanMap.java index 3db62b781..0bd29ac56 100644 --- a/src/java/org/apache/commons/collections/BeanMap.java +++ b/src/java/org/apache/commons/collections/BeanMap.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BeanMap.java,v 1.5 2002/03/13 04:15:49 mas Exp $ - * $Revision: 1.5 $ - * $Date: 2002/03/13 04:15:49 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BeanMap.java,v 1.6 2002/03/13 04:36:18 mas Exp $ + * $Revision: 1.6 $ + * $Date: 2002/03/13 04:36:18 $ * * ==================================================================== * @@ -68,8 +68,10 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.AbstractMap; +import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -85,13 +87,13 @@ import java.util.Set; * @author James Strachan */ -public class BeanMap extends AbstractMap { +public class BeanMap extends AbstractMap implements Cloneable { - private Object bean; + private transient Object bean; - private HashMap readMethods = new HashMap(); - private HashMap writeMethods = new HashMap(); - private HashMap types = new HashMap(); + private transient HashMap readMethods = new HashMap(); + private transient HashMap writeMethods = new HashMap(); + private transient HashMap types = new HashMap(); public static final Object[] NULL_ARGUMENTS = {}; public static HashMap defaultTransformers = new HashMap(); @@ -177,18 +179,77 @@ public class BeanMap extends AbstractMap { // Map interface //------------------------------------------------------------------------- - public Object clone() { + /** + * Clone this bean map using the following process: + * + *