com.rubecula.jep
Class TermEvaluator

java.lang.Object
  |
  +--com.rubecula.jep.TermEvaluator
All Implemented Interfaces:
org.nfunk.jep.ParserVisitor

public class TermEvaluator
extends java.lang.Object
implements org.nfunk.jep.ParserVisitor

This class is part of the link from JQuantity to JEP - TermEvaluator depends on JEP, but there is no dependence on the com.rubecula.jquantity package. Instead this class depends on the com.rubecula.util package.

Since:
V_0_1
Version:
$Revision: 1.9 $
Author:
Robin Hillyard

Constructor Summary
(package private) TermEvaluator(org.nfunk.jep.type.NumberFactory numberFactory, MillInterface mill, Lookupable variables)
          Constructor to create a new TermEvaluator for the purpose of evaluating expressions using JQuantity objects rather than Doubles.
 
Method Summary
 Presentable getValue()
          Mutating method to get the value of an expression (mutating because it pops the stack).
 void setDebug(boolean debug)
           
 void setDeclaredVariables(java.util.Hashtable variables)
           
 java.lang.Object visit(org.nfunk.jep.ASTConstant node, java.lang.Object data)
          Method to visit a constant node.
 java.lang.Object visit(org.nfunk.jep.ASTFunNode node, java.lang.Object data)
          Method to visit a function node.
 java.lang.Object visit(org.nfunk.jep.ASTStart node, java.lang.Object data)
          Method to visit a start node.
 java.lang.Object visit(org.nfunk.jep.ASTVarNode node, java.lang.Object data)
          Method to visit a variable node.
 java.lang.Object visit(org.nfunk.jep.SimpleNode node, java.lang.Object data)
          Method to visit a simple node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TermEvaluator

TermEvaluator(org.nfunk.jep.type.NumberFactory numberFactory,
              MillInterface mill,
              Lookupable variables)
        throws MillException
Constructor to create a new TermEvaluator for the purpose of evaluating expressions using JQuantity objects rather than Doubles.

Parameters:
numberFactory - a number factory which produces objects which are Presentable and which are grist to the mill provided (basically this means that they should also be BaseNumbers).
mill - a computation mill which can will operate on the kinds of objects produced by the numberFactory (may be null, in which case an exception will be thrown when the reference is dereferenced).
variables - a lookupable map of variables (may be null).
Throws:
MillException
Method Detail

setDebug

public void setDebug(boolean debug)

setDeclaredVariables

public void setDeclaredVariables(java.util.Hashtable variables)

getValue

public Presentable getValue()
Mutating method to get the value of an expression (mutating because it pops the stack).

Returns:
the top value from the mill stack.

visit

public java.lang.Object visit(org.nfunk.jep.SimpleNode node,
                              java.lang.Object data)
Method to visit a simple node.

Specified by:
visit in interface org.nfunk.jep.ParserVisitor
Parameters:
node - a simple node.
data - the (generic) data passed in.
Returns:
the (generic) data passed out (the result of calling the childrenAccept method on the node, passing in this as the first argument).

visit

public java.lang.Object visit(org.nfunk.jep.ASTStart node,
                              java.lang.Object data)
Method to visit a start node.

Specified by:
visit in interface org.nfunk.jep.ParserVisitor
Parameters:
node - a start node.
data - the (generic) data passed in.
Returns:
the (generic) data passed out (the result of calling the childrenAccept method on the node, passing in this as the first argument).

visit

public java.lang.Object visit(org.nfunk.jep.ASTFunNode node,
                              java.lang.Object data)
Method to visit a function node. This method has the side effect of operating on the mill stack, where the operator is derived from calling getName() on the node.

Specified by:
visit in interface org.nfunk.jep.ParserVisitor
Parameters:
node - a function node.
data - the (generic) data passed in.
Returns:
the (generic) data passed out (the result of calling the childrenAccept method on the node, passing in this as the first argument).

visit

public java.lang.Object visit(org.nfunk.jep.ASTVarNode node,
                              java.lang.Object data)
Method to visit a variable node. If the #_Variables instance field is set, this method has the side effect of pushing the variable's value onto the mill stack, where the key for the variable is the result of calling getName() on the node.

Specified by:
visit in interface org.nfunk.jep.ParserVisitor
Parameters:
node - a variable node.
data - the (generic) data passed in.
Returns:
the (generic) data passed out (the result of calling the childrenAccept method on the node, passing in this as the first argument).

visit

public java.lang.Object visit(org.nfunk.jep.ASTConstant node,
                              java.lang.Object data)
Method to visit a constant node. If the #_NumberFactory instance field is set, this method has the side effect of pushing the constant's value onto the mill stack, where the pushed value is a Presentable. If _NumberFactory is unset, an exception will result, thus requiring the JEP expression parser to evaluate the expression as it would without JQuantity involvement.

Specified by:
visit in interface org.nfunk.jep.ParserVisitor
Parameters:
node - a constant node.
data - the (generic) data passed in.
Returns:
the (generic) data passed out (the result of calling the childrenAccept method on the node, passing in this as the first argument).