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

StringToStringTable

public class StringToStringTable 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
private int
m_blocksize
Size of blocks to allocate
private String[]
m_map
Array of strings this contains
private int
m_firstFree
Number of strings this contains
private int
m_mapSize
Size of this table
Constructors Summary
public StringToStringTable()
Default constructor. Note that the default block size is very small, for small lists.


                    
   
  

    m_blocksize = 16;
    m_mapSize = m_blocksize;
    m_map = new String[m_blocksize];
  
public StringToStringTable(int blocksize)
Construct a StringToStringTable, using the given block size.

param
blocksize Size of blocks to allocate


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

param
key String to look up
return
True if the given string is in this table


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

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

param
val value to look up
return
True if the given value is in the table.


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

    return false;
  
public final java.lang.StringelementAt(int i)
Get the nth element.

param
i index of the string to look up.
return
The string at the given index.

    return m_map[i];
  
public final java.lang.Stringget(java.lang.String key)
Tell if the table contains the given string.

param
key String to look up
return
return the value of the string or null if not found.


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

    return null;
  
public final java.lang.StringgetByValue(java.lang.String val)
Tell if the table contains the given string in the value.

param
val Value of the string to look up
return
the string associated with the given value or null if not found


    for (int i = 1; i < m_firstFree; i += 2)
    {
      if (m_map[i].equals(val))
        return m_map[i - 1];
    }

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

param
key String to look up
return
The value of the string or null if not found


    if (null == key)
      return null;

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

    return null;
  
public final intgetLength()
Get the length of the list.

return
Number of strings in the list

    return m_firstFree;
  
public final voidput(java.lang.String key, java.lang.String value)
Append a string onto the vector. The strings go to the even locations in the array and the values in the odd.

param
key String to add to the list
param
value Value of the string


    if ((m_firstFree + 2) >= 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;
    }

    m_map[m_firstFree] = key;

    m_firstFree++;

    m_map[m_firstFree] = value;

    m_firstFree++;
  
public final voidremove(java.lang.String key)
Remove the given string and its value from this table.

param
key String to remove from the table


    for (int i = 0; i < m_firstFree; i += 2)
    {
      if (m_map[i].equals(key))
      {
        if ((i + 2) < m_firstFree)
          System.arraycopy(m_map, i + 2, m_map, i, m_firstFree - (i + 2));

        m_firstFree -= 2;
        m_map[m_firstFree] = null;
        m_map[m_firstFree + 1] = null;

        break;
      }
    }