本文整理汇总了Java中org.nfunk.jep.JEP.addVariable方法的典型用法代码示例。如果您正苦于以下问题:Java JEP.addVariable方法的具体用法?Java JEP.addVariable怎么用?Java JEP.addVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nfunk.jep.JEP
的用法示例。
在下文中一共展示了JEP.addVariable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJep
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* 初始化解析器
* @return
*/
private static JEP getJep(){
JEP myParser = new JEP();
// Allow implicit multiplication
myParser.setImplicitMul(true);
// Load the standard functions
myParser.addStandardFunctions();
// Load the standard constants, and complex variables/functions
myParser.addStandardConstants();
myParser.addComplex();
// Add and initialize x to 0
myParser.addVariable("x",0);
return myParser;
}
示例2: initParser
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* Initializes the parser
*/
private void initParser(String initialExpression) {
// Init Parser
myParser = new JEP();
// Allow implicit multiplication
myParser.setImplicitMul(true);
// Load the standard functions
myParser.addStandardFunctions();
// Load the standard constants, and complex variables/functions
myParser.addStandardConstants();
myParser.addComplex();
// Add and initialize x to 0
myParser.addVariable("x",0);
// Set the string to the initial value
setExpressionString(initialExpression);
}
示例3: getValue
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
@Override
public double getValue() throws CalcExeption {
// If no formula is set, throw an exception.
if(formula == null){
throw new CalcFormulaNotSetException();
}
// JEP parser instance
JEP parser = new JEP();
parser.addStandardConstants();
parser.addStandardFunctions();
// Initiate parameters
Iterator<String> params = parameters.keySet().iterator();
while(params.hasNext()){
String key = params.next();
parser.addVariable(key, parameters.get(key).getValue());
}
// Set the expression to parse
parser.parseExpression(formula);
parser.getSymbolTable().toString();
// Get the result
double result = parser.getValue();
if(Double.isNaN(result)){
throw new CalcParameterNotSetException();
}
return result;
}
示例4: main
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
public static void main(String args[]) {
int nEvals = 500;
int nVars = 1000;
Date start, finish;
String str = "";
JEP myParser = new JEP();
// Test small symbol table
for (int i=0; i<10; i++) {
myParser.addVariable("v"+i, 0);
str += "+" + "v" + i;
}
myParser.parseExpression(str);
System.out.print("Evaluating with small symbol table... ");
start = new Date();
for (int i=0; i<nEvals; i++) {
myParser.getValue();
}
finish = new Date();
System.out.println("done.");
System.out.println("Time: " +
(finish.getTime() - start.getTime()));
// Test large symbol table
str = "";
for (int i=0; i<nVars; i++) {
myParser.addVariable("v" + i, 0);
str += "+" + "v" + i;
}
myParser.parseExpression(str);
System.out.print("Evaluating with large symbol table... ");
start = new Date();
for (int i=0; i<nEvals; i++) {
myParser.getValue();
}
finish = new Date();
System.out.println("done.");
System.out.println("Time: " +
(finish.getTime() - start.getTime()));
}