FileDocCategorySizeDatePackage
KVMNameTable.javaAPI DocJ2ME CLDC 1.13907Wed Feb 05 15:56:02 GMT 2003runtime

KVMNameTable

public class KVMNameTable extends KVMHashtable

Fields Summary
static final String
NameStringPrefix
static final int
TABLE_SIZE
KVMClassTable
classTable
Constructors Summary
KVMNameTable()




      
        super(TABLE_SIZE, String.class); 
    
Methods Summary
public voidaddNewEntryCallback(int bucket, java.lang.Object neww)

        int value;
        String next = (String)getNext((String)neww);
        if (next == null) { 
            value = bucket + getSize();
        } else { 
            value = getKey(next) + getSize();
        }
        setKey(neww, value);
    
public voiddeclareUString(CCodeWriter out, java.lang.String name)

 
public intgetNameKey(java.lang.String string)

 
        return getKey(string);
    
public java.lang.StringgetUString(int key)

 
        String thisKey = Integer.toHexString(key + 0x10000).substring(1);
    return "&AllUTFStrings.U" + thisKey;
    
public java.lang.StringgetUString(java.lang.String string)

 
    if (string == null) return "NULL";
        return getUString(getKey(string));
    
longhash(java.lang.Object x)

 
        String str = (String)x;
        return stringHash(str);
    
java.lang.ObjecttableChain(CCodeWriter out, int bucket, java.lang.Object[] list)

        return list.length == 0 ? null : list[0];
    
voidtableEntry(CCodeWriter out, int bucket, java.lang.Object token)

 
        out.print(getUString((String)token));
    
voidwriteTable(CCodeWriter out, java.lang.String tableName)

 
    Vector all = new Vector();
    BitSet seenSizes   = new BitSet();
    for (int i = 0; i < TABLE_SIZE; i++) { 
        for (  String entry = (String)getFirst(i); 
           entry != null; 
           entry = (String)getNext(entry)) { 
        String keyFilled = 
            Integer.toHexString(getNameKey(entry)+0x10000).substring(1);
        all.add(new String[]{entry, keyFilled});
        seenSizes.set(entry.length());
        }
    }
    for (int i = 0; i < seenSizes.size(); i++) { 
        if (seenSizes.get(i)) { 
                out.println("DECLARE_USTRING_STRUCT(" + i + ");");
        }
    }
    Collections.sort(all, new Comparator() { 
          public int compare(Object o1, Object o2) { 
          String[] pair1 = (String[])o1;
          String[] pair2 = (String[])o2;
          int key1 = getNameKey(pair1[0]);
          int key2 = getNameKey(pair2[0]);
          return key1 - key2;
          }
        });
    out.println();
    out.println();
    out.println("static CONST struct AllUTFStrings_Struct {");
    for (Enumeration e = all.elements(); e.hasMoreElements(); ) { 
        String[] pair = (String[])e.nextElement(); 
        String entry = pair[0];
        String key = pair[1];
        out.println("\tstruct UTF_Hash_Entry_" + entry.length() + 
            " U" + key + ";");
    }
    out.println("} AllUTFStrings = {");
    for (Enumeration e = all.elements(); e.hasMoreElements(); ) { 
        String[] pair = (String[])e.nextElement(); 
        String entry = pair[0];
        String key = pair[1];
        String nextEntryName = getUString((String)getNext(entry));
            out.print("\tUSTRING(" + key + ", " + nextEntryName + ", " + 
              entry.length() + ", ");
            out.printSafeString(entry);
            out.print("),");
        try { 
        if (entry.charAt(0) < 20) { 
            String s = classTable.decodeMethodSignature(entry);
            out.print(" /* ");
            out.print(s);
            out.print(" */");
        } 
        } catch (RuntimeException ex) { }
        out.println();
    }
    out.println("};\n");
    super.writeTable(out, tableName);