fix return value of HashMap.put()

This commit is contained in:
Joel Dice 2007-10-13 15:46:20 -06:00
parent 96c3b2b6a7
commit 64313aa243

View File

@ -136,7 +136,6 @@ public class HashMap<K, V> implements Map<K, V> {
if (c == null) {
insert(helper.make(key, value, null));
} else {
V old = c.getValue();
c.setValue(value);
}
return c;
@ -180,8 +179,15 @@ public class HashMap<K, V> implements Map<K, V> {
}
public V put(K key, V value) {
Cell<K, V> c = putCell(key, value);
return (c == null ? null : c.getValue());
Cell<K, V> c = find(key);
if (c == null) {
insert(helper.make(key, value, null));
return null;
} else {
V old = c.getValue();
c.setValue(value);
return old;
}
}
public void putAll(Map<? extends K,? extends V> elts) {