1 |
/* Hashtable.java -- a class providing a basic hashtable data structure, |
/* Hashtable.java -- a class providing a basic hashtable data structure, |
2 |
mapping Object --> Object |
mapping Object --> Object |
3 |
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
4 |
|
|
5 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
6 |
|
|
102 |
public class Hashtable extends Dictionary |
public class Hashtable extends Dictionary |
103 |
implements Map, Cloneable, Serializable |
implements Map, Cloneable, Serializable |
104 |
{ |
{ |
105 |
|
// WARNING: Hashtable is a CORE class in the bootstrap cycle. See the |
106 |
|
// comments in vm/reference/java/lang/Runtime for implications of this fact. |
107 |
|
|
108 |
/** Default number of buckets. This is the value the JDK 1.3 uses. Some |
/** Default number of buckets. This is the value the JDK 1.3 uses. Some |
109 |
* early documentation specified this value as 101. That is incorrect. |
* early documentation specified this value as 101. That is incorrect. |
110 |
*/ |
*/ |
179 |
* pair. A Hashtable Entry is identical to a HashMap Entry, except that |
* pair. A Hashtable Entry is identical to a HashMap Entry, except that |
180 |
* `null' is not allowed for keys and values. |
* `null' is not allowed for keys and values. |
181 |
*/ |
*/ |
182 |
private static final class HashEntry extends BasicMapEntry |
private static final class HashEntry extends AbstractMap.BasicMapEntry |
183 |
{ |
{ |
184 |
/** The next entry in the linked list. */ |
/** The next entry in the linked list. */ |
185 |
HashEntry next; |
HashEntry next; |
343 |
* |
* |
344 |
* @param value the value to search for in this Hashtable |
* @param value the value to search for in this Hashtable |
345 |
* @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 |
|
346 |
* @see #contains(Object) |
* @see #contains(Object) |
347 |
* @see #containsKey(Object) |
* @see #containsKey(Object) |
348 |
|
* @throws NullPointerException if <code>value</code> is null |
349 |
* @since 1.2 |
* @since 1.2 |
350 |
*/ |
*/ |
351 |
public boolean containsValue(Object value) |
public boolean containsValue(Object value) |
364 |
// Must throw on null argument even if the table is empty |
// Must throw on null argument even if the table is empty |
365 |
if (value == null) |
if (value == null) |
366 |
throw new NullPointerException(); |
throw new NullPointerException(); |
367 |
|
|
368 |
return false; |
return false; |
369 |
} |
} |
370 |
|
|
514 |
{ |
{ |
515 |
Map.Entry e = (Map.Entry) itr.next(); |
Map.Entry e = (Map.Entry) itr.next(); |
516 |
// Optimize in case the Entry is one of our own. |
// Optimize in case the Entry is one of our own. |
517 |
if (e instanceof BasicMapEntry) |
if (e instanceof AbstractMap.BasicMapEntry) |
518 |
{ |
{ |
519 |
BasicMapEntry entry = (BasicMapEntry) e; |
AbstractMap.BasicMapEntry entry = (AbstractMap.BasicMapEntry) e; |
520 |
put(entry.key, entry.value); |
put(entry.key, entry.value); |
521 |
} |
} |
522 |
else |
else |
815 |
*/ |
*/ |
816 |
private int hash(Object key) |
private int hash(Object key) |
817 |
{ |
{ |
818 |
return Math.abs(key.hashCode() % buckets.length); |
// Note: Inline Math.abs here, for less method overhead, and to avoid |
819 |
|
// a bootstrap dependency, since Math relies on native methods. |
820 |
|
int hash = key.hashCode() % buckets.length; |
821 |
|
return hash < 0 ? -hash : hash; |
822 |
} |
} |
823 |
|
|
824 |
/** |
/** |
1145 |
return type == VALUES ? e.value : e.key; |
return type == VALUES ? e.value : e.key; |
1146 |
} |
} |
1147 |
} // class Enumerator |
} // class Enumerator |
1148 |
} |
} // class Hashtable |