goodslib
Class HashTable

java.lang.Object
  extended bygoodsjpi.Persistent
      extended bygoodslib.HashTable
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ClassLibrary

public class HashTable
extends Persistent

Hash table of persistent objects

See Also:
Serialized Form

Field Summary
protected  int count
           
protected  float loadFactor
           
protected  goodslib.HashTableEntry[] table
           
protected  int threshold
           
 
Fields inherited from class goodsjpi.Persistent
defaultMetaobject, metaobject
 
Constructor Summary
HashTable()
          Constructs a new, empty hashtable with a default capacity and load factor, which is 0.75.
HashTable(int initialCapacity)
          Constructs a new, empty HashTable with the specified initial capacity and default load factor.
HashTable(int initialCapacity, float loadFactor)
          Constructs a new, empty HashTable with the specified initial capacity and the specified load factor.
 
Method Summary
static int canonicalHashCode(java.lang.Object obj)
          Different versions of JDK provides different implementations of hashCode() methods for the same classes.
 void clear()
          Clears this HashTable so that it contains no keys.
 Persistent get(java.lang.Object key)
          Returns the value to which the specified key is mapped in this HashTable
 Persistent put(Persistent key, Persistent value)
          Maps the specified key to the specified value in this HashTable.
 Persistent put(java.lang.String key, Persistent value)
          Associate object with string key.
protected  void rehash()
          Rehashes the contents of the HashTable into a HashTable with a larger capacity.
 Persistent remove(java.lang.Object key)
          Removes the key (and its corresponding value) from this HashTable.
 int size()
          Returns the number of keys in this HashTable.
 
Methods inherited from class goodsjpi.Persistent
attachToStorage, clone, clusterWith, finalize, getDatabase, getOid, getStorageId, hashCode, onLoad
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

protected goodslib.HashTableEntry[] table

count

protected int count

threshold

protected int threshold

loadFactor

protected float loadFactor
Constructor Detail

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 capacity of the HashTable.
loadFactor - a number between 0.0 and 1.0.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than or equal to zero, or 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 and default load factor.

Parameters:
initialCapacity - the initial capacity of the HashTable.

HashTable

public HashTable()
Constructs a new, empty hashtable with a default capacity and load factor, which is 0.75.

Method Detail

size

public int size()
Returns the number of keys in this HashTable.

Returns:
the number of keys in this HashTable.

canonicalHashCode

public static int canonicalHashCode(java.lang.Object obj)
Different versions of JDK provides different implementations of hashCode() methods for the same classes. For example, String.hashCode() will return different values in JDK 1.5 and JDK 1.2 This method tries to solve this problem at least for String class.


get

public Persistent get(java.lang.Object key)
Returns the value to which the specified key is mapped in this HashTable

Parameters:
key - a key in the HashTable.
Returns:
the value to which the key is mapped in this HashTable; null if the key is not mapped to any value in this HashTable.

rehash

protected void rehash()
Rehashes the contents of the HashTable into a HashTable with a larger capacity. This method is called automatically when the number of keys in the HashTable exceeds this HashTable's capacity and load factor.


put

public Persistent put(Persistent key,
                      Persistent value)
Maps the specified key to the specified value in this HashTable. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
key - the HashTable key.
value - the value.
Returns:
the previous value of the specified key in this HashTable, or null if it did not have one.
Throws:
java.lang.NullPointerException - if the key or value is null.

put

public Persistent put(java.lang.String key,
                      Persistent value)
Associate object with string key.


remove

public Persistent remove(java.lang.Object key)
Removes the key (and its corresponding value) from this HashTable. This method does nothing if the key is not in the HashTable.

Parameters:
key - the key that needs to be removed.
Returns:
the value to which the key had been mapped in this HashTable, or null if the key did not have a mapping.

clear

public void clear()
Clears this HashTable so that it contains no keys.