lt.monarch.math
Class FormulaParser

java.lang.Object
  extended by lt.monarch.math.AbstractFormulaParser
      extended by lt.monarch.math.FormulaParser
All Implemented Interfaces:
java.io.Serializable

public class FormulaParser
extends AbstractFormulaParser

Parses the formula into the formula tree, which enables to calculate the value of the formula. The x0, x1, x2, x3, x4 and etc. are variables which can be used in the formula and the values of those can be supplied through eval method. In the eval method x0 corresponds to the first element in the array, x1 to the second and etc. Possible functions are: "sin", "cos", "tan", "asin", "acos", "atan", "abs", "exp", "log", "lg", "sqrt", "rad", "deg", "round", "floor", "ceil", "rnd". Also available statistical operations: "mean", "stdev", "variance", e.g. "mean(x0)*stdev(x0)" Possible constants are: "PI", "E". Numbers are double values. Possible operators are: "+", "-", "*", "/", "%", "^".

See Also:
Serialized Form

Nested Class Summary
Modifier and Type Class and Description
 
Nested classes/interfaces inherited from class lt.monarch.math.AbstractFormulaParser
AbstractFormulaParser.AbstractNode
 
Field Summary
Modifier and Type Field and Description
protected  AbstractFormulaParser.AbstractNode rootNode
          The root node, that starts the evaluation
 
Fields inherited from class lt.monarch.math.AbstractFormulaParser
dataModel, nodeHash
 
Constructor Summary
Constructor and Description
FormulaParser(java.lang.String formula)
          Formula parser constructor
 
Method Summary
Modifier and Type Method and Description
 void dispose()
          Disposes the resources used by the class
 double eval()
          Evaluates the value of the formula
 java.lang.Double eval(double value)
          Evaluates the value of the formula
 java.lang.Double eval(java.lang.Double[] values)
          Evaluates the value of the formula
protected  void finalize()
           
 void setVariable(java.lang.String variableName, int value)
          Sets variable value
protected  void setVariables(java.lang.Double[] values)
          Sets values of the variables
 
Methods inherited from class lt.monarch.math.AbstractFormulaParser
getDataModel, setDataModel
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootNode

protected AbstractFormulaParser.AbstractNode rootNode
The root node, that starts the evaluation

Constructor Detail

FormulaParser

public FormulaParser(java.lang.String formula)
              throws java.lang.Exception
Formula parser constructor

Parameters:
formula - Formula string
Throws:
java.lang.Exception - Exception if the error occurs while parsing the formula
Method Detail

eval

public double eval()
Evaluates the value of the formula

Returns:
Value of the formula

eval

public java.lang.Double eval(double value)
                      throws java.lang.IllegalArgumentException
Evaluates the value of the formula

Parameters:
value - the variable value which corresponds to x1
Returns:
Value of the formula
Throws:
java.lang.IllegalArgumentException - Throws an exception if number of given values does not meet the number of variables in the formula.

eval

public java.lang.Double eval(java.lang.Double[] values)
                      throws java.lang.IllegalArgumentException
Evaluates the value of the formula

Parameters:
values - the values of variables
Returns:
Value of the formula
Throws:
java.lang.IllegalArgumentException - Throws an exception if number of given values does not meet the number of variables in the formula.

setVariables

protected void setVariables(java.lang.Double[] values)
Sets values of the variables

Parameters:
values - array of variable values

setVariable

public void setVariable(java.lang.String variableName,
                        int value)
Sets variable value

Parameters:
variableName - variable name. Possible names: index, row, column
value - variable value

dispose

public void dispose()
Description copied from class: AbstractFormulaParser
Disposes the resources used by the class

Specified by:
dispose in class AbstractFormulaParser

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable