stella.util
Class ExpressionEvaluator

java.lang.Object
  extended by stella.util.ExpressionEvaluator
All Implemented Interfaces:
Serializable

public class ExpressionEvaluator
extends Object
implements Serializable

An arbitrary expression that is parseable to a single number or a boolean at run-time. Variables that are related to the target are identified by checking their instance against TargetDependingParameter. Constants may be specified in the basic properties of the evaluator.

See Also:
Serialized Form

Field Summary
private  ExpressionNode expression
          The parsable double expression.
private  String root
          The string used for parsing.
 
Constructor Summary
ExpressionEvaluator(String init)
          Constructs a new expression evaluator.
 
Method Summary
 Boolean calculateBoolean(ParameterClustering set)
          Returns the actual value of the expression if the target is of no importance.
 Boolean calculateBoolean(ParameterClustering set, TargetDefinition target, Map<String,Object> base)
          Returns the actual value of the expression.
 Number calculateNumber(ParameterClustering set)
          Returns the actual value of the expression if the target is of no importance.
 Number calculateNumber(ParameterClustering set, TargetDefinition target, Map<String,Object> base)
          Returns the actual value of the expression.
private  String fillExpression(ParameterClustering set, TargetDefinition target, Map<String,Object> base)
           
 ExpressionNode getExpression()
          Returns the initial expression.
 void initEvaluator(String node)
          Initializes the expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expression

private transient ExpressionNode expression
The parsable double expression.


root

private String root
The string used for parsing.

Constructor Detail

ExpressionEvaluator

public ExpressionEvaluator(String init)
Constructs a new expression evaluator. The properties can be used for additional variables that should be available to the evaluator.

Method Detail

initEvaluator

public void initEvaluator(String node)
Initializes the expression. Variable substitution is done in the #evaluate method. Proper parsing is only possible if the argument follows the generic ExpressionNode specification.

Parameters:
node - A String expression.

calculateNumber

public Number calculateNumber(ParameterClustering set)
Returns the actual value of the expression if the target is of no importance.


calculateBoolean

public Boolean calculateBoolean(ParameterClustering set)
Returns the actual value of the expression if the target is of no importance.


calculateNumber

public Number calculateNumber(ParameterClustering set,
                              TargetDefinition target,
                              Map<String,Object> base)
Returns the actual value of the expression. Variables that are TargetDependingParameters are evaluted using the target definition. Variable names must either be substitutable from the parameter cluster handed over or specified as constants in the DTDConstants.CONSTANT section of the merit. The sequence of parameter substitution first looks up the merit's constant. Only if the variable is not a defined constant, it is evaluated using the parameter set.

Returns:
Either a Double or a Long

calculateBoolean

public Boolean calculateBoolean(ParameterClustering set,
                                TargetDefinition target,
                                Map<String,Object> base)
Returns the actual value of the expression. Variables that are TargetDependingParameters are evaluted using the target definition. Variable names must either be substitutable from the parameter cluster handed over or specified as constants in the DTDConstants.CONSTANT section of the merit. The sequence of parameter substitution first looks up the merit's constant. Only if the variable is not a defined constant, it is evaluated using the parameter set.

Returns:
Either a Boolean or null

fillExpression

private String fillExpression(ParameterClustering set,
                              TargetDefinition target,
                              Map<String,Object> base)

getExpression

public ExpressionNode getExpression()
Returns the initial expression.