FileDocCategorySizeDatePackage
StringToIntTable.javaAPI DocJava SE 5 API4178Fri Aug 26 14:56:04 BST 2005com.sun.org.apache.xml.internal.utils

StringToIntTable

public 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.
xsl.usage
internal

Fields Summary
public static final int
INVALID_KEY
private int
m_blocksize
Block size to allocate
private String[]
m_map
Array of strings this table points to. Associated with ints in m_values
private int[]
m_values
Array of ints this table points. Associated with strings from m_map.
private int
m_firstFree
Number of ints in the table
private int
m_mapSize
Size 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.

param
blocksize Size of block to allocate


    m_blocksize = blocksize;
    m_mapSize = blocksize;
    m_map = new String[blocksize];
    m_values = new int[m_blocksize];
  
Methods Summary
public final booleancontains(java.lang.String key)
Tell if the table contains the given string.

param
key String to look for
return
True if the string is in the table


    for (int i = 0; i < m_firstFree; i++)
    {
      if (m_map[i].equals(key))
        return true;
    }

    return false;
  
public final intget(java.lang.String key)
Tell if the table contains the given string.

param
key String to look for
return
The String's int value


    for (int i = 0; i < m_firstFree; i++)
    {
      if (m_map[i].equals(key))
        return m_values[i];
    }

	return INVALID_KEY;
  
public final intgetIgnoreCase(java.lang.String key)
Tell if the table contains the given string. Ignore case.

param
key String to look for
return
The string's int value


    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 intgetLength()
Get the length of the list.

return
the length of the list

    return m_firstFree;
  
public final java.lang.String[]keys()
Return array of keys in the table.

return
Array of strings

    String [] keysArr = new String[m_firstFree];

    for (int i = 0; i < m_firstFree; i++)
    {
      keysArr[i] = m_map[i];
    }

    return keysArr;
  
public final voidput(java.lang.String key, int value)
Append a string onto the vector.

param
key String to append
param
value The int value of the string


    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++;