1 8 package org.lsmp.djep.xjep; 9 10 import org.nfunk.jep.*; 11 12 18 public class XVariable extends Variable { 19 private Node equation=null; 20 21 public XVariable(String name) { 22 super(name); 23 } 24 25 public XVariable(String name, Object value) { 26 super(name, value); 27 } 28 29 30 public boolean hasEquation() { return equation != null; } 31 32 public void setEquation(Node eqn) 33 { 34 equation = eqn; 35 this.setValidValue(false); 36 } 37 38 public Node getEquation() { return equation; } 39 40 44 public Object calcValue(XJep jep) throws Exception 45 { 46 if(equation == null ) return getValue(); 47 Object val = jep.evaluate(equation); 48 setValue(val); 49 return val; 50 } 51 52 53 public String toString(PrintVisitor pv) 54 { 55 StringBuffer sb = new StringBuffer (name); 56 sb.append(": val "+getValue() ); 57 if(!hasValidValue()) sb.append("(invalid)"); 58 sb.append(" "); 59 if(getEquation()!=null) sb.append(pv.toString(getEquation())); 60 else sb.append("no equation"); 61 return sb.toString(); 62 } 63 } 64 | Popular Tags |