com.jaxfront.core.rule
Class MathEvaluator

java.lang.Object
  extended by com.jaxfront.core.rule.MathEvaluator

public class MathEvaluator
extends java.lang.Object

MathEvaluator provides a simple mechanism to evaluate algebraic expressions. It uses and extends the JEP Parser hosted by sourcefourge.net. Only with the MathEvaluator.class it's possible to use nodeFunctions! NodeFunctions are functions that uses Nodes (Types) referenced by a TypePath.

Version:
1.60
See Also:
JEP

Nested Class Summary
 class MathEvaluator.MathCommunicator
           
 
Field Summary
 int _callCount
           
static java.lang.String MATH_VAR_DOM_ID
           
static java.lang.String MATH_VAR_FALSE
           
static java.lang.String MATH_VAR_GROUP_ID
           
static java.lang.String MATH_VAR_GROUP_UUID_ID
           
static java.lang.String MATH_VAR_MANDANT
           
static java.lang.String MATH_VAR_NA_N
           
static java.lang.String MATH_VAR_NULL
           
static java.lang.String MATH_VAR_OS_NAME
           
static java.lang.String MATH_VAR_PARAM_FALSE
           
static java.lang.String MATH_VAR_PARAM_TRUE
           
static java.lang.String MATH_VAR_TRUE
           
static java.lang.String MATH_VAR_USER_COUNTRY
           
static java.lang.String MATH_VAR_USER_HOME
           
static java.lang.String MATH_VAR_USER_ID
           
static java.lang.String MATH_VAR_USER_LANGUAGE
           
static java.lang.String MATH_VAR_USER_NAME
           
static java.lang.String MATH_VAR_USER_ROLE
           
static java.lang.String MATH_VAR_USER_TIMEZONE
           
static java.lang.String MATH_VAR_USER_UUID_ID
           
static java.lang.String MATH_VAR_UUID
           
static java.lang.String MATH_VAR_WEB_APP_NAME
           
 long timeConsumption
           
 
Constructor Summary
MathEvaluator()
           
 
Method Summary
 double evaluate(java.lang.String expression, MathEvaluator.MathCommunicator communicator)
          Evaluate a simple algebraic expression
 double evaluate(Type formulaRoot, java.lang.String expression)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 double evaluate(Type formulaRoot, java.lang.String expression, boolean includeOnlySerializable)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 double evaluate(Type formulaRoot, Type eventSource, java.lang.String expression, boolean includeOnlySerializable)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 boolean evaluateBoolean(java.lang.String expression, MathEvaluator.MathCommunicator communicator)
          Evaluate a simple algebraic expression.
 boolean evaluateBoolean(Type formulaRoot, java.lang.String expression)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 boolean evaluateBoolean(Type formulaRoot, java.lang.String expression, boolean includeOnlySerializable)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 boolean evaluateBoolean(Type formulaRoot, Type eventSource, java.lang.Object event, java.lang.String expression, boolean includeOnlySerializable)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 java.lang.Object evaluateObject(java.lang.String expression, MathEvaluator.MathCommunicator com)
          Evaluate a simple algebraic expression.
 java.lang.Object evaluateObject(Type formulaRoot, java.lang.String expression)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 java.lang.Object evaluateObject(Type formulaRoot, java.lang.String expression, boolean includeOnlySerializable)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 java.lang.Object evaluateObject(Type formulaRoot, Type eventSource, java.lang.Object event, java.lang.String expression, boolean includeOnlySerializable)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 java.util.HashSet evaluateReferencedNodes(Type formulaRoot, java.lang.String expression)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 java.lang.String evaluateString(java.lang.String expression, MathEvaluator.MathCommunicator com)
          Evaluate a simple algebraic expression.
 java.lang.String evaluateString(Type formulaRoot, java.lang.Object eventSource, java.lang.Object event, java.lang.String expression, boolean includeOnlySerializable)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 java.lang.String evaluateString(Type formulaRoot, java.lang.String expression)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 java.lang.String evaluateString(Type formulaRoot, java.lang.String expression, boolean includeOnlySerializable)
          Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions
 java.lang.Object evaluateUser(java.lang.String expression, Type aBaseType)
          Evaluate a simple algebraic expression.
 java.lang.String evaluateUserString(java.lang.String expression, MathEvaluator.MathCommunicator com)
          Evaluate a simple algebraic expression.
 java.lang.String evaluateUserString(java.lang.String expression, Type aBaseType)
          Evaluate a simple algebraic expression.
 int getCalls()
           
 java.lang.String getErrorInfo()
           
 java.net.URL getFunctionsURL()
           
 java.net.URL getFunctionsXSD()
           
static MathEvaluator getInstance()
          Returns a new instance of the MathEvaluator
 java.util.Hashtable getNodeFunctionNames()
           
 java.util.Enumeration getRegisteredFunctions()
          Parses the current expression in the exprField.
 java.util.Hashtable getVariables()
           
 boolean isDebug()
           
 void setDebug(boolean _debug)
           
 void setVariable(java.lang.String name, java.lang.Object value)
          This method set a simple variable to JEP!
 void setVariables(java.util.Hashtable variables)
          This method set variables to JEP!
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MATH_VAR_TRUE

public static final java.lang.String MATH_VAR_TRUE
See Also:
Constant Field Values

MATH_VAR_FALSE

public static final java.lang.String MATH_VAR_FALSE
See Also:
Constant Field Values

MATH_VAR_PARAM_TRUE

public static final java.lang.String MATH_VAR_PARAM_TRUE
See Also:
Constant Field Values

MATH_VAR_PARAM_FALSE

public static final java.lang.String MATH_VAR_PARAM_FALSE
See Also:
Constant Field Values

MATH_VAR_NA_N

public static final java.lang.String MATH_VAR_NA_N
See Also:
Constant Field Values

MATH_VAR_NULL

public static final java.lang.String MATH_VAR_NULL
See Also:
Constant Field Values

MATH_VAR_USER_COUNTRY

public static final java.lang.String MATH_VAR_USER_COUNTRY
See Also:
Constant Field Values

MATH_VAR_OS_NAME

public static final java.lang.String MATH_VAR_OS_NAME
See Also:
Constant Field Values

MATH_VAR_USER_HOME

public static final java.lang.String MATH_VAR_USER_HOME
See Also:
Constant Field Values

MATH_VAR_MANDANT

public static final java.lang.String MATH_VAR_MANDANT
See Also:
Constant Field Values

MATH_VAR_USER_ROLE

public static final java.lang.String MATH_VAR_USER_ROLE
See Also:
Constant Field Values

MATH_VAR_USER_TIMEZONE

public static final java.lang.String MATH_VAR_USER_TIMEZONE
See Also:
Constant Field Values

MATH_VAR_USER_NAME

public static final java.lang.String MATH_VAR_USER_NAME
See Also:
Constant Field Values

MATH_VAR_USER_LANGUAGE

public static final java.lang.String MATH_VAR_USER_LANGUAGE
See Also:
Constant Field Values

MATH_VAR_USER_ID

public static final java.lang.String MATH_VAR_USER_ID
See Also:
Constant Field Values

MATH_VAR_GROUP_ID

public static final java.lang.String MATH_VAR_GROUP_ID
See Also:
Constant Field Values

MATH_VAR_WEB_APP_NAME

public static final java.lang.String MATH_VAR_WEB_APP_NAME
See Also:
Constant Field Values

MATH_VAR_USER_UUID_ID

public static final java.lang.String MATH_VAR_USER_UUID_ID
See Also:
Constant Field Values

MATH_VAR_GROUP_UUID_ID

public static final java.lang.String MATH_VAR_GROUP_UUID_ID
See Also:
Constant Field Values

MATH_VAR_UUID

public static final java.lang.String MATH_VAR_UUID
See Also:
Constant Field Values

MATH_VAR_DOM_ID

public static final java.lang.String MATH_VAR_DOM_ID
See Also:
Constant Field Values

_callCount

public int _callCount

timeConsumption

public long timeConsumption
Constructor Detail

MathEvaluator

public MathEvaluator()
Method Detail

isDebug

public boolean isDebug()

setDebug

public void setDebug(boolean _debug)

evaluate

public double evaluate(Type formulaRoot,
                       java.lang.String expression)
                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
double result
Throws:
org.nfunk.jep.ParseException

evaluate

public double evaluate(Type formulaRoot,
                       java.lang.String expression,
                       boolean includeOnlySerializable)
                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
double result
Throws:
org.nfunk.jep.ParseException

evaluate

public double evaluate(Type formulaRoot,
                       Type eventSource,
                       java.lang.String expression,
                       boolean includeOnlySerializable)
                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
double result
Throws:
org.nfunk.jep.ParseException

evaluate

public double evaluate(java.lang.String expression,
                       MathEvaluator.MathCommunicator communicator)
                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression

Returns:
double result
Throws:
org.nfunk.jep.ParseException

evaluateBoolean

public boolean evaluateBoolean(Type formulaRoot,
                               java.lang.String expression)
                        throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
boolean true/false
Throws:
org.nfunk.jep.ParseException

evaluateBoolean

public boolean evaluateBoolean(Type formulaRoot,
                               java.lang.String expression,
                               boolean includeOnlySerializable)
                        throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
boolean true/false
Throws:
org.nfunk.jep.ParseException

evaluateBoolean

public boolean evaluateBoolean(Type formulaRoot,
                               Type eventSource,
                               java.lang.Object event,
                               java.lang.String expression,
                               boolean includeOnlySerializable)
                        throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
boolean true/false
Throws:
org.nfunk.jep.ParseException

evaluateBoolean

public boolean evaluateBoolean(java.lang.String expression,
                               MathEvaluator.MathCommunicator communicator)
                        throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression.

Returns:
boolean true/false
Throws:
org.nfunk.jep.ParseException

evaluateObject

public java.lang.Object evaluateObject(Type formulaRoot,
                                       java.lang.String expression)
                                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
Object result
Throws:
org.nfunk.jep.ParseException

evaluateObject

public java.lang.Object evaluateObject(Type formulaRoot,
                                       java.lang.String expression,
                                       boolean includeOnlySerializable)
                                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
Object result
Throws:
org.nfunk.jep.ParseException

evaluateObject

public java.lang.Object evaluateObject(Type formulaRoot,
                                       Type eventSource,
                                       java.lang.Object event,
                                       java.lang.String expression,
                                       boolean includeOnlySerializable)
                                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
Object result
Throws:
org.nfunk.jep.ParseException

evaluateObject

public java.lang.Object evaluateObject(java.lang.String expression,
                                       MathEvaluator.MathCommunicator com)
                                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression.

Returns:
Object result
Throws:
org.nfunk.jep.ParseException

evaluateString

public java.lang.String evaluateString(Type formulaRoot,
                                       java.lang.String expression)
                                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
String result
Throws:
org.nfunk.jep.ParseException

evaluateString

public java.lang.String evaluateString(Type formulaRoot,
                                       java.lang.Object eventSource,
                                       java.lang.Object event,
                                       java.lang.String expression,
                                       boolean includeOnlySerializable)
                                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
String result
Throws:
org.nfunk.jep.ParseException

evaluateString

public java.lang.String evaluateString(Type formulaRoot,
                                       java.lang.String expression,
                                       boolean includeOnlySerializable)
                                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
String result
Throws:
org.nfunk.jep.ParseException

evaluateString

public java.lang.String evaluateString(java.lang.String expression,
                                       MathEvaluator.MathCommunicator com)
                                throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression.

Returns:
Object result
Throws:
org.nfunk.jep.ParseException

evaluateUserString

public java.lang.String evaluateUserString(java.lang.String expression,
                                           MathEvaluator.MathCommunicator com)
Evaluate a simple algebraic expression.

Returns:
Object result

evaluateUserString

public java.lang.String evaluateUserString(java.lang.String expression,
                                           Type aBaseType)
Evaluate a simple algebraic expression.

Returns:
Object result

evaluateUser

public java.lang.Object evaluateUser(java.lang.String expression,
                                     Type aBaseType)
Evaluate a simple algebraic expression.

Returns:
Object result

getErrorInfo

public java.lang.String getErrorInfo()

getInstance

public static MathEvaluator getInstance()
Returns a new instance of the MathEvaluator

Returns:
com.jaxfront.core.rule.MathEvaluator

getRegisteredFunctions

public java.util.Enumeration getRegisteredFunctions()
Parses the current expression in the exprField. This method also re-initializes the contents of the symbol and function tables. This is neccessary because the "allow undeclared variables" option adds variables from expressions to the symbol table.


getCalls

public int getCalls()

getFunctionsURL

public java.net.URL getFunctionsURL()

getFunctionsXSD

public java.net.URL getFunctionsXSD()

setVariable

public void setVariable(java.lang.String name,
                        java.lang.Object value)
This method set a simple variable to JEP! The method take not care about datatypes.

Parameters:
variables - java.util.Hashtable

setVariables

public void setVariables(java.util.Hashtable variables)
This method set variables to JEP! It takes the key value as variable name and variable value. The method take not care about datatypes.

Parameters:
variables - java.util.Hashtable

getVariables

public java.util.Hashtable getVariables()

evaluateReferencedNodes

public java.util.HashSet evaluateReferencedNodes(Type formulaRoot,
                                                 java.lang.String expression)
                                          throws org.nfunk.jep.ParseException
Evaluate a simple algebraic expression and set a new formulaRoot for nodeFunctions

Returns:
double result
Throws:
org.nfunk.jep.ParseException

getNodeFunctionNames

public java.util.Hashtable getNodeFunctionNames()