de.congrace.exp4j
Class ExpressionBuilder

java.lang.Object
  extended by de.congrace.exp4j.ExpressionBuilder

public class ExpressionBuilder
extends Object

This is Builder implementation for the exp4j API used to create a Calculable instance for the user

Author:
frank asseg

Field Summary
static String PROPERTY_UNARY_HIGH_PRECEDENCE
          Property name for unary precedence choice.
 
Constructor Summary
ExpressionBuilder(String expression)
          Create a new ExpressionBuilder
 
Method Summary
 Calculable build()
          build a new Calculable from the expression using the supplied variables
 ExpressionBuilder withCustomFunction(CustomFunction function)
          add a custom function instance for the evaluator to recognize
 ExpressionBuilder withCustomFunctions(Collection<CustomFunction> functions)
           
 ExpressionBuilder withExpression(String expression)
          set the mathematical expression for parsing
 ExpressionBuilder withOperation(CustomOperator operation)
          set a CustomOperator to be used in the expression
 ExpressionBuilder withOperations(Collection<CustomOperator> operations)
          set a Collection of CustomOperator to use in the expression
 ExpressionBuilder withVariable(String variableName, double value)
          set the value for a variable
 ExpressionBuilder withVariableNames(String... variableNames)
          set the variables names used in the expression without setting their values
 ExpressionBuilder withVariables(Map<String,Double> variableMap)
          set the values for variables
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_UNARY_HIGH_PRECEDENCE

public static final String PROPERTY_UNARY_HIGH_PRECEDENCE
Property name for unary precedence choice. You can set System.getProperty(PROPERTY_UNARY_HIGH_PRECEDENCE,"false") in order to change evaluation from an expression like "-3^2" from "(-3)^2" to "-(3^2)"

See Also:
Constant Field Values
Constructor Detail

ExpressionBuilder

public ExpressionBuilder(String expression)
Create a new ExpressionBuilder

Parameters:
expression - the expression to evaluate
Method Detail

build

public Calculable build()
                 throws UnknownFunctionException,
                        UnparsableExpressionException
build a new Calculable from the expression using the supplied variables

Returns:
the Calculable which can be used to evaluate the expression
Throws:
UnknownFunctionException - when an unrecognized function name is used in the expression
UnparsableExpressionException - if the expression could not be parsed

withCustomFunction

public ExpressionBuilder withCustomFunction(CustomFunction function)
add a custom function instance for the evaluator to recognize

Parameters:
function - the CustomFunction to add
Returns:
the ExpressionBuilder instance

withCustomFunctions

public ExpressionBuilder withCustomFunctions(Collection<CustomFunction> functions)

withVariable

public ExpressionBuilder withVariable(String variableName,
                                      double value)
set the value for a variable

Parameters:
variableName - the variable name e.g. "x"
value - the value e.g. 2.32d
Returns:
the ExpressionBuilder instance

withVariableNames

public ExpressionBuilder withVariableNames(String... variableNames)
set the variables names used in the expression without setting their values

Parameters:
variableNames - vararg String of the variable names used in the expression
Returns:
the ExpressionBuilder instance

withVariables

public ExpressionBuilder withVariables(Map<String,Double> variableMap)
set the values for variables

Parameters:
variableMap - a map of variable names to variable values
Returns:
the ExpressionBuilder instance

withOperation

public ExpressionBuilder withOperation(CustomOperator operation)
set a CustomOperator to be used in the expression

Parameters:
operation - the CustomOperator to be used
Returns:
the ExpressionBuilder instance

withOperations

public ExpressionBuilder withOperations(Collection<CustomOperator> operations)
set a Collection of CustomOperator to use in the expression

Parameters:
operations - the Collection of CustomOperator to use
Returns:
the ExpressionBuilder instance

withExpression

public ExpressionBuilder withExpression(String expression)
set the mathematical expression for parsing

Parameters:
expression - a mathematical expression
Returns:
the ExpressionBuilder instance


Copyright © 2012. All Rights Reserved.