edu.vt.marian.search
Class FullIDStringTable

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--edu.vt.marian.search.FullIDTable
                    |
                    +--edu.vt.marian.search.FullIDStringTable

public class FullIDStringTable
extends FullIDTable

Provides a hash table for FullIDs and Strings such that both can be used as keys to the other. So, a FullID can map to a String, and that String can reverse-map to the FullID. (I am presuming this mapping is one-to-one.)

This class implicitly relies upon the hashCode method to be defined in the object that is going to be used as a key object.

See Also:
FullIDTable, FullID, FullID.hashCode(), Hashtable, Debug, Serialized Form

Fields inherited from class edu.vt.marian.search.FullIDTable
BAD_PARAMS, debug, NULL_STREAM, OK
 
Constructor Summary
FullIDStringTable(java.io.BufferedReader br, edu.vt.marian.common.Debug debug)
          Create a FullID/String hash table from a file of initial mappings.
FullIDStringTable(edu.vt.marian.common.Debug debug)
          Create an empty hash table for FullIDs and Strings
FullIDStringTable(int initialCapacity, edu.vt.marian.common.Debug debug)
          Create an empty hash table for FullIDs and Strings specifying initial capacity, but with default load factor.
FullIDStringTable(int initialCapacity, float loadFactor, edu.vt.marian.common.Debug debug)
          Create an empty hash table for FullIDs and Strings specifying initial capacity and load factor.
 
Method Summary
 boolean isInTable(java.lang.String string)
          Test whether a given String is in the hash table.
 java.lang.Object put(edu.vt.marian.common.FullID fullID, java.lang.String string)
          Insert a FullID->String mapping into the hash table, along with the reverse mapping.
 int toStream(java.io.PrintWriter pw)
          Dump the FullIDTable to an output stream (file).
 java.lang.String toString()
          Convert hash table to a printable string representation.
 java.lang.String toString(int estimatedSize)
          Convert hash table to a printable string representation.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FullIDStringTable

public FullIDStringTable(edu.vt.marian.common.Debug debug)
Create an empty hash table for FullIDs and Strings

FullIDStringTable

public FullIDStringTable(int initialCapacity,
                         float loadFactor,
                         edu.vt.marian.common.Debug debug)
Create an empty hash table for FullIDs and Strings specifying initial capacity and load factor.
Parameters:
initialCapacity - initial size of hash table
loadFactor - occupancy threshold before growth needed
debug - debugging object

FullIDStringTable

public FullIDStringTable(int initialCapacity,
                         edu.vt.marian.common.Debug debug)
Create an empty hash table for FullIDs and Strings specifying initial capacity, but with default load factor.
Parameters:
initialCapacity - initial size of hash table
debug - debugging object

FullIDStringTable

public FullIDStringTable(java.io.BufferedReader br,
                         edu.vt.marian.common.Debug debug)
Create a FullID/String hash table from a file of initial mappings. The input file consists of lines of FullID->String mappings. Each mapping line is of the form:

classID:instanceID\tString\n

As each mapping is read, it is inserted into the newly created hash table as both the forward and the reverse mapping.

Method Detail

isInTable

public boolean isInTable(java.lang.String string)
Test whether a given String is in the hash table.
Parameters:
string - String object to test for existence in hash table
Returns:
True if string is a key for something in the hash table; false otherwise.

put

public java.lang.Object put(edu.vt.marian.common.FullID fullID,
                            java.lang.String string)
Insert a FullID->String mapping into the hash table, along with the reverse mapping.
Parameters:
fullID - FullID key value
string - String mapped to by FullID
Returns:
Object if either the FullID or the String were already in the hash table; null otherwise.
See Also:
Hashtable.put(java.lang.Object, java.lang.Object)

toString

public java.lang.String toString(int estimatedSize)
Convert hash table to a printable string representation.
Returns:
String containing object mappings
See Also:
FullID.toString()

toString

public java.lang.String toString()
Convert hash table to a printable string representation.
Returns:
String containing object mappings
Overrides:
toString in class FullIDTable
See Also:
FullID.toString()

toStream

public int toStream(java.io.PrintWriter pw)
Dump the FullIDTable to an output stream (file). This method invokes the toStream() method of FullID in writing both the key and hashed value to the output stream. The format of the dump is (key, object)*.
Parameters:
pw - output stream to which hash table should be dumped
Returns:
OK if table dumped successfully; NULL_STREAM if pw was null.
Overrides:
toStream in class FullIDTable