FileDocCategorySizeDatePackage
StringTable.javaAPI DocJ2ME CLDC 1.12723Wed Feb 05 15:56:04 GMT 2003vm

StringTable

public class StringTable extends Object
There are two string-like data types in today's JDK: 1) zero-terminated, C-language, ASCII strings 2) Java Strings. The former arise from: (a) UTF encoding of Java class, method, field names and type signatures, used for linkage (b) UTF encoded forms of Java String constants, used as keys for the intern-ing of said constants. See the class AsciiStrings where these are manipulated to achieve some sharing of runtime data structures. In this, the StringTable class, we keep track of Java Strings, in the form of StringConstant's. We enter them in a Str2ID structure, which will be wanted at runtime. And we assign layout of the runtime char[] data. Much aliasing of data is possible, since this is read-only and not usually zero-terminated. We won't do any of that, for now. There is much potential here.

Fields Summary
public jcc.Str2ID
stringHash
public Hashtable
htable
public StringBuffer
data
private int
aggregateSize
private int
stringIndex
Constructors Summary
Methods Summary
public java.util.EnumerationallStrings()

    return htable.elements();
    
public intarrangeStringData()

    /*
     * Our initial guess is simply to concatenate all the data.
     * Later, we can try to be cleverer.
     */
    data = new StringBuffer( aggregateSize );
    int curOffset = 0;
    Enumeration s = allStrings();
    while ( s.hasMoreElements() ){
        StringConstant t = (StringConstant)s.nextElement();
        t.unicodeOffset = curOffset;
        data.append( t.str.string );
        curOffset += t.str.string.length();
    }
    return curOffset;
    
public voidintern(components.StringConstant s)


         
    StringConstant t = (StringConstant)htable.get( s );
    if ( t == null ){
        htable.put( s, s );
        stringHash.getID( s.str , s );
        aggregateSize += s.str.string.length();
        s.unicodeIndex = stringIndex++;
    } else {
        s.unicodeIndex = t.unicodeIndex;
    }
    
public intinternedStringCount()

 return stringIndex;