Skip navigation links

Package com.singularsys.jep.misc.boundvariable

This package allows the creation of Jep variables which are bound to java objects.

See: Description

Package com.singularsys.jep.misc.boundvariable Description

This package allows the creation of Jep variables which are bound to java objects. For example a Jep variable can be bound to a field of an object, the value of the variable is found from the field and the value of the field will be changed when the jep variable is changed.

 public class MyObj {
     public Double a;
     public double b;
 }
 ...
 // Create Jep with a variable factory which allows bound variables
 Jep jep = new Jep(new BoundVariableFactory());
 // Create an object, with a Double field a and a double field b
 MyObj obj = new MyObj();
 obj.a = new Double(3.0);
 obj.b = 5.0;
 // Create binding objects for the two fields
 FieldVariableBinding bindA = new FieldVariableBinding(obj,"a");
 FieldVariableBinding bindB = new FieldVariableBinding(obj,"b");
 // Create variables bound to these fields
 jep.addVariable("a", bindA);
 jep.addVariable("b", bindB);
 // Parse an equation using these values
 Node n = jep.parse("b=4*a");
 Object res = jep.evaluate(n);
 System.out.println("Result is "+res+" value of field b is "+obj.b);
See Also:
BoundVariableTest
Skip navigation links

Copyright © 2018 Singular Systems http://www.singularsys.com/jep