当前位置: 首页>>代码示例>>Java>>正文


Java ExpressionBuilder类代码示例

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


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

示例1: processCondition

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public int processCondition( int depth, Random ran, boolean isBoss )
{
	if ( Global.isNumber( spawnEquation ) )
	{
		return Integer.parseInt( spawnEquation );
	}
	else
	{
		ExpressionBuilder expB = EquationHelper.createEquationBuilder( spawnEquation, ran );
		expB.variable( "depth" );
		expB.variable( "boss" );

		Expression exp = EquationHelper.tryBuild( expB );
		if ( exp == null ) { return 0; }

		exp.setVariable( "depth", depth );
		exp.setVariable( "boss", isBoss ? 1 : 0 );

		int val = (int) exp.evaluate();

		return val;
	}
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:24,代码来源:DungeonFileParser.java

示例2: evaluate

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static int evaluate( String eqn, HashMap<String, Integer> variableMap, Random ran )
{
	if ( Global.isNumber( eqn ) )
	{
		return Integer.parseInt( eqn );
	}
	else
	{
		ExpressionBuilder expB = createEquationBuilder( eqn, ran );
		setVariableNames( expB, variableMap, "" );
		Expression exp = tryBuild( expB );

		if ( exp == null )
		{
			return 0;
		}
		else
		{
			setVariableValues( exp, variableMap, "" );
			double rawVal = exp.evaluate();
			int val = Math.round( (float)rawVal );

			return val;
		}
	}
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:27,代码来源:EquationHelper.java

示例3: FromMathExpressionDoubleParameter

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
/**
  * Create a custom {@link FromMathExpressionDoubleParameter} object.<br><br>
  * 
  * See also {@link FromMathExpressionDoubleParameter} and {@link Parameter}.
  * 
  * @param mathExpression (<code>E</code>)<br>
  *        The mathematical expression to parse.
  * @param variableName (<code>X</code>)<br>
  *        The variable with respect to which <code>E</code> is a univariate function
  *        <code>E(X)</code>.
  * @param parameterName <br>
  *        The {@link String} name of this model parameter.
  */
@Inject
public FromMathExpressionDoubleParameter(
@Named("FROM_MATH_EXPRESSION_DOUBLE_MODEL_PARAMETER_EXPRESSION")
   final String mathExpression,
@Named("FROM_MATH_EXPRESSION_DOUBLE_MODEL_VARIABLE_NAME")
   final String variableName,
@Named("FROM_MATH_EXPRESSION_DOUBLE_MODEL_PARAMETER_NAME")
   final String parameterName
   ) {
   super(parameterName);
   StateVerifier.checkNotNull(mathExpression, variableName);
   this.mathExpression = mathExpression;
   this.variableName = variableName;
   
   if(mathExpression.isEmpty())
      throw new IllegalArgumentException(
         getClass().getSimpleName() + ": input math expression is empty.");
   
   this.parsedExpression =
      new ExpressionBuilder(mathExpression)
         .variables(variableName)
         .build();
   
   this.useCounter = 0L;
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:39,代码来源:FromMathExpressionDoubleParameter.java

示例4: startStage

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
@Override
public void startStage(StageConfiguration config) {

  // TODO: implement me!
  // can i reuse the expresion?
  inputFields = config.getListParam("inputFields");
  outputField = config.getProperty("outputField");
  expressionString = config.getProperty("expressionString");

  // create the expression builder
  ExpressionBuilder eBuilder = new ExpressionBuilder(expressionString);
  // set up the variables.
  eBuilder.variables(new HashSet<String>(inputFields));
  // compile the expression.
  expr = eBuilder.build();

}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:18,代码来源:MathValues.java

示例5: producePoints

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static PointsMinMaxPair producePoints(double xMin, double xMax, String expression) {
	java.awt.geom.Point2D.Double[] points = new Point2D.Double[Math.abs((int) ((xMax - xMin) / .1) + 1)];
	double min = Double.NaN, max = Double.NaN;
	
	Expression builtExpression = new ExpressionBuilder(expression).variables("x").build();
	
	for (double x = xMin, c = 0; x <= xMax; x += .1, c++) {
		try {
			double val = builtExpression.setVariable("x", x).evaluate();
			points[(int) c] = new Point2D.Double(x, val);

			if (Double.compare(min, Double.NaN) == 0)
				min = val;
			if (Double.compare(max, Double.NaN) == 0)
				max = val;
			if (val < min)
				min = val;
			if (val > max)
				max = val;
		} catch (ArithmeticException | IllegalArgumentException ex) {
			ex.printStackTrace();
			if (ex instanceof ArithmeticException) {
				ex.printStackTrace();
				return null;
			} else {
				ex.printStackTrace();
				Object[] options = { "OK" };
				JOptionPane.showOptionDialog(null, "BAD INPUT!", "Bad Input", JOptionPane.PLAIN_MESSAGE,
						JOptionPane.ERROR_MESSAGE, null, options, options[0]);
				return null;
			}
		}
	}
	double minMax[] = new double[2];
	minMax[0] = min;
	minMax[1] = max;
	
	return new PointsMinMaxPair(points, minMax);
}
 
开发者ID:Scoutdrago3,项目名称:MusicToGraph,代码行数:40,代码来源:Expressions.java

示例6: parseNodeValue

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
private Object parseNodeValue(String value, Map<String, Double> variables)
{
	if (value.startsWith("{") && value.endsWith("}"))
	{
		return new ExpressionBuilder(value).variables(variables.keySet()).build().setVariables(variables).evaluate();
	}
	return value;
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:9,代码来源:SkillData.java

示例7: makeRegister

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
private ModbusRegister makeRegister(final Register reg) {
    return new ModbusRegister() {
        @Override
        public String getName() {
            return reg.getName();
        }

        @Override
        public int getAddress() {
            return reg.getAddress();
        }

        @Override
        public int getLength() {
            return reg.getLength();
        }

        @Override
        public Expression getTransform() {
            Expression transform = new ExpressionBuilder(reg.getTransform()).variables("_").build().setVariable("_", 0);
            ValidationResult val = transform.validate();
            if (!val.isValid()) {
                throw new RuntimeException(String.format("Invalid transform '%s': %s", reg.getTransform(), val.getErrors()));
            }
            return transform;
        }

        @Override
        public ModbusRegister.Type getType() {
            switch (reg.getType()) {
                case "float":
                    return Type.FLOAT;
                case "int":
                    return Type.INT;
                default:
                    throw new RuntimeException("Unknown register type '" + reg.getType() + "'");
            }
        }
    };
}
 
开发者ID:GideonLeGrange,项目名称:modbus-mqtt,代码行数:41,代码来源:ModbusMqttService.java

示例8: load

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static FastEnumMap<Statistic, Integer> load( Element xml, FastEnumMap<Statistic, Integer> values )
{
	for ( int i = 0; i < xml.getChildCount(); i++ )
	{

		Element el = xml.getChild( i );

		Statistic stat = Statistic.valueOf( el.getName().toUpperCase() );
		String eqn = el.getText().toLowerCase();

		int newVal = values.get( stat );

		if ( Global.isNumber( eqn ) )
		{
			newVal = Integer.parseInt( eqn );
		}
		else
		{
			ExpressionBuilder expB = EquationHelper.createEquationBuilder( eqn );
			expB.variable( "value" );
			expB.variable( "val" );

			Expression exp = EquationHelper.tryBuild( expB );
			if ( exp != null )
			{
				exp.setVariable( "value", newVal );
				exp.setVariable( "val", newVal );

				newVal = (int) exp.evaluate();
			}
		}

		values.put( stat, newVal );
	}

	return values;
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:38,代码来源:Global.java

示例9: applyFunctions

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static void applyFunctions(ExpressionBuilder expB)
{
	expB.function(round);
	expB.function(clamp);
	
	expB.function(min);
	expB.function(min3);
	expB.function(min4);
	expB.function(min5);
	
	expB.function(max);
	expB.function(max3);
	expB.function(max4);
	expB.function(max5);
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:16,代码来源:MathUtilFunctions.java

示例10: applyOperators

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static void applyOperators(ExpressionBuilder expB)
{
	expB.operator(lessThan);
	expB.operator(lessThanOrEqual);
	
	expB.operator(greaterThan);
	expB.operator(greaterThanOrEqual);
	
	expB.operator(equal);
	expB.operator(notEqual);
	
	expB.operator(and);
	expB.operator(or);
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:15,代码来源:BooleanOperators.java

示例11: tryBuild

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static Expression tryBuild( ExpressionBuilder expB )
{
	Expression exp = null;

	// try
	// {
	exp = expB.build();
	// }
	// catch (Exception e) { }

	return exp;
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:13,代码来源:EquationHelper.java

示例12: setVariableNames

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static void setVariableNames( ExpressionBuilder expB, HashMap<String, Integer> variableMap, String prefix )
{
	for ( String key : variableMap.keySet() )
	{
		expB.variable( prefix + key );
	}
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:8,代码来源:EquationHelper.java

示例13: createEquationBuilder

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public static ExpressionBuilder createEquationBuilder( String eqn, Random ran )
{
	ExpressionBuilder expB = new ExpressionBuilder( eqn );
	BooleanOperators.applyOperators( expB );
	expB.function( new RandomFunction( ran ) );
	expB.function( new ChanceFunction( ran ) );
	MathUtilFunctions.applyFunctions( expB );

	return expB;
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:11,代码来源:EquationHelper.java

示例14: MathStep

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
public MathStep(final Traversal.Admin traversal, final String equation) {
    super(traversal);
    this.equation = equation;
    this.variables = MathStep.getVariables(this.equation);
    this.expression = new ExpressionBuilder(this.equation)
            .variables(this.variables)
            .implicitMultiplication(false)
            .build();
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:10,代码来源:MathStep.java

示例15: evalExpression

import net.objecthunter.exp4j.ExpressionBuilder; //导入依赖的package包/类
/**
 * Evaluate the entered expression and recalculate the resulting amount.
 * @return Boolean indicating whether the operation was successful or not.
 */
public boolean evalExpression() {
    String exp = txtMain.getText().toString();
    NumericHelper helper = new NumericHelper(this);

    exp = helper.cleanUpNumberString(exp);

    if (exp.length() > 0) {
        try {
            Double result = new ExpressionBuilder(exp).build().evaluate();

            int precision = getPrecision();
            mAmount = MoneyFactory.fromString(Double.toString(result))
                    .truncate(precision);
        } catch (IllegalArgumentException ex) {
            // Just display the last valid value.
            displayFormattedAmount();
            // Use the warning colour.
            txtTop.setTextColor(getResources().getColor(R.color.material_amber_800));

            return false;
        } catch (Exception e) {
            Timber.e(e, "evaluating expression");
        }
    } else {
        mAmount = MoneyFactory.fromString("0");
    }

    displayFormattedAmount();
    txtTop.setTextColor(mDefaultColor);
    return true;
}
 
开发者ID:moneymanagerex,项目名称:android-money-manager-ex,代码行数:36,代码来源:CalculatorActivity.java


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