diff --git a/classpath/java/util/HashMap.java b/classpath/java/util/HashMap.java index 43ee2e8148..2197f9838d 100644 --- a/classpath/java/util/HashMap.java +++ b/classpath/java/util/HashMap.java @@ -107,7 +107,7 @@ public class HashMap implements Map { array = newArray; } - private Cell find(K key) { + private Cell find(Object key) { if (array != null) { int index = helper.hash(key) & (array.length - 1); for (Cell c = array[index]; c != null; c = c.next()) { @@ -158,20 +158,29 @@ public class HashMap implements Map { return c; } - public boolean containsKey(K key) { + public boolean containsKey(Object key) { return find(key) != null; } - public boolean containsValue(V value) { - return values().contains(value); + public boolean containsValue(Object value) { + if (array != null) { + int index = array.length - 1; + for (Cell c = array[index]; c != null; c = c.next()) { + if (helper.equal(value, c.getValue())) { + return true; + } + } + } + + return false; } - public V get(K key) { + public V get(Object key) { Cell c = find(key); return (c == null ? null : c.getValue()); } - public Cell removeCell(K key) { + public Cell removeCell(Object key) { Cell old = null; if (array != null) { int index = helper.hash(key) & (array.length - 1); @@ -213,8 +222,8 @@ public class HashMap implements Map { } } - public V remove(K key) { - Cell c = removeCell(key); + public V remove(Object key) { + Cell c = removeCell((K)key); return (c == null ? null : c.getValue()); } @@ -314,8 +323,8 @@ public class HashMap implements Map { return HashMap.this.isEmpty(); } - public boolean contains(Entry e) { - return containsKey(e.getKey()); + public boolean contains(Object o) { + return (o instanceof Entry) ? containsKey(((Entry)o).getKey()) : false; } public boolean add(Entry e) { @@ -354,7 +363,7 @@ public class HashMap implements Map { return HashMap.this.isEmpty(); } - public boolean contains(K key) { + public boolean contains(Object key) { return containsKey(key); } @@ -368,7 +377,7 @@ public class HashMap implements Map { return change; } - public boolean remove(K key) { + public boolean remove(Object key) { return removeCell(key) != null; } @@ -395,7 +404,7 @@ public class HashMap implements Map { return HashMap.this.isEmpty(); } - public boolean contains(V value) { + public boolean contains(Object value) { return containsValue(value); }