本文整理汇总了Java中org.openlca.expressions.FormulaInterpreter.bind方法的典型用法代码示例。如果您正苦于以下问题:Java FormulaInterpreter.bind方法的具体用法?Java FormulaInterpreter.bind怎么用?Java FormulaInterpreter.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openlca.expressions.FormulaInterpreter
的用法示例。
在下文中一共展示了FormulaInterpreter.bind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidName
import org.openlca.expressions.FormulaInterpreter; //导入方法依赖的package包/类
/**
* Returns true if the given name is a valid identifier for a parameter. We
* allow the same rules as for Java identifiers.
*/
public static boolean isValidName(String paramaterName) {
if (paramaterName == null)
return false;
String id = paramaterName.trim();
if (id.isEmpty())
return false;
for (int i = 0; i < id.length(); i++) {
char c = id.charAt(i);
if (i == 0 && !Character.isLetter(c))
return false;
if (i > 0 && !Character.isJavaIdentifierPart(c))
return false;
}
FormulaInterpreter interpreter = new FormulaInterpreter();
interpreter.bind(paramaterName, "1");
try {
interpreter.eval(paramaterName);
} catch (InterpreterException e) {
return false;
}
return true;
}
示例2: initInterpreter
import org.openlca.expressions.FormulaInterpreter; //导入方法依赖的package包/类
private FormulaInterpreter initInterpreter(ParameterDao dao) {
FormulaInterpreter interpreter = new FormulaInterpreter();
for (Parameter parameter : dao.getGlobalParameters()) {
interpreter.bind(parameter.getName(),
Double.toString(parameter.getValue()));
}
return interpreter;
}
示例3: createInterpreter
import org.openlca.expressions.FormulaInterpreter; //导入方法依赖的package包/类
private FormulaInterpreter createInterpreter(List<Parameter> globals) {
FormulaInterpreter interpreter = new FormulaInterpreter();
for (Parameter global : globals) {
String name = global.getName();
String val = Double.toString(global.getValue());
interpreter.bind(name, val);
}
return interpreter;
}
示例4: calculatedParamter
import org.openlca.expressions.FormulaInterpreter; //导入方法依赖的package包/类
private void calculatedParamter(SPCalculatedParameter parameter,
Map<String, SPCalculatedParameter> index)
throws IllegalAccessException {
ES2Parameter es2Parameter = new ES2Parameter();
parameters.put(parameter.getName(), es2Parameter);
// @id
es2Parameter.id = UUID.randomUUID().toString();
// @name & @variableName
if (parameter.getName() != null && !parameter.getName().equals("")) {
es2Parameter.getName().add(new LangString(parameter.getName()));
es2Parameter.variableName = parameter.getName();
}
// @isCalculatedAmount
es2Parameter.isCalculatedAmount = true;
String expression = parameter.getExpression();
// @mathematicalRelation
es2Parameter.mathematicalRelation = expression;
// convert formula
try {
FormulaInterpreter interpreter = new FormulaInterpreter();
for (String name : index.keySet()) {
if (expression.contains(name)) {
if (parameters.containsKey(name)) {
interpreter.bind(name, Double.toString(parameters
.get(name).amount));
} else {
calculatedParamter(index.get(name), index);
if (!parameters.containsKey(name))
throw new IllegalAccessException(
"Conversion formula error!");
interpreter.bind(name, Double.toString(parameters
.get(name).amount));
}
}
}
// @amount
es2Parameter.amount = interpreter
.eval(expression.replace(",", ";"));
} catch (InterpreterException e) {
e.printStackTrace();
}
}