本文整理汇总了Java中org.nfunk.jep.JEP类的典型用法代码示例。如果您正苦于以下问题:Java JEP类的具体用法?Java JEP怎么用?Java JEP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JEP类属于org.nfunk.jep包,在下文中一共展示了JEP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceVariableInExpression
import org.nfunk.jep.JEP; //导入依赖的package包/类
private Expression replaceVariableInExpression(Expression oldExpression, Map<Integer, SetAlias> variableRenamings) {
if (logger.isDebugEnabled()) logger.debug("Replacing paths in expression: " + oldExpression);
Expression expression = oldExpression.clone();
JEP jepExpression = expression.getJepExpression();
SymbolTable symbolTable = jepExpression.getSymbolTable();
for (Variable variable : symbolTable.getVariables()) {
VariablePathExpression oldDescription = (VariablePathExpression) variable.getDescription();
SetAlias newVariable = variableRenamings.get(oldDescription.getStartingVariable().getId());
if (newVariable != null) {
VariablePathExpression newDescription = new VariablePathExpression(oldDescription, newVariable);
variable.setDescription(newDescription);
variable.setOriginalDescription(newDescription.getAbsolutePath());
}
}
if (logger.isDebugEnabled()) logger.debug("Resulting expression: " + expression);
return expression;
}
示例2: checkSelectionCondition
import org.nfunk.jep.JEP; //导入依赖的package包/类
public void checkSelectionCondition(List<PathExpression> setPaths, Expression condition, INode root) throws ExpressionSyntaxException {
if (condition == null) {
throw new ExpressionSyntaxException("Transformation function cannot be null. Set path: " + setPaths);
}
StringBuilder errorMessage = new StringBuilder();
JEP jepExpression = condition.getJepExpression();
SymbolTable symbolTable = jepExpression.getSymbolTable();
for (Variable variable : symbolTable.getVariables()) {
String variableName = variable.getName();
PathExpression variablePath = searchPathInSet(setPaths, variableName, root);
if (variablePath == null) {
errorMessage.append("Unable to find path for variable ").append(variableName).append("\n");
} else {
variable.setDescription(variablePath);
variable.setOriginalDescription(variablePath);
}
}
if (errorMessage.length() != 0) {
throw new ExpressionSyntaxException(errorMessage.toString());
}
}
示例3: checkExpression
import org.nfunk.jep.JEP; //导入依赖的package包/类
public void checkExpression(List<PathExpression> sourcePaths, Expression expression) throws ExpressionSyntaxException {
if (expression == null) {
throw new ExpressionSyntaxException("Transformation function cannot be null. Source paths: " + sourcePaths);
}
StringBuilder errorMessage = new StringBuilder();
JEP jepExpression = expression.getJepExpression();
SymbolTable symbolTable = jepExpression.getSymbolTable();
for (Variable variable : symbolTable.getVariables()) {
String variableName = variable.getName();
PathExpression variablePath = searchPath(sourcePaths, variableName);
if (variablePath == null) {
errorMessage.append("Unable to find path for variable ").append(variableName).append("\n");
} else {
variable.setDescription(variablePath);
variable.setOriginalDescription(variablePath);
}
}
if (errorMessage.length() != 0) {
throw new ExpressionSyntaxException(errorMessage.toString());
}
}
示例4: 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());
}
示例5: 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());
}
示例6: 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;
}
示例7: 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;
}
示例8: 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());
}
示例9: init
import org.nfunk.jep.JEP; //导入依赖的package包/类
/**
* The initialization function of the applet. It adds all the
* components such as text fields and also creates the JEP object
*/
public void init() {
// initialize value for x
xValue = 10;
// add the interface components
addGUIComponents();
// Set up the parser (more initialization in parseExpression())
myParser = new JEP();
myParser.initFunTab(); // clear the contents of the function table
myParser.addStandardFunctions();
myParser.setTraverse(true);
// simulate changed options to initialize output
optionsChanged();
}
示例10: 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);
}
示例11: initParser
import org.nfunk.jep.JEP; //导入依赖的package包/类
@Override
public void initParser(boolean useStandardConstants, Process process) {
parser = new JEP();
parser.addStandardFunctions();
if (useStandardConstants)
parser.addStandardConstants();
addCustomFunctions();
addCustomConstants();
setAllowUndeclared(false);
setImplicitMul(false);
if (process != null) {
parser.addFunction("param", new ParameterValue(process));
parser.addFunction("macro", new MacroValue(process));
parser.removeFunction("rand");
parser.addFunction("rand", new Random(process));
}
}
示例12: 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);
}
}
}
示例13: 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;
}
示例14: addFunctions
import org.nfunk.jep.JEP; //导入依赖的package包/类
public static void addFunctions( JEP parser )
{
for ( Entry<String, PostfixMathCommandI> e : ALL_FUNCTIONS.entrySet() )
{
String fname = e.getKey();
PostfixMathCommandI cmd = e.getValue();
parser.addFunction( fname, cmd );
}
}
示例15: 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 );
}