Package org.apache.uima.internal.util
Class SymbolTable
- java.lang.Object
-
- org.apache.uima.internal.util.SymbolTable
-
public class SymbolTable extends java.lang.ObjectThe SymbolTable class provides a generic symbol table. A symbol table is a bijective mapping between strings and integers. Symbol numbering starts at a point defined by the user, which is 0 by default. A SymbolTable provides quick access to symbol numbers (code points) through a hash table. The reverse map is facilitated through a separate vector of the symbols. This is memory intensive, but much faster than searching through the hashtable.
-
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_STARTprivate java.util.ArrayList<java.lang.String>int2symbolMapprivate intstartprivate java.util.HashMap<java.lang.String,java.lang.Integer>symbol2intMap
-
Constructor Summary
Constructors Constructor Description SymbolTable()Default constructorSymbolTable(int start)Use this constructor if you need your symbol numbering to start at a different point than 0.SymbolTable(java.lang.String[] names)Init the symbol table from an array of strings, where code points correspond to array positions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intabs2rel(int i)booleancontains(java.lang.String symbol)SymbolTablecopy()Perform a deep copy.intget(java.lang.String symbol)Get value of symbol in table.intgetStart()Get the starting number of the symbol table.java.lang.StringgetSymbol(int i)Find the symbol corresponding to a value.static SymbolTablereadFromFile(java.lang.String filename)Read a file line by line, and create an entry for each line.private intrel2abs(int i)intset(java.lang.String symbol)Create new symbol in table.intsize()Returns number of symbols in table.java.lang.StringtoString()Returns the string representation of the internal hash table.
-
-
-
Field Detail
-
DEFAULT_START
private static final int DEFAULT_START
- See Also:
- Constant Field Values
-
start
private int start
-
symbol2intMap
private final java.util.HashMap<java.lang.String,java.lang.Integer> symbol2intMap
-
int2symbolMap
private final java.util.ArrayList<java.lang.String> int2symbolMap
-
-
Constructor Detail
-
SymbolTable
public SymbolTable(int start)
Use this constructor if you need your symbol numbering to start at a different point than 0.- Parameters:
start- The code point of the first symbol added to the table. Subsequent symbols will have larger code points.
-
SymbolTable
public SymbolTable()
Default constructor
-
SymbolTable
public SymbolTable(java.lang.String[] names)
Init the symbol table from an array of strings, where code points correspond to array positions. Warning: if the array contains duplicate strings, the numbering will be off!- Parameters:
names- The String array containing the symbols.
-
-
Method Detail
-
contains
public boolean contains(java.lang.String symbol)
-
getStart
public int getStart()
Get the starting number of the symbol table.- Returns:
- The start of the table.
-
copy
public SymbolTable copy()
Perform a deep copy.- Returns:
- A copy of
this.
-
rel2abs
private final int rel2abs(int i)
-
abs2rel
private final int abs2rel(int i)
-
set
public int set(java.lang.String symbol)
Create new symbol in table. If the symbol already exists, only the symbol's number is returned. Use get() if you need to find out if the symbol is already in the table.- Parameters:
symbol- the input string to be put in the table.- Returns:
- the symbol's number.
-
get
public int get(java.lang.String symbol)
Get value of symbol in table.- Parameters:
symbol- the input string.- Returns:
- the symbol's number, if the symbol is in the table, and
start-1, else (wherestartis the code point of the first symbol).
-
getSymbol
public java.lang.String getSymbol(int i)
Find the symbol corresponding to a value.- Parameters:
i- the number that we want to get the string value for.- Returns:
- the symbol corresponding to the input number, if it exists, and null, else.
-
size
public int size()
Returns number of symbols in table.- Returns:
- The number of symbols in the table.
-
toString
public java.lang.String toString()
Returns the string representation of the internal hash table.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representing the symbol table.
-
readFromFile
public static SymbolTable readFromFile(java.lang.String filename) throws java.io.IOException
Read a file line by line, and create an entry for each line. Empty lines are ignored. Lines containing only whitespace are not.- Parameters:
filename- The name of the file to be read in.- Returns:
- The SymbolTable created from the file.
- Throws:
java.io.IOException- Errors reading in the file.
-
-