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:
parent
4b460152a1
commit
37b6aedcd0
|
@ -150,6 +150,9 @@ public class TransformedMap
|
||||||
* @throws the transformed object
|
* @throws the transformed object
|
||||||
*/
|
*/
|
||||||
protected Map transformMap(Map map) {
|
protected Map transformMap(Map map) {
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
Map result = new LinkedMap(map.size());
|
Map result = new LinkedMap(map.size());
|
||||||
for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
|
for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
|
||||||
Map.Entry entry = (Map.Entry) it.next();
|
Map.Entry entry = (Map.Entry) it.next();
|
||||||
|
|
|
@ -907,23 +907,46 @@ public abstract class AbstractTestMap extends AbstractTestObject {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check putAll OK adding empty map to empty map
|
||||||
resetEmpty();
|
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 m2 = makeFullMap();
|
||||||
|
|
||||||
map.putAll(m2);
|
map.putAll(m2);
|
||||||
confirmed.putAll(m2);
|
confirmed.putAll(m2);
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
|
// check putAll OK adding non-empty JDK map to empty map
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
|
|
||||||
m2 = makeConfirmedMap();
|
m2 = makeConfirmedMap();
|
||||||
Object[] keys = getSampleKeys();
|
Object[] keys = getSampleKeys();
|
||||||
Object[] values = getSampleValues();
|
Object[] values = getSampleValues();
|
||||||
for(int i = 0; i < keys.length; i++) {
|
for(int i = 0; i < keys.length; i++) {
|
||||||
m2.put(keys[i], values[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);
|
map.putAll(m2);
|
||||||
confirmed.putAll(m2);
|
confirmed.putAll(m2);
|
||||||
verify();
|
verify();
|
||||||
|
|
Loading…
Reference in New Issue