StringToIntTablepublic final class StringToIntTable extends Object A very simple lookup table that stores a list of strings, the even
number strings being keys, and the odd number strings being values.
This class is a copy of the one in com.sun.org.apache.xml.internal.utils.
It exists to cut the serializers dependancy on that package.
This class is not a public API, it is only public so it can be used
in com.sun.org.apache.xml.internal.serializer. |
Fields Summary |
---|
public static final int | INVALID_KEY | private int | m_blocksizeBlock size to allocate | private String[] | m_mapArray of strings this table points to. Associated with ints
in m_values | private int[] | m_valuesArray of ints this table points. Associated with strings from
m_map. | private int | m_firstFreeNumber of ints in the table | private int | m_mapSizeSize of this table |
Constructors Summary |
---|
public StringToIntTable()Default constructor. Note that the default
block size is very small, for small lists.
m_blocksize = 8;
m_mapSize = m_blocksize;
m_map = new String[m_blocksize];
m_values = new int[m_blocksize];
| public StringToIntTable(int blocksize)Construct a StringToIntTable, using the given block size.
m_blocksize = blocksize;
m_mapSize = blocksize;
m_map = new String[blocksize];
m_values = new int[m_blocksize];
|
Methods Summary |
---|
public final boolean | contains(java.lang.String key)Tell if the table contains the given string.
for (int i = 0; i < m_firstFree; i++)
{
if (m_map[i].equals(key))
return true;
}
return false;
| public final int | get(java.lang.String key)Tell if the table contains the given string.
for (int i = 0; i < m_firstFree; i++)
{
if (m_map[i].equals(key))
return m_values[i];
}
return INVALID_KEY;
| public final int | getIgnoreCase(java.lang.String key)Tell if the table contains the given string. Ignore case.
if (null == key)
return INVALID_KEY;
for (int i = 0; i < m_firstFree; i++)
{
if (m_map[i].equalsIgnoreCase(key))
return m_values[i];
}
return INVALID_KEY;
| public final int | getLength()Get the length of the list.
return m_firstFree;
| public final java.lang.String[] | keys()Return array of keys in the table.
String [] keysArr = new String[m_firstFree];
for (int i = 0; i < m_firstFree; i++)
{
keysArr[i] = m_map[i];
}
return keysArr;
| public final void | put(java.lang.String key, int value)Append a string onto the vector.
if ((m_firstFree + 1) >= m_mapSize)
{
m_mapSize += m_blocksize;
String newMap[] = new String[m_mapSize];
System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1);
m_map = newMap;
int newValues[] = new int[m_mapSize];
System.arraycopy(m_values, 0, newValues, 0, m_firstFree + 1);
m_values = newValues;
}
m_map[m_firstFree] = key;
m_values[m_firstFree] = value;
m_firstFree++;
|
|