本文整理汇总了Java中org.nfunk.jep.JEP.parseExpression方法的典型用法代码示例。如果您正苦于以下问题:Java JEP.parseExpression方法的具体用法?Java JEP.parseExpression怎么用?Java JEP.parseExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nfunk.jep.JEP
的用法示例。
在下文中一共展示了JEP.parseExpression方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testClone3
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
public void testClone3() {
JEP jepExpression = new JEP();
jepExpression.setAllowUndeclared(true);
jepExpression.addStandardConstants();
jepExpression.addStandardFunctions();
jepExpression.parseExpression("append(a, b, c)");
System.out.println("JEP: " + jepExpression);
System.out.println(jepExpression.getTopNode().toLongString());
jepExpression.setVarValue("a", "Uno");
jepExpression.setVarValue("b", "Due");
jepExpression.setVarValue("c", "Tre");
System.out.println("Value: " + jepExpression.getValueAsObject());
JEP clone = (JEP) jepExpression.clone();
clone.setVarValue("a", "Dieci");
clone.setVarValue("b", "Undici");
clone.setVarValue("c", "Dodici");
System.out.println("Value originale: " + jepExpression.getValueAsObject());
System.out.println("Value clone: " + clone.getValueAsObject());
}
示例2: test6
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
public void test6() {
JEP jepExpression = new JEP();
jepExpression.setAllowUndeclared(true);
jepExpression.addStandardConstants();
jepExpression.addStandardFunctions();
jepExpression.parseExpression("year > 1980");
System.out.println("JEP: " + jepExpression);
jepExpression.setVarValue("year", 1981);
Object value1 = jepExpression.getValueAsObject();
System.out.println("Value: " + value1);
assertEquals(1.0, value1);
jepExpression.setVarValue("year", 1971);
Object value2 = jepExpression.getValueAsObject();
System.out.println("Value: " + value2);
assertEquals(0.0, value2);
jepExpression.setVarValue("year", "1971");
System.out.println("Value: " + jepExpression.getValueAsObject());
}
示例3: 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;
}
示例4: testClonazione3
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
public void testClonazione3() {
JEP jepExpression = new JEP();
jepExpression.setAllowUndeclared(true);
jepExpression.addStandardConstants();
jepExpression.addStandardFunctions();
jepExpression.parseExpression("append(a, b, c)");
System.out.println("JEP: " + jepExpression);
System.out.println(jepExpression.getTopNode().toLongString());
jepExpression.setVarValue("a", "Uno");
jepExpression.setVarValue("b", "Due");
jepExpression.setVarValue("c", "Tre");
System.out.println("Value: " + jepExpression.getValueAsObject());
JEP clone = (JEP) jepExpression.clone();
clone.setVarValue("a", "Dieci");
clone.setVarValue("b", "Undici");
clone.setVarValue("c", "Dodici");
System.out.println("Value originale: " + jepExpression.getValueAsObject());
System.out.println("Value clone: " + clone.getValueAsObject());
}
示例5: 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);
}
}
}
示例6: 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;
}
示例7: expressionIsTrue
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* Evaluates whether an expression is true or false.
*
* @param expression the expression to evaluate.
* @return True if the expression is true, false otherwise.
*/
public static boolean expressionIsTrue( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return isEqual( parser.getValue(), 1.0 );
}
示例8: calculateGenericExpression
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* Calculates a regular mathematical expression.
*
* @param expression The expression to calculate.
* @return The result of the operation.
*/
public static Object calculateGenericExpression( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
Object result = parser.getValueAsObject();
return result;
}
示例9: calculateExpressionInternal
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
private static double calculateExpressionInternal( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return parser.getValue();
}
示例10: expressionHasErrors
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* Investigates whether the expression is valid or has errors.
*
* @param expression The expression to validate.
* @return True if the expression has errors, false otherwise.
*/
public static boolean expressionHasErrors( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return parser.hasError();
}
示例11: getExpressionErrorInfo
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* Returns the error information for an invalid expression.
*
* @param expression The expression to validate.
* @return The error information for an invalid expression, null if
* the expression is valid.
*/
public static String getExpressionErrorInfo( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return parser.getErrorInfo();
}
示例12: 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();
}
示例13: expressionIsTrue
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* Evaluates whether an expression is true or false.
*
* @param expression the expression to evaluate.
* @return True if the expression is true, false otherwise.
*/
public static boolean expressionIsTrue( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return isEqual( parser.getValue(), 1.0 );
}
示例14: calculateExpressionInternal
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
private static double calculateExpressionInternal( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return parser.getValue();
}
示例15: expressionHasErrors
import org.nfunk.jep.JEP; //导入方法依赖的package包/类
/**
* Investigates whether the expression is valid or has errors.
*
* @param expression The expression to validate.
* @return True if the expression has errors, false otherwise.
*/
public static boolean expressionHasErrors( String expression )
{
final JEP parser = getJep();
parser.parseExpression( expression );
return parser.hasError();
}