View Javadoc
1 2 //package jrre.classloader; 3 package jrre.api.java.lang; 4 5 import jrre.classloader.classfile.pool_entries.*; 6 import java.util.*; 7 8 /*** 9 * 10 * 11 * @author Christopher Ellsworth (Chris@chrisellsworth.com) 12 * @author Clerance Alston (massclax@hotmail.com) 13 */ 14 public class SymbolTable extends HashMap { 15 16 private int size; 17 18 /*** 19 * Default constructor for the symbol table. 20 */ 21 public SymbolTable(){ 22 super(); 23 } 24 25 /*** 26 * Constructs the symbol table with the maximum number 27 * of entries it will need to have. 28 * 29 * @param capacity The capacity to initialise it with. 30 */ 31 public SymbolTable(int capacity){ 32 super(capacity); 33 size = capacity; 34 } 35 36 /*** 37 * Adds a symbol to the table based on its index 38 * in the constant pool. 39 * 40 * @param constantPoolIndex The index in the constant pool associated with the entry. 41 * @param entry The entry in the constant pool to add to the symbol table. 42 */ 43 public void addSymbol(int constantPoolIndex, CPInfo entry){ 44 45 put(new Integer(constantPoolIndex), entry); 46 } 47 48 /*** 49 * Gets a symbol from the table based its 50 * key into the constant pool. 51 * 52 * @param constantPoolIndex The index in the constant pool associated with the desired entry. 53 * @return The entry in the constant pool associated with the constant pool index 54 * specified. 55 */ 56 public CPInfo getSymbol(int constantPoolIndex){ 57 Integer key = new Integer(constantPoolIndex); 58 59 if(!containsKey(key)){ 60 java.lang.System.err.println("Symbol table does not contain a entry to the following key: "+key); 61 return null; 62 } 63 64 return (CPInfo)get(key); 65 } 66 67 public int getSize() { return size; } 68 69 public String toString(){ 70 71 StringBuffer toReturn = new StringBuffer(); 72 73 int index = 1; 74 75 CPInfo cpInfo = (CPInfo)getSymbol(index); 76 77 while(cpInfo != null){ 78 toReturn.append("\n"+index+" :: "+cpInfo.toString()); 79 cpInfo = (CPInfo)getSymbol(++index); 80 } 81 /* 82 while((cpInfo = (CPInfo)keyIterator.next()) != null){ 83 84 toReturn.append(index+" :: "+cpInfo.toString()); 85 86 } 87 */ 88 return toReturn.toString(); 89 } 90 }

This page was automatically generated by Maven