1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.*; 26 27 import org.xquark.extractor.common.Debug; 28 29 public final class VariableTable { 30 private static final String RCSRevision = "$Revision: 1.4 $"; 31 private static final String RCSName = "$Name: $"; 32 33 34 VariableTable _defautVariableTable; 35 HashMap _varTable; 36 37 public VariableTable () 38 { 39 _varTable = new HashMap(); 41 } 43 48 public VariableTable getDefautVariableTable() 49 { 50 return _defautVariableTable; 53 } 54 55 60 public void setDefautVariableTable(VariableTable aDefautVariableTable) 61 { 62 _defautVariableTable = aDefautVariableTable; 64 } 66 67 68 77 public Expression get(String varName) 78 { 79 81 Expression retVal = null; 82 83 retVal = (Expression)_varTable.get(varName); 84 if (null==retVal && _defautVariableTable != null) { 85 retVal = _defautVariableTable.get(varName); 86 } 87 88 return retVal; 90 } 91 92 100 public void put(String varName, Expression translation) 101 { 102 Debug.assertTrue(null!=varName,"null!=varName"); 104 Debug.assertTrue(null!=translation,"null!=translation"); 105 _varTable.put(varName, translation); 106 } 108 109 public HashSet getCurrentLevelTableInstances() 110 { 111 HashSet retVal = new HashSet(); 113 Collection varTrans = _varTable.values(); 114 Iterator iter = varTrans.iterator(); 115 while (iter.hasNext()) { 116 Object item = iter.next(); 117 if (item instanceof TupleExpression) { 118 retVal.add( ((TupleExpression)item).getTableInstance() ); 119 } 120 else if (item instanceof AttributeExpression) { 121 retVal.add( ((AttributeExpression)item).getTableInstance() ); 122 } 123 } 124 return retVal; 126 } 127 public HashSet getPredefinedTableInstances() 128 { 129 HashSet retVal = new HashSet(); 131 VariableTable nextVT = getDefautVariableTable(); 132 while (null != nextVT ) { 133 retVal.addAll(nextVT.getCurrentLevelTableInstances()); 134 nextVT = nextVT.getDefautVariableTable(); 135 } 136 return retVal; 138 } 139 } 140 | Popular Tags |