org.yawlfoundation.yawl.cost.data
Class ExpressionParser

java.lang.Object
  extended by org.yawlfoundation.yawl.cost.data.ExpressionParser

public class ExpressionParser
extends Object

Parses and evaluates a numeric expression. Valid operators are + - * and \ (note the backslash for division). Sub-expressions may be parenthesised to any level.

Author:
Michael Adams
Created/Last Date:
15/11/11

Constructor Summary
ExpressionParser()
           
ExpressionParser(String expr, Map<String,String> vars)
          Creates a new parser
 
Method Summary
 double evaluate()
          Evaluates a previously added expression
 double evaluate(String expr)
          Evaluates an expression
static void main(String[] args)
          Unit tests the class with expressions entered from the command line
 void setExpression(String expr)
          Sets the primary expression for this parser
 void setVariables(Map<String,String> vars)
          sets the map of variables and their values for this parser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionParser

public ExpressionParser()

ExpressionParser

public ExpressionParser(String expr,
                        Map<String,String> vars)
Creates a new parser

Parameters:
expr - the expression to parse
vars - a set of variables and their values
Method Detail

setVariables

public void setVariables(Map<String,String> vars)
sets the map of variables and their values for this parser

Parameters:
vars - the map of variables and their values

setExpression

public void setExpression(String expr)
Sets the primary expression for this parser

Parameters:
expr - the expression to parse

evaluate

public double evaluate()
Evaluates a previously added expression

Returns:
the result of the evaluation
Throws:
NumberFormatException - if the expression is malformed

evaluate

public double evaluate(String expr)
Evaluates an expression

Parameters:
expr - the expression to evaluate
Returns:
the result of the evaluation
Throws:
NumberFormatException - if the expression is malformed

main

public static void main(String[] args)
Unit tests the class with expressions entered from the command line

Parameters:
args - runtime arguments - none required


Copyright © 2004-2012 The YAWL Foundation.