Copyright (C) 2000, 2001, Geert Vernaeve. All Rights Reserved.
package gve.calc.formula; import java.util.Hashtable;
When redefining a variable, the old contents are lost forever.
public class SingleEvaluator implements Evaluator { private Hashtable vars; private Hashtable functions = new Hashtable(); public SingleEvaluator() { vars = new Hashtable(); } public Object clone() { SingleEvaluator result = new SingleEvaluator(); result.vars = (Hashtable)vars.clone(); result.functions = (Hashtable)functions.clone(); return result; } public void defineVariable(String name,Part value) { vars.put(name,value); } public java.util.Enumeration variables() { return vars.keys(); } public void undefVariable(String name) { vars.remove(name); } public Part getValue(String identifier) { return (Part)vars.get(identifier); } public void setValue(String name,Part value) { vars.put(name,value); } public String toString() { return vars.toString(); } public void dump() { java.util.Enumeration keys = vars.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); System.out.println("---key "+key); Object val = vars.get(key); if (val instanceof Part) ((Part)val).dump(1); else System.out.println(val); } } public Part call(String funcname,Part args) { Function f = (Function)functions.get(funcname); if (f == null) return null; return f.call(funcname,args,this); } public void setFunction(String funcname,Function f) { functions.put(funcname,f); } public boolean isFunction(String funcname) { return (functions.get(funcname) != null); } }