• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ExpressionBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中de.congrace.exp4j.ExpressionBuilder的典型用法代码示例。如果您正苦于以下问题:Java ExpressionBuilder类的具体用法?Java ExpressionBuilder怎么用?Java ExpressionBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ExpressionBuilder类属于de.congrace.exp4j包,在下文中一共展示了ExpressionBuilder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: evaluateExpression

import de.congrace.exp4j.ExpressionBuilder; //导入依赖的package包/类
/**
 * Evaluates the expression provided.
 * 
 * @param value
 *            the value to evaluate
 * @param executionTime
 *            the execution time
 * @param simulationTime
 *            the simulationTime
 * @param rampTime
 *            the rampTime
 * @return the long value of evaluating the expression.
 * @throws IllegalArgumentException
 *             if there is an issue evaluating the expression.
 */
public static long evaluateExpression(String value, long executionTime, long simulationTime, long rampTime)
        throws IllegalArgumentException {
    if (StringUtils.isBlank(value)) {
        throw new IllegalArgumentException("Expression is either null or empty.");
    }
    String expression = normalizeExpression(value);
    try {
        Calculable calc = new ExpressionBuilder(expression)
                .withVariable(ESTIMATED_RUN_TIME, executionTime)
                .withVariable(SIMULATION_TIME, simulationTime)
                .withVariable(RAMP_TIME, rampTime)
                .build();
        long result = Math.round(calc.calculate());
        LOG.debug(value + " --> " + expression + " = " + Long.toString(result));
        return result;
    } catch (Exception e) {
        LOG.warn(value + " is not a valid expression.");
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:36,代码来源:TestParamUtil.java


示例2: evalute

import de.congrace.exp4j.ExpressionBuilder; //导入依赖的package包/类
@Override
public int evalute(String expression, Map<String, Object> paramsMap){
	try {
		ExpressionBuilder builder = new ExpressionBuilder(expression);
		Set<Entry<String, Object>> entries = paramsMap.entrySet();
		for(Entry<String, Object> entry : entries){
			String key = entry.getKey();
			Object value = entry.getValue();
			if (value instanceof Number) {
				Number num = (Number)value;
				builder.withVariable(key, num.doubleValue());
			}
		}
		return (int)builder.build().calculate();
	}
	catch (Exception e) {
		throw new EvaluatorException(e);
	}
}
 
开发者ID:gubaojian,项目名称:Kite,代码行数:20,代码来源:Exp4jEvaluator.java


示例3: weight

import de.congrace.exp4j.ExpressionBuilder; //导入依赖的package包/类
private double weight(Annotation node, String weightString, AnnotatedText t, AnnotatedText h, boolean isT) {
	Map<String, Double> valuesMap = new HashMap<String, Double>();
	for (NamedWeightCalculator c : calculators)
		valuesMap.put(c.name(), isT ? c.weightT(node, t, h) : c.weightH(node, t, h));
	ExpressionBuilder calc = new ExpressionBuilder(weightString).withVariables(valuesMap);
	try {
		double valuex = calc.build().calculate();
		return valuex;
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(0);
		return 0;
	}
}
 
开发者ID:kouylekov,项目名称:edits,代码行数:15,代码来源:ExpressionWeightCalculator.java


示例4: extractFeatures

import de.congrace.exp4j.ExpressionBuilder; //导入依赖的package包/类
@Override
public DoubleMatrix extractFeatures(FormattedSegments formattedSegments) {
    DoubleMatrix result = new DoubleMatrix(formattedSegments.getNumberOfRows(), 1);
    ExpressionBuilder expressionBuilder = new ExpressionBuilder(expression);
    for (int i = 0; i < formattedSegments.getNumberOfRows(); i++) {
        Map<String, Double> variableMap = getVariableMap(formattedSegments, i);
        double featureValue = getFeatureValue(expressionBuilder, variableMap);
        result.put(i, 0, featureValue);
    }
    return result;
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:12,代码来源:CustomFeatureExtractor.java


示例5: getFeatureValue

import de.congrace.exp4j.ExpressionBuilder; //导入依赖的package包/类
private double getFeatureValue(ExpressionBuilder expressionBuilder, Map<String, Double> variableMap) {
    expressionBuilder.withVariables(variableMap);
    Calculable calc = null;
    try {
        calc = expressionBuilder.build();
    } catch (UnknownFunctionException | UnparsableExpressionException e) {
        String message = "Expression for feature extractor (" + name + ") is not valid.";
        throw new InvalidExpressionException(message, e);
    }
    return calc.calculate();
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:12,代码来源:CustomFeatureExtractor.java


示例6: evaluate

import de.congrace.exp4j.ExpressionBuilder; //导入依赖的package包/类
private void evaluate() {
	if (!empty) {
		String textToEvaluate = output.getText().toString();
		textToEvaluate = textToEvaluate.replace(getString(R.string.multiply_operator).charAt(0), '*');
		textToEvaluate = textToEvaluate.replace(getString(R.string.divide_operator).charAt(0), '/');
		Log.d("math", "Evaluating expression: " + textToEvaluate);
		ExpressionBuilder builder = new ExpressionBuilder(textToEvaluate);
		try {
			lastValue = Math.round(builder.build().calculate());
			output.setText(Long.toString(lastValue));
			setNumberAllowed(false);
			setOperatorAllowed(true);
			output.setEllipsize(TruncateAt.END);
			stack.clear();
			if (listener != null) {
				listener.onNewResult(lastValue);
			}
		} catch (Exception ex) {
			if (colorTimer != null) {
				colorTimer.cancel();
			}
			colorTimer = new Timer();
			colorTimer.schedule(new TimerTask() {
				int redVal = 255;

				@Override
				public void run() {
					Keypad.this.getActivity().runOnUiThread(new ColorSetter(Color.argb(255, redVal, 0, 0), output));
					redVal -= 2;
					if (redVal < 0) {
						cancel();
					}
				}
			}, 1, 17);
		}
	}
}
 
开发者ID:ellenpoe,项目名称:BlitzCalc,代码行数:38,代码来源:Keypad.java


示例7: evaluateExpression

import de.congrace.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static int evaluateExpression( String expression )
    throws IllegalArgumentException
{
    try
    {
        return
                StringUtils.isBlank( expression )
                        ? 0
                        : (int) new ExpressionBuilder( expression ).build().calculate();
    }
    catch ( Exception e )
    {
        throw new IllegalArgumentException( "Unable to evaluate expression " + expression );
    }
}
 
开发者ID:bitstrings,项目名称:splasher-maven-plugin,代码行数:16,代码来源:DrawingUtil.java



注:本文中的de.congrace.exp4j.ExpressionBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TestServer类代码示例发布时间:2022-05-22
下一篇:
Java OnDisabled类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap