structure
Class Hashtable

java.lang.Object
  extended by structure.Hashtable
All Implemented Interfaces:
Map

public class Hashtable
extends Object
implements Map

Implements a dictionary as a table of hashed key-value pairs. Collisions are resolved through linear probing. Values used as keys in this structure must have a hashcode method that returns the same value when two keys are "equals". Initially, a table of suggested size is allocated. It will be expanded as the load factor (ratio of pairs to entries) grows.

See Also:
ChainedHashtable

Constructor Summary
Hashtable()
          Construct a hash table that is initially empty.
Hashtable(int initialCapacity)
          Construct a hash table that is capable of holding at least initialCapacity values.
 
Method Summary
 void clear()
          Remove all key-value pairs from hashtable.
 boolean containsKey(Object key)
          Returns true iff a specific key appears within the table.
 boolean containsValue(Object value)
          Returns true if a specific value appears within the table.
 Set entrySet()
           
 Object get(Object key)
          Get the value associated with a key.
 boolean isEmpty()
          Determine if table is empty.
 Iterator iterator()
          Returns a traversal that traverses over the values of the hashtable.
 Iterator keys()
          Get a traversal over the keys of the hashtable.
 Set keySet()
           
 Object put(Object key, Object value)
          Place a key-value pair within the table.
 void putAll(Map other)
          Put all of the values found in another map into this map, overriding previous key-value associations.
 Object remove(Object key)
          Remove a key-value pair from the table.
 int size()
          Return the number of key-value pairs within the table.
 String toString()
          Generate a string representation of the hash table.
 Structure values()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface structure.Map
equals, hashCode
 

Constructor Detail

Hashtable

public Hashtable(int initialCapacity)
Construct a hash table that is capable of holding at least initialCapacity values. If that value is approached, it will be expanded appropriately. It is probably best if the capacity is prime. Table is initially empty.

Parameters:
initialCapacity - The initial capacity of the hash table.

Hashtable

public Hashtable()
Construct a hash table that is initially empty.

Method Detail

clear

public void clear()
Remove all key-value pairs from hashtable.

Specified by:
clear in interface Map

size

public int size()
Return the number of key-value pairs within the table.

Specified by:
size in interface Map
Returns:
The number of key-value pairs currently in table.

isEmpty

public boolean isEmpty()
Determine if table is empty.

Specified by:
isEmpty in interface Map
Returns:
True if table is empty.

containsValue

public boolean containsValue(Object value)
Returns true if a specific value appears within the table.

Specified by:
containsValue in interface Map
Parameters:
value - The value sought.
Returns:
True iff the value appears within the table.

containsKey

public boolean containsKey(Object key)
Returns true iff a specific key appears within the table.

Specified by:
containsKey in interface Map
Parameters:
key - The key sought.
Returns:
True iff the key sought appears within table.

iterator

public Iterator iterator()
Returns a traversal that traverses over the values of the hashtable.

Returns:
A value traversal, over the values of the table.

get

public Object get(Object key)
Get the value associated with a key.

Specified by:
get in interface Map
Parameters:
key - The key used to find the desired value.
Returns:
The value associated with the desired key.

keys

public Iterator keys()
Get a traversal over the keys of the hashtable.

Returns:
a traversal over the key values appearing within table.

put

public Object put(Object key,
                  Object value)
Place a key-value pair within the table.

Specified by:
put in interface Map
Parameters:
key - The key to be added to table.
value - The value associated with key.
Returns:
The old value associated with key if previously present.

putAll

public void putAll(Map other)
Put all of the values found in another map into this map, overriding previous key-value associations.

Specified by:
putAll in interface Map
Parameters:
other - is the source mapping

remove

public Object remove(Object key)
Remove a key-value pair from the table.

Specified by:
remove in interface Map
Parameters:
key - The key of the key-value pair to be removed.
Returns:
The value associated with the removed key.

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map

keySet

public Set keySet()
Specified by:
keySet in interface Map

values

public Structure values()
Specified by:
values in interface Map

toString

public String toString()
Generate a string representation of the hash table.

Overrides:
toString in class Object
Returns:
The string representing the table.