[all packages]
[package net.sf.pizzacompiler.util]
[class hierarchy]
[index]
public class net.sf.pizzacompiler.util.Hashtable<A, B>
(source file: /home/enno/source/tmp/pizza/main/src/net/sf/pizzacompiler/util/Hashtable.pizza)
java.lang.Object
|
+----net.sf.pizzacompiler.util.Dictionary<A, B>
|
+----net.sf.pizzacompiler.util.Hashtable<A, B>
The pure class interface.
public class Hashtable<A, B>
extends Dictionary<A, B>
implements java.io.Serializable, Cloneable
-
Hashtable class. Maps keys to values. Any object can be used as
a key and/or value. Values must extend Object and must not be null.
To sucessfully store and retrieve objects from a hash table, the
object used as the key must implement the hashCode() and equals()
methods.
This example creates a hashtable of numbers. It uses the names of
the numbers as keys:
Hashtable<int, String> numbers = new Hashtable();
numbers.put(1, "one");
numbers.put(2, "two");
numbers.put(3, "three");
To retrieve a number use:
String n = numbers.get(2);
if (n != null) {
System.out.println("2 = " + n);
}
- See also:
- hashCode, equals
- Hashtable()
-
Constructs a new, empty hashtable
- Hashtable(int)
-
Constructs a new, empty hashtable with the specified initial
capacity.
- Hashtable(int, float)
-
Constructs a new, empty hashtable with the specified initial
capacity and the specified
- clear()
-
Clears the hash table so that it has no more elements in it.
- clone()
-
Creates a clone of the hashtable
- contains(B)
-
Returns true if the specified object is an element of the hashtable.
This operation is
- containsKey(A)
-
Returns true if the collection contains an element for the key.
- elements()
-
Returns an enumeration of the elements
- get(A)
-
Gets the object associated with the specified key in the
hashtable.
- isEmpty()
-
Returns true if the hashtable contains no elements.
- keys()
-
Returns an enumeration of the hashtable's keys.
- put(A, B)
-
Puts the specified element into the hashtable, using the specified
key
- rehash()
-
Rehashes the content of the table into a bigger table.
This method is called
- remove(A)
-
Removes the element corresponding to the key
- size()
-
Returns the number of elements contained in the hashtable.
- toString()
-
Converts to a rather lengthy String.
- EntryList<A, B>
-
Chains hashtable entries.
- KeyEnumeration<A, B>
-
- NullEntryList<A, B>
-
Uses the NullObject pattern to avoid lots of tests for Null in
missing entries
- ValueEnumeration<A, B>
-
Hashtable
public Hashtable(int initialCapacity,
float loadFactor);
-
Constructs a new, empty hashtable with the specified initial
capacity and the specified load factor.
- Parameters:
- initialCapacity - the initial number of buckets
- loadFactor - a number between 0.0 and 1.0, it defines
the threshold for rehashing the hashtable into
a bigger one.
- Throws:
- IllegalArgumentException -If the initial capacity
is less than or equal to zero.
- IllegalArgumentException -If the load factor is
less than or equal to zero.
-
Hashtable
public Hashtable(int initialCapacity);
-
Constructs a new, empty hashtable with the specified initial
capacity.
- Parameters:
- initialCapacity - the initial number of buckets
Hashtable
public Hashtable();
-
Constructs a new, empty hashtable. A default capacity and load factor
is used. Note that the hashtable will automatically grow when it gets
full.
size
public int size();
-
Returns the number of elements contained in the hashtable.
- Overrides:
- size in class Dictionary
isEmpty
public boolean isEmpty();
-
Returns true if the hashtable contains no elements.
- Overrides:
- isEmpty in class Dictionary
keys
public synchronized Enumeration<A> keys();
-
Returns an enumeration of the hashtable's keys.
- Overrides:
- keys in class Dictionary
- See also:
- elements, Enumeration
elements
public synchronized Enumeration<B> elements();
-
Returns an enumeration of the elements. Use the Enumeration methods
on the returned object to fetch the elements sequentially. No order
is preserved.
- Overrides:
- elements in class Dictionary
- See also:
- keys, Enumeration
contains
public synchronized boolean contains(B value);
-
Returns true if the specified object is an element of the hashtable.
This operation is more expensive than the containsKey() method.
- Parameters:
- value - the value that we are looking for
- Throws:
- NullPointerException -If the value being searched
for is equal to null.
-
- See also:
- containsKey
containsKey
public synchronized boolean containsKey(A key);
-
Returns true if the collection contains an element for the key.
- Parameters:
- key - the key that we are looking for
- See also:
- contains
get
public synchronized B get(A key);
-
Gets the object associated with the specified key in the
hashtable.
- Parameters:
- key - the specified key
- Returns:
- the element for the key or null if the key
is not defined in the hash table.
- Overrides:
- get in class Dictionary
- See also:
- put
rehash
protected void rehash();
-
Rehashes the content of the table into a bigger table.
This method is called automatically when the hashtable's
load exceeds the load factor.
put
public synchronized B put(A key,
B value);
-
Puts the specified element into the hashtable, using the specified
key. The element is not entered to the hash table if another element
with the same key exists.
The element may be retrieved by doing a get() with the same key.
The key and the element cannot be null.
- Parameters:
- key - the specified key in the hashtable
- value - the specified element
- Returns:
- the old value of the key, or null if it did not have one.
- Throws:
- NullPointerException -If the value of the element
is equal to null.
-
- Overrides:
- put in class Dictionary
- See also:
- get
remove
public synchronized B remove(A key);
-
Removes the element corresponding to the key. Does nothing if the
key is not present.
- Parameters:
- key - the key that needs to be removed
- Returns:
- the value of key, or null if the key was not found.
- Overrides:
- remove in class Dictionary
clear
public synchronized void clear();
-
Clears the hash table so that it has no more elements in it.
clone
public synchronized Object clone();
-
Creates a clone of the hashtable. A shallow copy is made,
the keys and elements themselves are NOT cloned. This is a
relatively expensive operation.
- Overrides:
- clone in class Object
toString
public synchronized String toString();
-
Converts to a rather lengthy String.
- Overrides:
- toString in class Object
private static class EntryList<A, B>
private static class EntryList<A, B>
-
Chains hashtable entries.
private static class NullEntryList<A, B>
private static class NullEntryList<A, B>
extends EntryList<A, B>
-
Uses the NullObject pattern to avoid lots of tests for Null in
missing entries
private class KeyEnumeration<A, B>
private class KeyEnumeration<A, B>
implements Enumeration<A>
private class ValueEnumeration<A, B>
private class ValueEnumeration<A, B>
implements Enumeration<A>
[all packages]
[package net.sf.pizzacompiler.util]
[class hierarchy]
[index]
net.sf.pizzacompiler.util.Hashtable.html