本文整理匯總了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();
}
}