aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/util/Hashtable.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/util/Hashtable.java')
-rw-r--r--libjava/java/util/Hashtable.java52
1 files changed, 27 insertions, 25 deletions
diff --git a/libjava/java/util/Hashtable.java b/libjava/java/util/Hashtable.java
index a94143b8f09..698871b5124 100644
--- a/libjava/java/util/Hashtable.java
+++ b/libjava/java/util/Hashtable.java
@@ -234,7 +234,7 @@ public class Hashtable extends Dictionary
public Hashtable(Map m)
{
this(Math.max(m.size() * 2, DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR);
- putAllInternal(m);
+ putAll(m);
}
/**
@@ -333,7 +333,22 @@ public class Hashtable extends Dictionary
*/
public synchronized boolean contains(Object value)
{
- return containsValue(value);
+ for (int i = buckets.length - 1; i >= 0; i--)
+ {
+ HashEntry e = buckets[i];
+ while (e != null)
+ {
+ if (value.equals(e.value))
+ return true;
+ e = e.next;
+ }
+ }
+
+ // Must throw on null argument even if the table is empty
+ if (value == null)
+ throw new NullPointerException();
+
+ return false;
}
/**
@@ -350,22 +365,9 @@ public class Hashtable extends Dictionary
*/
public boolean containsValue(Object value)
{
- for (int i = buckets.length - 1; i >= 0; i--)
- {
- HashEntry e = buckets[i];
- while (e != null)
- {
- if (value.equals(e.value))
- return true;
- e = e.next;
- }
- }
-
- // Must throw on null argument even if the table is empty
- if (value == null)
- throw new NullPointerException();
-
- return false;
+ // Delegate to older method to make sure code overriding it continues
+ // to work.
+ return contains(value);
}
/**
@@ -510,7 +512,7 @@ public class Hashtable extends Dictionary
{
Iterator itr = m.entrySet().iterator();
- for (int msize = m.size(); msize > 0; msize--)
+ while (itr.hasNext())
{
Map.Entry e = (Map.Entry) itr.next();
// Optimize in case the Entry is one of our own.
@@ -850,20 +852,20 @@ public class Hashtable extends Dictionary
}
/**
- * A simplified, more efficient internal implementation of putAll(). The
- * Map constructor and clone() should not call putAll or put, in order to
- * be compatible with the JDK implementation with respect to subclasses.
+ * A simplified, more efficient internal implementation of putAll(). clone()
+ * should not call putAll or put, in order to be compatible with the JDK
+ * implementation with respect to subclasses.
*
* @param m the map to initialize this from
*/
void putAllInternal(Map m)
{
Iterator itr = m.entrySet().iterator();
- int msize = m.size();
- this.size = msize;
+ size = 0;
- for (; msize > 0; msize--)
+ while (itr.hasNext())
{
+ size++;
Map.Entry e = (Map.Entry) itr.next();
Object key = e.getKey();
int idx = hash(key);