本文整理汇总了Java中com.udojava.evalex.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于com.udojava.evalex包,在下文中一共展示了Expression类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: generateEasterEgg
import com.udojava.evalex.Expression; //导入依赖的package包/类
private String generateEasterEgg(Expression expression, BigDecimal result, String query, String stringifiedResult) {
if (result.intValueExact() == 69) {
return stringifiedResult + "\t( ͡° ͜ʖ ͡°)";
}
query = query.replaceAll(" ", "");
if (query.startsWith("2+2-1") && ((expression.isBoolean() && result.intValueExact() == 1) || result.intValueExact() == 3)) {
return stringifiedResult + "\t-\tQuick maths!";
}
if (query.equals("10") && stringifiedResult.equals("10")) {
return "There are only 10 types of people in the world, those who understand binary and those who don't.";
}
return stringifiedResult;
}
开发者ID:avaire,项目名称:avaire,代码行数:18,代码来源:CalculateCommand.java
示例2: doGet
import com.udojava.evalex.Expression; //导入依赖的package包/类
@Override
public void doGet(final HttpServletRequest pRequest, final HttpServletResponse pResponse)
throws IOException {
pResponse.setContentType("application/json");
final Result result = new Result();
try {
final String input = pRequest.getParameter("input");
BigDecimal value = new Expression(input).eval();
result.setSum(value.toString());
} catch (final Exception e) {
result.setError(e.toString());
}
//TODO what is faster?
//1
new Gson().toJson(result, pResponse.getWriter());
//2
// final String resultAsString = new Gson().toJson(result);
// pResponse.getWriter().print(resultAsString);
}
开发者ID:IstiN,项目名称:android-training-2017,代码行数:24,代码来源:CalculatorServlet.java
示例3: onCommand
import com.udojava.evalex.Expression; //导入依赖的package包/类
@Override
public boolean onCommand(Message message, String[] args) {
if (args.length == 0) {
return sendErrorMessage(message, "Missing argument, the `equation` argument is required!");
}
String string = String.join(" ", args).trim();
try {
Expression expression = createExpression(string);
BigDecimal result = expression.eval();
if (expression.isBoolean()) {
MessageFactory.makeInfo(message,
generateEasterEgg(expression, result, string, result.intValueExact() == 1 ? "True" : "False")
).queue();
return true;
}
MessageFactory.makeInfo(message, generateEasterEgg(expression, result, string, result.toPlainString())).queue();
} catch (Exception ex) {
return sendErrorMessage(message, ex.getMessage().replaceAll("'", "`"));
}
return true;
}
开发者ID:avaire,项目名称:avaire,代码行数:26,代码来源:CalculateCommand.java
示例4: createExpression
import com.udojava.evalex.Expression; //导入依赖的package包/类
private Expression createExpression(String string) {
int where = string.toLowerCase().indexOf("where");
if (where == -1) {
return new Expression(string)
.setVariable("tau", new BigDecimal(Math.PI * 2));
}
Expression expression = new Expression(string.substring(0, where).trim())
.setVariable("tau", new BigDecimal(Math.PI * 2));
for (String var : string.substring(where + 5, string.length()).trim().split(" and ")) {
String[] varArgs = var.split("=");
if (varArgs.length != 2) {
varArgs = var.split("is");
if (varArgs.length != 2) {
continue;
}
}
expression.setVariable(varArgs[0].trim(), new BigDecimal(varArgs[1].trim()));
}
return expression;
}
开发者ID:avaire,项目名称:avaire,代码行数:26,代码来源:CalculateCommand.java
示例5: fieldValueIsCalculatedByFormula
import com.udojava.evalex.Expression; //导入依赖的package包/类
@Then("^(?:I should see |)the \"(.*?)\" field value is calculated using the following formula:$")
public void fieldValueIsCalculatedByFormula(
String field, String formula) throws Throwable {
final double precision = 0.0099;
double pageVal = Double.parseDouble(Page.getCurrent().onPage(field)
.getText());
for (String key : Context.variables()) {
formula = formula.replaceAll(key, Context.get(key).toString());
}
Expression expression = new Expression(formula);
double calcVal = expression
.setRoundingMode(RoundingMode.HALF_EVEN).setPrecision(6).eval().doubleValue();
Assert.assertEquals("Wrong " + field + "! on page (" + pageVal
+ ") vs calulated (" + calcVal + ")", pageVal, calcVal, precision);
}
开发者ID:mkolisnyk,项目名称:0686OS,代码行数:17,代码来源:BasicKDTSteps.java
示例6: ConditionEvaluator
import com.udojava.evalex.Expression; //导入依赖的package包/类
public ConditionEvaluator(String eval) {
super();
this.eval = eval;
this.queryVars = new HashMap<>();
this.expression = new Expression(replaceQueriesWithVariables(eval));
log.debugf("eval [%s] produced [%s] with variables %s", eval, expression.getOriginalExpression(), queryVars);
// Do a test evaluation to validate the expression
try {
for (String var : queryVars.keySet()) {
this.expression.setVariable(var, "1");
}
this.expression.eval();
} catch (Exception e) {
throw new IllegalArgumentException("Invalid eval expression [" + eval + "]: " + e.getMessage());
}
}
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:21,代码来源:ConditionEvaluator.java
示例7: map
import com.udojava.evalex.Expression; //导入依赖的package包/类
/**
* Applies {@code doubleExpression} compiled to an expression to the series referenced by
* {@code seriesNames} row by row and returns the results as a new series. The series' values
* are mapped to variables in {@code doubleExpression} by series names. Only series referenced
* by {@code seriesNames} can be referenced by the expression.
* The series are converted to {@code DoubleSeries} transparently and the results
* are returned as DoubleSeries as well.
*
* <br/><b>NOTE:</b> doubleExpression is compiled to an {@code EvalEx} expression.
*
* @param doubleExpression expression to be compiled and applied using EvalEx
* @throws IllegalArgumentException if the series does not exist
* @return series with evaluation results
*/
public DoubleSeries map(String doubleExpression, final String... seriesNames) {
// TODO support escaping of "}"
final String[] vars = new String[seriesNames.length];
for(int i=0; i<seriesNames.length; i++) {
String pattern = String.format("${%s}", seriesNames[i]);
String replace = String.format("__%d", i);
vars[i] = replace;
doubleExpression = doubleExpression.replace(pattern, replace);
}
final Expression e = new Expression(doubleExpression);
return this.map(new Series.DoubleFunction() {
@Override
public double apply(double[] values) {
for(int i=0; i<values.length; i++) {
e.with(vars[i], new BigDecimal(values[i]));
}
return e.eval().doubleValue();
}
}, seriesNames);
}
开发者ID:linkedin,项目名称:pinot,代码行数:37,代码来源:DataFrame.java
示例8: execute
import com.udojava.evalex.Expression; //导入依赖的package包/类
@Override
protected void execute(CommandEvent e) {
if (!e.getArgs().isEmpty()) {
String result;
if (e.getArgs().equalsIgnoreCase("quick maths")) {
result = "2 + 2 - 1 = that's 3 quick maths.";
e.replySuccess("**Expression Evaluated!**\n**Result:**" + C.codeblock(result));
return;
}
if (e.getArgs().replace(" ", "").equalsIgnoreCase("2+2-1")) {
result = "that's 3 quick maths";
e.replySuccess("**Expression Evaluated!**\n**Result:**" + C.codeblock(result));
return;
}
try {
result = new Expression(e.getArgs()).eval().toPlainString();
} catch (Expression.ExpressionException | ArithmeticException e1) {
e.replyError("Invalid Expression!");
return;
}
if (result == null) {
e.replyError("Invalid Expression!");
return;
}
e.replySuccess("**Expression Evaluated!**\n**Result:**" + C.codeblock(result));
} else {
e.replyError("**Correct Usage:** ^" + name + " " + arguments);
}
}
开发者ID:WheezyGold7931,项目名称:happybot,代码行数:39,代码来源:MathCommand.java
示例9: execute
import com.udojava.evalex.Expression; //导入依赖的package包/类
protected void execute(Input input, Output output) {
StringBuilder sb = new StringBuilder();
for (String s : input.getArguments()) {
sb.append(s.replaceAll(",", "").trim());
}
Expression expression = new Expression(sb.toString());
BigDecimal result = expression.eval();
DecimalFormat df = new DecimalFormat(
"#,###.##################################################");
output.sendMessage(createEmbed(this.settings.getEmbedColor(), "Result",
"**```\n" + df.format(result).toString() + "\n```**"));
}
开发者ID:Svetroid,项目名称:Hobbes-v1,代码行数:13,代码来源:Calculate.java
示例10: onCalculateResult
import com.udojava.evalex.Expression; //导入依赖的package包/类
@Override
public void onCalculateResult() {
if (mCurrentStringExpression.isEmpty() || mCurrentStringExpression.contains(INFINITY)) {
view.showInvalidExpressionMessage();
} else {
clearLastValueIfItIsAnOperator();
mCurrentStringExpression = mCurrentStringExpression.replaceAll(PERCENTAGE, "/100");
Expression expression = new Expression(mCurrentStringExpression);
BigDecimal bigDecimalResult = expression.eval();
double doubleResult = bigDecimalResult.doubleValue();
String stringResult;
if (isValueInteger(doubleResult) && !isScientificNotation(Double.toString(doubleResult))) {
int roundedValue = (int) Math.round(doubleResult);
stringResult = String.valueOf(roundedValue);
} else {
stringResult = Double.toString(doubleResult);
}
view.showResult(stringResult);
mCurrentStringExpression = stringResult;
}
}
开发者ID:zurche,项目名称:simple-calc,代码行数:29,代码来源:CalculatorPresenter.java
示例11: verifyTableRowCount
import com.udojava.evalex.Expression; //导入依赖的package包/类
@Then("^(?:I should see |)the \"(.*)\" (?:table|list) has \"(.*)\" (?:items|rows)$")
public void verifyTableRowCount(String list, String countValue) throws Exception {
TableView control = (TableView) verifyElementExists(list);
BigDecimal actualCount = new BigDecimal(control.getItemsCount());
String expectedCountValue = countValue;
for (String key : Context.variables()) {
expectedCountValue = expectedCountValue.replaceAll(key, Context.get(key).toString());
}
Expression expression = new Expression(expectedCountValue);
BigDecimal expectedCount = expression.setPrecision(0).eval();
Assert.assertEquals("Unexpected row count for the '" + list + "' table", expectedCount, actualCount);
}
开发者ID:mkolisnyk,项目名称:0686OS,代码行数:13,代码来源:BasicKDTSteps.java
示例12: getExpression
import com.udojava.evalex.Expression; //导入依赖的package包/类
public Expression getExpression() {
return expression;
}
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:4,代码来源:ConditionEvaluator.java
注:本文中的com.udojava.evalex.Expression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论