http://www.eteks.com

com.eteks.parser
Class DoubleInterpreter

java.lang.Object
  |
  +--com.eteks.parser.DoubleInterpreter
All Implemented Interfaces:
Interpreter
Direct Known Subclasses:
WrapperInterpreter

public class DoubleInterpreter
extends java.lang.Object
implements Interpreter

Runtime interpreter operating on Double objects. This class implements the computation of all the literals, operators and functions defined in Syntax with double numbers.
Functions and expressions may use this interpreter to compute values if the value of their parameters are Number objects (Double, Integer,...).
This interpreter is used as the default interpreter in CompiledFunction and CompiledExpression classes.
The methods of this class are thread safe.

Since:
Jeks 1.0
Version:
1.0
Author:
Emmanuel Puybaret
See Also:
Syntax

Field Summary
static java.lang.Double FALSE_DOUBLE
          The double constant matching the constant FALSE (equal to new Double (0)).
static java.lang.Double TRUE_DOUBLE
          The double constant matching the constant TRUE (equal to new Double (1)).
 
Constructor Summary
DoubleInterpreter()
           
 
Method Summary
 java.lang.Object getBinaryOperatorValue(java.lang.Object binaryOperatorKey, java.lang.Object operand1, java.lang.Object operand2)
          Returns the value of the operation of the binary operator binaryOperatorKey applied on the two operands operand1 and operand2.
 java.lang.Object getCommonFunctionValue(java.lang.Object commonFunctionKey, java.lang.Object param)
          Returns the value of the common function commonFunctionKey with the parameter param.
 java.lang.Object getConditionValue(java.lang.Object paramIf, java.lang.Object paramThen, java.lang.Object paramElse)
          Returns the value paramThen or paramElse depending on whether isTrue (paramIf) returning true or false.
 java.lang.Object getConstantValue(java.lang.Object constantKey)
          Returns the value of the constant constantKey.
 java.lang.Object getFunctionValue(Function function, java.lang.Object[] parametersValue, boolean recursiveCall)
          Returns the value of the function function with its parameters parametersValue.
 java.lang.Object getLiteralValue(java.lang.Object literal)
          Returns the value of the literal literal.
 java.lang.Object getParameterValue(java.lang.Object parameter)
          Returns the value of the parameter parameter.
 java.lang.Object getUnaryOperatorValue(java.lang.Object unaryOperatorKey, java.lang.Object operand)
          Returns the value of the operation of the unary operator unaryOperatorKey applied on the operand operand.
 boolean isTrue(java.lang.Object condition)
          Returns true or false according to the value of condition.
 boolean supportsRecursiveCall()
          Returns true thus enabling this interpreter to evaluate the value of recursive calls.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FALSE_DOUBLE

public static final java.lang.Double FALSE_DOUBLE
The double constant matching the constant FALSE (equal to new Double (0)).

TRUE_DOUBLE

public static final java.lang.Double TRUE_DOUBLE
The double constant matching the constant TRUE (equal to new Double (1)).
Constructor Detail

DoubleInterpreter

public DoubleInterpreter()
Method Detail

getLiteralValue

public java.lang.Object getLiteralValue(java.lang.Object literal)
Returns the value of the literal literal. literal may be an instance of Number.
Specified by:
getLiteralValue in interface Interpreter
Parameters:
literal - an instance of Number.
Returns:
the value of the literal. The returned value is an instance of Double.
Throws:
java.lang.IllegalArgumentException - if literal isn't an instance of Number.

getParameterValue

public java.lang.Object getParameterValue(java.lang.Object parameter)
Returns the value of the parameter parameter. parameter may be an instance of Number. This method may throw an exception if the interpreter doesn't accept the type of parameter.
Specified by:
getParameterValue in interface Interpreter
Parameters:
parameter - an instance of Number.
Returns:
the value of the parameter. The returned value is an instance of Double.
Throws:
java.lang.IllegalArgumentException - if parameter isn't an instance of Number.

getConstantValue

public java.lang.Object getConstantValue(java.lang.Object constantKey)
Returns the value of the constant constantKey. constantKey may be the key of a constant of Syntax (one of CONSTANT_PI, CONSTANT_E, CONSTANT_FALSE, CONSTANT_TRUE).
Specified by:
getConstantValue in interface Interpreter
Parameters:
constantKey - the key of a constant of Syntax.
Returns:
the value of the constant. The returned value is an instance of Double.
Throws:
java.lang.IllegalArgumentException - if constantKey isn't a key of a constant of Syntax.

getUnaryOperatorValue

public java.lang.Object getUnaryOperatorValue(java.lang.Object unaryOperatorKey,
                                              java.lang.Object operand)
Returns the value of the operation of the unary operator unaryOperatorKey applied on the operand operand. unaryOperatorKey must be the key of an unary operator of Syntax (one of OPERATOR_POSITIVE, OPERATOR_OPPOSITE, OPERATOR_LOGICAL_NOT, OPERATOR_BITWISE_NOT).
Specified by:
getUnaryOperatorValue in interface Interpreter
Parameters:
unaryOperatorKey - the key of an unary operator of Syntax.
operand - the operand (instance of Number).
Returns:
the result of the operation. The returned value is an instance of Double.
Throws:
java.lang.IllegalArgumentException - if operand isn't an instance of Number, if operand isn't an integer operand when unaryOperatorKey is the key Syntax.OPERATOR_BITWISE_NOT or if unaryOperatorKey isn't the key of an unary operator of Syntax.

getBinaryOperatorValue

public java.lang.Object getBinaryOperatorValue(java.lang.Object binaryOperatorKey,
                                               java.lang.Object operand1,
                                               java.lang.Object operand2)
Returns the value of the operation of the binary operator binaryOperatorKey applied on the two operands operand1 and operand2. binaryOperatorKey must be the key of a binary operator of Syntax (one of OPERATOR_ADD, OPERATOR_SUBSTRACT, OPERATOR_MULTIPLY, OPERATOR_DIVIDE,...).
Specified by:
getBinaryOperatorValue in interface Interpreter
Parameters:
binaryOperatorKey - the key of a binary operator of Syntax.
operand1 - the first operand (instance of Number).
operand2 - the second operand (instance of Number).
Returns:
the result of the operation. The returned value is an instance of Double.
Throws:
java.lang.IllegalArgumentException - if operand1 or operand2 aren't instances of Number, if operand1 or operand2 are not integer operands when binaryOperatorKey is the key of a bit operator (Syntax.OPERATOR_BITWISE_... and Syntax.OPERATOR_SHIFT_...) or if binaryOperatorKey isn't the key of a binary operator of Syntax.

getCommonFunctionValue

public java.lang.Object getCommonFunctionValue(java.lang.Object commonFunctionKey,
                                               java.lang.Object param)
Returns the value of the common function commonFunctionKey with the parameter param. commonFunctionKey must be the key of a commomon function of Syntax (one of FUNCTION_LN, FUNCTION_LOG, FUNCTION_EXP, FUNCTION_SQR,...).
Specified by:
getCommonFunctionValue in interface Interpreter
Parameters:
commonFunctionKey - the key of a common function of Syntax.
param - the parameter of the function (instance of Number).
Returns:
the result of the function. The returned value is an instance of Double.
Throws:
java.lang.IllegalArgumentException - if param isn't an instance of Number or if commonFunctionKey isn't the key of a commomon function of Syntax.

getConditionValue

public java.lang.Object getConditionValue(java.lang.Object paramIf,
                                          java.lang.Object paramThen,
                                          java.lang.Object paramElse)
Returns the value paramThen or paramElse depending on whether isTrue (paramIf) returning true or false. As the implementation of the supportsRecursiveCall () method in this class returns true, this method isn't called internally to get the result of a condition.
Specified by:
getConditionValue in interface Interpreter
Parameters:
paramIf - the condition.
paramThen - the true condition value.
paramElse - the false condition value.
Returns:
the result of the condition.
See Also:
supportsRecursiveCall()

isTrue

public boolean isTrue(java.lang.Object condition)
Returns true or false according to the value of condition.
Specified by:
isTrue in interface Interpreter
Parameters:
condition - the value to test (instance of Number).
Returns:
false if the double value of condition equals 0. otherwise true.

supportsRecursiveCall

public boolean supportsRecursiveCall()
Returns true thus enabling this interpreter to evaluate the value of recursive calls.
Specified by:
supportsRecursiveCall in interface Interpreter
Returns:
true.
See Also:
getConditionValue(java.lang.Object, java.lang.Object, java.lang.Object)

getFunctionValue

public java.lang.Object getFunctionValue(Function function,
                                         java.lang.Object[] parametersValue,
                                         boolean recursiveCall)
Returns the value of the function function with its parameters parametersValue. This method returns the result of function.computeFunction (this, parametersValue).
Specified by:
getFunctionValue in interface Interpreter
Parameters:
function - the function to compute.
parametersValue - the value of function's parameters.
recursiveCall - true if the call of this function is a recursive call, meaning that the current evaluated function calls itself.
Returns:
the result of the function.

&cp; 1998-2003 eTeks - All rights reserved