diff --git a/classpath/java/util/Collection.java b/classpath/java/util/Collection.java index cfde456aab..c2d68500c7 100644 --- a/classpath/java/util/Collection.java +++ b/classpath/java/util/Collection.java @@ -15,7 +15,7 @@ public interface Collection extends Iterable { public boolean isEmpty(); - public boolean contains(T element); + public boolean contains(Object element); public boolean add(T element); diff --git a/classpath/java/util/HashMap.java b/classpath/java/util/HashMap.java index 913f58b696..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()) { @@ -159,19 +159,28 @@ public class HashMap implements Map { } public boolean containsKey(Object key) { - return find((K)key) != null; + return find(key) != null; } public boolean containsValue(Object value) { - return values().contains((V)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); } diff --git a/classpath/java/util/Map.java b/classpath/java/util/Map.java index bdb02e52c4..47edee351e 100644 --- a/classpath/java/util/Map.java +++ b/classpath/java/util/Map.java @@ -15,17 +15,17 @@ public interface Map { public int size(); - public boolean containsKey(Object key); + public boolean containsKey(Object obj); - public boolean containsValue(Object value); + public boolean containsValue(Object obj); - public V get(K key); + public V get(Object key); public V put(K key, V value); public void putAll(Map elts); - public V remove(K key); + public V remove(Object key); public void clear();