本文整理汇总了Java中org.nfunk.jep.JEP.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java JEP.getValue方法的具体用法?Java JEP.getValue怎么用?Java JEP.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nfunk.jep.JEP
的用法示例。
在下文中一共展示了JEP.getValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formulaParser
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* 计算数学表达式
* @param value
* @return
*/
public static double formulaParser (String value){
double sum = 0;
JEP myParser = null;
if(myParser==null){
myParser = getJep();
}
try{
myParser.parseExpression(value);
boolean hasError = myParser.hasError();
sum = myParser.getValue();
}catch(Exception e){
e.printStackTrace();
}
return sum;
}
示例2: process
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
@Override
public void process(RegisterData data, String funcArg) {
log.trace("Processing: "+funcArg);
JEP j = new JEP();
j.addStandardConstants();
j.addStandardFunctions();
j.addConstant("$", new Double(data.getFloat()));
j.parseExpression(funcArg);
if (j.hasError()) {
log.error((j.getErrorInfo()));
data.setNull();
} else {
Double value = j.getValue();
if (j.hasError()) {
log.error(j.getErrorInfo());
} else {
data.setDataFloat(value.floatValue());
log.trace("Evaluated to : "+value);
}
}
}
示例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: calculateExpressionInternal
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
private static double calculateExpressionInternal( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return parser.getValue();
}
示例5: calculateExpression
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* Calculate the expression.
*
* @param expression
* Expression string
* @return calculate result
* @throws IllegalArgumentException
*/
public static double calculateExpression(String expression) throws IllegalArgumentException {
JEP myParser = new JEP();
myParser.parseExpression(expression);
if (myParser.hasError()) {
throw new IllegalArgumentException();
}
return myParser.getValue();
}
示例6: calculateExpressionInternal
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
private static double calculateExpressionInternal( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return parser.getValue();
}
示例7: 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()));
}