Added BeanMap.putAllWriteable(BeanMap) method, and unit test.

PR:11262


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130756 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
pjack 2002-08-10 02:05:20 +00:00
parent 560c096309
commit 9adb578a23
2 changed files with 33 additions and 6 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/BeanMap.java,v 1.11 2002/06/12 03:59:15 mas Exp $
* $Revision: 1.11 $
* $Date: 2002/06/12 03:59:15 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BeanMap.java,v 1.12 2002/08/10 02:05:20 pjack Exp $
* $Revision: 1.12 $
* $Date: 2002/08/10 02:05:20 $
*
* ====================================================================
*
@ -253,6 +253,23 @@ public class BeanMap extends AbstractMap implements Cloneable {
return newMap;
}
/**
* Puts all of the writeable properties from the given BeanMap into this
* BeanMap. Read-only properties will be ignored.
*
* @param map the BeanMap whose properties to put
*/
public void putAllWriteable(BeanMap map) {
Iterator readableKeys = map.readMethods.keySet().iterator();
while(readableKeys.hasNext()) {
Object key = readableKeys.next();
if(getWriteMethod(key) != null) {
this.put(key, map.get(key));
}
}
}
/**
* This method reinitializes the bean map to have default values for the
* bean's properties. This is accomplished by constructing a new instance

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestBeanMap.java,v 1.6 2002/06/18 05:35:58 mas Exp $
* $Revision: 1.6 $
* $Date: 2002/06/18 05:35:58 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestBeanMap.java,v 1.7 2002/08/10 02:05:20 pjack Exp $
* $Revision: 1.7 $
* $Date: 2002/08/10 02:05:20 $
*
* ====================================================================
*
@ -331,4 +331,14 @@ public class TestBeanMap extends TestMap {
"TestBeanMap.bulkTestMapKeySet.testSimpleSerialization"
};
}
public void testBeanMapPutAllWriteable() {
BeanMap map1 = (BeanMap)makeFullMap();
BeanMap map2 = (BeanMap)makeFullMap();
map2.put("someIntValue", new Integer(0));
map1.putAllWriteable(map2);
assertEquals(map1.get("someIntValue"), new Integer(0));
}
}