本文整理汇总了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;
}
}
示例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;
}
}
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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() + "'");
}
}
};
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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 );
}
}
示例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;
}
示例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();
}
示例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;
}