Fix so putAll works with an empty map

bug 34686, reported by Marc Lottman

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@169097 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2005-05-07 17:13:40 +00:00
parent 4b460152a1
commit 37b6aedcd0
2 changed files with 28 additions and 2 deletions

View File

@ -150,6 +150,9 @@ public class TransformedMap
* @throws the transformed object
*/
protected Map transformMap(Map map) {
if (map.isEmpty()) {
return map;
}
Map result = new LinkedMap(map.size());
for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();

View File

@ -907,23 +907,46 @@ public abstract class AbstractTestMap extends AbstractTestObject {
return;
}
// check putAll OK adding empty map to empty map
resetEmpty();
assertEquals(0, map.size());
map.putAll(new HashMap());
assertEquals(0, map.size());
// check putAll OK adding empty map to non-empty map
resetFull();
int size = map.size();
map.putAll(new HashMap());
assertEquals(size, map.size());
// check putAll OK adding non-empty map to empty map
resetEmpty();
Map m2 = makeFullMap();
map.putAll(m2);
confirmed.putAll(m2);
verify();
// check putAll OK adding non-empty JDK map to empty map
resetEmpty();
m2 = makeConfirmedMap();
Object[] keys = getSampleKeys();
Object[] values = getSampleValues();
for(int i = 0; i < keys.length; i++) {
m2.put(keys[i], values[i]);
}
map.putAll(m2);
confirmed.putAll(m2);
verify();
// check putAll OK adding non-empty JDK map to non-empty map
resetEmpty();
m2 = makeConfirmedMap();
map.put(keys[0], values[0]);
confirmed.put(keys[0], values[0]);
verify();
for(int i = 1; i < keys.length; i++) {
m2.put(keys[i], values[i]);
}
map.putAll(m2);
confirmed.putAll(m2);
verify();