edu.neu.ccs.quick
Class QuickHashtable

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byedu.neu.ccs.quick.QuickHashtable
All Implemented Interfaces:
Cloneable, Map, Serializable

public class QuickHashtable
extends Hashtable

QuickHashtable extends Hashtable by adding one constructor and three methods putPairs, setPairs, and removeKeys that handle an array of Object at once.

In addition, symmetric methods are added that will hash both a key to its value and a value to its key.

All constructors of the original Hashtable class are provided as well.

The only inherited methods that are overridden are those that will throw an exception on null arguments. In this class, such methods will handle null in a sensible fashion.

Since:
2.3
Version:
2.3
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Hashtable
 
Field Summary
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
QuickHashtable()
          A constructor that delegates to class Hashtable.
QuickHashtable(int initialCapacity)
          A constructor that delegates to class Hashtable.
QuickHashtable(int initialCapacity, float loadFactor)
          A constructor that delegates to class Hashtable.
QuickHashtable(Map m)
          A constructor that delegates to class Hashtable.
QuickHashtable(Object[][] pairs)
          Constructor that adds the given 2-dimensional array of key-value pairs one-by-one to the hash table.
 
Method Summary
 boolean contains(Object value)
          Returns true if the hash table contains the value.
 boolean containsKey(Object key)
          Returns true if the hash table contains the key.
 boolean containsValue(Object value)
          Returns true if the hash table contains the value.
 Object get(Object key)
          Returns the value to which the hash table maps the specified key.
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this hash table.
 void putPairs(Object[][] pairs)
          Method that adds the given 2-dimensional array of key-value pairs one-by-one to the hash table.
 void putPairsSymmetric(Object[][] pairs)
          Method that adds the given 2-dimensional array of key-value pairs one-by-one symmetrically to the hash table.
 void putSymmetric(Object key, Object value)
          Method that adds the key-value pair symmetrically to the hash table, that is, the key maps to the value and the value maps to the key.
 Object remove(Object key)
          Removes the mapping for this key from this hash table if present.
 void removeKeys(Object[] keys)
          Method that removes the given array of keys one-by-one from the hash table.
 void setPairs(Object[][] pairs)
          Method that first clears this hash table of any existing pairs and then adds the given array of pairs one-by-one to the hash table.
 void setPairsSymmetric(Object[][] pairs)
          Method that first clears this hash table of any existing pairs and then adds the given array of pairs one-by-one symmetrically to the hash table.
 
Methods inherited from class java.util.Hashtable
clear, clone, elements, entrySet, equals, hashCode, isEmpty, keys, keySet, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QuickHashtable

public QuickHashtable()
A constructor that delegates to class Hashtable.


QuickHashtable

public QuickHashtable(int initialCapacity)
A constructor that delegates to class Hashtable.


QuickHashtable

public QuickHashtable(int initialCapacity,
                      float loadFactor)
A constructor that delegates to class Hashtable.


QuickHashtable

public QuickHashtable(Map m)
A constructor that delegates to class Hashtable.


QuickHashtable

public QuickHashtable(Object[][] pairs)

Constructor that adds the given 2-dimensional array of key-value pairs one-by-one to the hash table.

Ignores key-value pairs in which either item is null.

The capacity is set either to 10 or to 1.5 times the length of the array pairs whichever is larger.

The load factor is set to the default of 0.75.

Parameters:
pairs - the array of pairs to add to this hash table
See Also:
putPairs(Object[][])
Method Detail

put

public Object put(Object key,
                  Object value)

Associates the specified value with the specified key in this hash table. If the hash table previously contained a mapping for this key, the old value is replaced.

If the key or value is null, then simply returns null.

Parameters:
key - the key associated with the specified value
value - the value to be associated with the specified key
Returns:
previous value associated with specified key, or null if there was no mapping for key
See Also:
Hashtable.put(Object, Object)

get

public Object get(Object key)

Returns the value to which the hash table maps the specified key. Returns null if the hash table contains no mapping for the key.

If the key is null, then simply returns null.

Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which the hash table maps the specified key, or null if the hash table contains no mapping for the key
See Also:
Hashtable.get(Object)

remove

public Object remove(Object key)

Removes the mapping for this key from this hash table if present.

If the key is null, then simply returns null.

Parameters:
key - the key whose mapping should be removed
Returns:
previous value associated with specified key, or null if there was no mapping for key
See Also:
Hashtable.remove(Object)

containsKey

public boolean containsKey(Object key)

Returns true if the hash table contains the key.

If the key is null, then simply returns false.

Parameters:
key - the key whose presence in the hash table is to be tested
Returns:
true if the key is non-null and is a key in the hash table
See Also:
Hashtable.containsKey(Object)

containsValue

public boolean containsValue(Object value)

Returns true if the hash table contains the value.

If the value is null, then simply returns false.

Parameters:
value - the value whose presence in the hash table is to be tested
Returns:
true if the value is non-null and is a value in the hash table
See Also:
Hashtable.containsValue(Object)

contains

public boolean contains(Object value)

Returns true if the hash table contains the value.

If the value is null, then simply returns false.

Parameters:
value - the value whose presence in the hash table is to be tested
Returns:
true if the value is non-null and is a value in the hash table
See Also:
Hashtable.contains(Object)

putPairs

public void putPairs(Object[][] pairs)

Method that adds the given 2-dimensional array of key-value pairs one-by-one to the hash table.

If pairs is null, then does nothing.

Ignores any subarray pairs[i] that is null or not of length 2.

Ignores key-value pairs in which either item is null.

Parameters:
pairs - the array of pairs to add to this hash table
See Also:
QuickHashtable(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

setPairs

public void setPairs(Object[][] pairs)

Method that first clears this hash table of any existing pairs and then adds the given array of pairs one-by-one to the hash table.

If pairs is null, then this method is equivalent to the inherited method clear.

Ignores any subarray pairs[i] that is null or not of length 2.

Ignores key-value pairs in which either item is null.

Parameters:
pairs - the array of pairs to add to this hash table after clearance
See Also:
putPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

removeKeys

public void removeKeys(Object[] keys)

Method that removes the given array of keys one-by-one from the hash table.

If keys is null, then does nothing.

Ignores key items that are null.

Parameters:
keys - the array of keys to remove from this hash table
See Also:
putPairs(Object[][]), setPairs(Object[][]), putSymmetric(Object, Object), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

putSymmetric

public void putSymmetric(Object key,
                         Object value)

Method that adds the key-value pair symmetrically to the hash table, that is, the key maps to the value and the value maps to the key.

Does nothing if the key or value is null.

Parameters:
key - the key in the key-value pair
value - the value in the key-value pair
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putPairsSymmetric(Object[][]), setPairsSymmetric(Object[][])

putPairsSymmetric

public void putPairsSymmetric(Object[][] pairs)

Method that adds the given 2-dimensional array of key-value pairs one-by-one symmetrically to the hash table.

If pairs is null, then does nothing.

Ignores any subarray pairs[i] that is null or not of length 2.

Ignores key-value pairs in which either item is null.

Parameters:
pairs - the array of pairs to add symmetrically to this hash table
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), setPairsSymmetric(Object[][])

setPairsSymmetric

public void setPairsSymmetric(Object[][] pairs)

Method that first clears this hash table of any existing pairs and then adds the given array of pairs one-by-one symmetrically to the hash table.

If pairs is null, then this method is equivalent to the inherited method clear.

Ignores any subarray pairs[i] that is null or not of length 2.

Ignores key-value pairs in which either item is null.

Parameters:
pairs - the array of pairs to add symmetrically to this hash table after clearance
See Also:
putPairs(Object[][]), setPairs(Object[][]), removeKeys(Object[]), putSymmetric(Object, Object), putPairsSymmetric(Object[][])