1 package com.genimen.djeneric.tools.scriptengine.core.util; 30 31 import java.util.HashMap ; 32 import java.util.Stack ; 33 34 public class VariableStack extends Stack 35 { 36 private static final long serialVersionUID = 1L; 37 38 public VariableStack() 39 { 40 } 41 42 public Variable push(String name, Object obj) 43 { 44 return (Variable) push(new Variable(name, obj)); 45 } 46 47 public Variable getContextObject(int i) 48 { 49 return (Variable) get(i); 50 } 51 52 public Object getValue(String name) 53 { 54 for (int i = size() - 1; i >= 0; i--) 55 { 56 Variable obj = getContextObject(i); 57 if (obj.getName().equals(name)) return obj.getObject(); 58 } 59 return null; 60 } 61 62 public Variable getVariable(String name) 63 { 64 for (int i = size() - 1; i >= 0; i--) 65 { 66 Variable obj = getContextObject(i); 67 if (obj.getName().equals(name)) return obj; 68 } 69 return null; 70 } 71 72 public HashMap getVariableTypes() 73 { 74 HashMap result = new HashMap (); 75 for (int i = 0; i < size(); i++) 76 { 77 Variable obj = getContextObject(i); 78 result.put(obj.getName(), obj.getTypeName()); 79 } 80 return result; 81 } 82 } | Popular Tags |