Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## uchicago.src.sim.math
Class CEquation

    java.lang.Object
      uchicago.src.sim.math.CEquation

    public class CEquation

extends java.lang.Object

A user specifiable evaluatable equation. This class will evaluate a specified equation replacing the variables in the equation with values from a specified object. The result of the equation evaluation will then be written to the object.

When evaluated a CEquation will replace the variables in the specified equation with those read from a specified object. For example, if the equation is "x + 1 * z", then evaluation will replace x and z in the equation with the results of calling getX() and getZ() on the object. The result of this evaluation will be assigned to the a resultVar in a similar manner. For example, if the resultVar is "y", then on assignment the result of the equation evaluation will be assigned to the object via the object's setY(double) method.

The variable "t" can also be used. "t" is replaced by the value of the current tick count. Similarly, the variable "dt" can be used. It will be set to the delta of the current tick count and the tick count at which the last evaluation occured.

Evaluation is performed using the `evaluate` method and assignment is performed using the `assign` method.

Version:
  $Revision: 1.11 $ $Date: 2005/08/12 16:13:29 $
Author:
  Nick Collier

Constructor Summary
`CEquation(java.lang.Object target, TickCounter counter, java.lang.String equation, java.lang.String resultVar)` Creates a CEquation from the specified parameters.
`CEquation(java.lang.Object target, TickCounter counter, java.lang.String equation, java.lang.String resultVar, double initialDTValue)` Creates a CEquation from the specified parameters.

Method Summary
`void` | `assign()` Assigns the result of the last call to `evaluate` to the result variable of the target specified in the constructor.
`void` | `evaluate()` Evaluates the equation encapsulated by this CEquation.
`void` | `evaluateAndAssign()` Evaluates the currently encapsulated equation and assigns the result to the result variable.
`java.lang.String` | `getEquation()`
`void` | `setEquation(java.lang.String equation)` Sets the equation to evalute.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CEquation

    public CEquation(java.lang.Object target,
                     TickCounter counter,
                     java.lang.String equation,
                     java.lang.String resultVar)

  Creates a CEquation from the specified parameters. When evaluated the CEquation will replace the variables in the specified equation with those read from the specified target. For example, if the equation is "x + 1 * z", then evaluation will replace x and z in the equation with the results of calling getX() and getZ() on the target. The result of this evaluation will be assigned to the specified resultVar in a similar manner. For example, if the resultVar is "y", then on assignment the result of the equation evaluation will be assigned to the target via a setY(double) method.

  The variable "t" can also be used. "t" is replaced by the value of the current tick count. Similarly, the variable "dt" can be used. It will be set to the delta of the current tick count and the tick count at which the last evaluation occured. dt defaults to a value of 0 on the first evaluation. Use the alternate constructor to specify a different initial value.

  Evaluation is performed using the `evaluate` method and assignment is performed using the `assign` method.

  Parameters:
    `target` - the target from which the equations variable values are read and to which the result is assigned
    `counter` - a TickCounter from which the value of the "t" variable can be set
    `equation` - the equation to evaluate.
    `resultVar` - the name of the variable to assign the result to

### CEquation

    public CEquation(java.lang.Object target,
                     TickCounter counter,
                     java.lang.String equation,
                     java.lang.String resultVar,
                     double initialDTValue)

  Creates a CEquation from the specified parameters. When evaluated the CEquation will replace the variables in the specified equation with those read from the specified target. For example, if the equation is "x + 1 * z", then evaluation will replace x and z in the equation with the results of calling getX() and getZ() on the target. The result of this evaluation will be assigned to the specified resultVar in a similar manner. For example, if the resultVar is "y", then on assignment the result of the equation evaluation will be assigned to the target via a setY(double) method.

  The variable "t" can also be used. "t" is replaced by the value of the current tick count. Similarly, the variable "dt" can be used. It will be set to the delta of the current tick count and the tick count at which the last evaluation occured.

  Evaluation is performed using the `evaluate` method and assignment is performed using the `assign` method.

  Parameters:
    `target` - the target from which the equations variable values are read and to which the result is assigned
    `counter` - a TickCounter from which the value of the "t" variable can be set
    `equation` - the equation to evaluate.
    `resultVar` - the name of the variable to assign the result to
    `initialDTValue` - the initial value of dt to use on the first evaluation when it would otherwise be set to 0

Method Detail

### evaluate

    public void evaluate()

  Evaluates the equation encapsulated by this CEquation. This does NOT assign the result to the variable specified in the constructor. To assign the result to the result variable, follow the `evaluate()` call with a call to `assign()` or alternatively call `evaluateAndAssign()`.

  See Also:
    `assign()`, `evaluateAndAssign()`

### assign

    public void assign()

  Assigns the result of the last call to `evaluate` to the result variable of the target specified in the constructor.

### evaluateAndAssign

    public void evaluateAndAssign()

  Evaluates the currently encapsulated equation and assigns the result to the result variable.

### getEquation

    public java.lang.String getEquation()

  Returns:
    the equation currently encapsulated and evaluated by this CEquation.

### setEquation

    public void setEquation(java.lang.String equation)

  Sets the equation to evalute.

  Parameters:
    `equation` -

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD