sofya.mutator
Class StringTable

java.lang.Object
  extended by sofya.mutator.StringTable

public final class StringTable
extends java.lang.Object

Table that maps strings to integer indices to provide string compaction, primarily for use in writing strings to files.

Version:
09/27/2005
Author:
Alex Kinneer

Constructor Summary
StringTable()
          Creates a new string table.
 
Method Summary
 int addString(java.lang.String str)
          Adds a string to this table.
 java.lang.String lookupIndex(int index)
          Gets the string associated with a given index in this table, if the index exists in the table.
 int lookupString(java.lang.String str)
          Gets the index of a string, if it has been added to this table.
 int size()
          Gets the number of strings indexed by this table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTable

public StringTable()
Creates a new string table.

Method Detail

addString

public int addString(java.lang.String str)
Adds a string to this table.

Parameters:
str - String to be added to this table.
Returns:
Index assigned to the string.

lookupString

public int lookupString(java.lang.String str)
                 throws java.util.NoSuchElementException
Gets the index of a string, if it has been added to this table.

Parameters:
str - String for which to retrieve the assigned index from this table.
Returns:
The index assigned to the string in this table.
Throws:
java.util.NoSuchElementException - If the specified string has not been added to this table.

lookupIndex

public java.lang.String lookupIndex(int index)
                             throws java.util.NoSuchElementException
Gets the string associated with a given index in this table, if the index exists in the table.

Parameters:
index - Index for which to find the associated string.
Returns:
The string associated with the given index in this table.
Throws:
java.util.NoSuchElementException - If the specified index does not have a mapping in this table.

size

public int size()
Gets the number of strings indexed by this table.

Returns:
The number of strings stored in this table.