# Package com.singularsys.jep.misc.boundvariable

package com.singularsys.jep.misc.boundvariable

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 = Double.valueOf(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`

- Related Packages
  Package
  Description
  com.singularsys.jep.misc
  Miscellaneous components.
- Class
  Description
  BoundVariable
  A variable bound to an object outside Jep.
  BoundVariableFactory
  A variable factory for creating bound variables.
  ChainedObjectVariableBindingMapper
  Creates VariableBinding objects by translating the variable name into a chain of object references.
  FieldVariableBinding
  A `VariableBinding` which binds variables to a particular field of an object.
  MutableDouble
  A simple Mutable Double class.
  VariableBinding
  Bound variables will call these methods to interact with objects outside Jep.
  VariableBindingMapper
  Defines a method which translates a variable name into a variable binding.