Commit 0dccd146 by Mark Wielaard Committed by Mark Wielaard

Hashtable.java (contains): Remove NullPointer check.

        * java/util/Hashtable.java (contains): Remove NullPointer check.
        (containsValue): Add NullPointer check.
        (remove): Always throw NullPointerException when key is null.

From-SVN: r51994
parent 3b1d8b3b
2002-04-07 Mark Wielaard <mark@klomp.org>
* java/util/Hashtable.java (contains): Remove NullPointer check.
(containsValue): Add NullPointer check.
(remove): Always throw NullPointerException when key
is null.
2002-04-07 Adam King <aking@dreammechanics.com> 2002-04-07 Adam King <aking@dreammechanics.com>
* java/lang/natSystem.cc (init_properties): Call new function * java/lang/natSystem.cc (init_properties): Call new function
...@@ -25,7 +32,7 @@ ...@@ -25,7 +32,7 @@
2002-04-05 Mark Wielaard <mark@klomp.org> 2002-04-05 Mark Wielaard <mark@klomp.org>
* java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do * java/util/ArrayList.java (removeRange): If toIndex == fromIndex do
nothing, if toIndex < fromIndex throw IndexOutIfBoundsException. nothing, if toIndex < fromIndex throw IndexOutIfBoundsException.
2002-04-05 Adam Megacz <adam@xwt.org> 2002-04-05 Adam Megacz <adam@xwt.org>
......
...@@ -322,10 +322,6 @@ public class Hashtable extends Dictionary ...@@ -322,10 +322,6 @@ public class Hashtable extends Dictionary
* <code>containsValue()</code>, and is O(n). * <code>containsValue()</code>, and is O(n).
* <p> * <p>
* *
* Note: this is one of the <i>old</i> Hashtable methods which does
* not like null values; it throws NullPointerException if the
* supplied parameter is null.
*
* @param value the value to search for in this Hashtable * @param value the value to search for in this Hashtable
* @return true if at least one key maps to the value * @return true if at least one key maps to the value
* @throws NullPointerException if <code>value</code> is null * @throws NullPointerException if <code>value</code> is null
...@@ -334,19 +330,17 @@ public class Hashtable extends Dictionary ...@@ -334,19 +330,17 @@ public class Hashtable extends Dictionary
*/ */
public synchronized boolean contains(Object value) public synchronized boolean contains(Object value)
{ {
// Check if value is null.
if (value == null)
throw new NullPointerException();
return containsValue(value); return containsValue(value);
} }
/** /**
* Returns true if this Hashtable contains a value <code>o</code>, such that * Returns true if this Hashtable contains a value <code>o</code>, such that
* <code>o.equals(value)</code>. This is the new API for the old * <code>o.equals(value)</code>. This is the new API for the old
* <code>contains()</code>, except that it is forgiving of null. * <code>contains()</code>.
* *
* @param value the value to search for in this Hashtable * @param value the value to search for in this Hashtable
* @return true if at least one key maps to the value * @return true if at least one key maps to the value
* @throws NullPointerException if <code>value</code> is null
* @see #contains(Object) * @see #contains(Object)
* @see #containsKey(Object) * @see #containsKey(Object)
* @since 1.2 * @since 1.2
...@@ -358,11 +352,16 @@ public class Hashtable extends Dictionary ...@@ -358,11 +352,16 @@ public class Hashtable extends Dictionary
HashEntry e = buckets[i]; HashEntry e = buckets[i];
while (e != null) while (e != null)
{ {
if (AbstractCollection.equals(value, e.value)) if (value.equals(e.value))
return true; return true;
e = e.next; e = e.next;
} }
} }
// Must throw on null argument even if the table is empty
if (value == null)
throw new NullPointerException();
return false; return false;
} }
...@@ -468,17 +467,12 @@ public class Hashtable extends Dictionary ...@@ -468,17 +467,12 @@ public class Hashtable extends Dictionary
* Removes from the table and returns the value which is mapped by the * Removes from the table and returns the value which is mapped by the
* supplied key. If the key maps to nothing, then the table remains * supplied key. If the key maps to nothing, then the table remains
* unchanged, and <code>null</code> is returned. * unchanged, and <code>null</code> is returned.
* <b>NOTE:</b>Map.remove and Dictionary.remove disagree whether null
* is a valid parameter; at the moment, this implementation obeys Map.remove,
* and silently ignores null.
* *
* @param key the key used to locate the value to remove * @param key the key used to locate the value to remove
* @return whatever the key mapped to, if present * @return whatever the key mapped to, if present
*/ */
public synchronized Object remove(Object key) public synchronized Object remove(Object key)
{ {
if (key == null)
return null;
int idx = hash(key); int idx = hash(key);
HashEntry e = buckets[idx]; HashEntry e = buckets[idx];
HashEntry last = null; HashEntry last = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment