本文整理汇总了Java中net.objecthunter.exp4j.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于net.objecthunter.exp4j包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
@Override
public void generate(Area area) {
Expression[] expressions = expressionThreadLocal.get();
for (int x = 0; x < Area.SIZE_BLOCKS; x++) {
for (int z = 0; z < Area.SIZE_BLOCKS; z++) {
int minHeight = 0;
for (Expression e : expressions) {
int y = height(e, x + area.minBlockX, z + area.minBlockZ);
for (int i = y; i >= minHeight; i--) {
block(area, x, i, z);
}
if (y > minHeight) minHeight = y + 1;
}
}
}
}
示例2: processCondition
import net.objecthunter.exp4j.Expression; //导入依赖的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;
}
}
示例3: evaluate
import net.objecthunter.exp4j.Expression; //导入依赖的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;
}
}
}
示例4: producePoints
import net.objecthunter.exp4j.Expression; //导入依赖的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);
}
示例5: initialValue
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
@Override
protected Expression[] initialValue() {
Expression[] expressions = new Expression[eqn.length];
for (int i = 0; i < eqn.length; i++) {
expressions[i] = getExpression(eqn[i]);
}
return expressions;
}
示例6: Generator
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
Generator(String eqn) {
Log.info("Equation Terrain " + getClass().getSimpleName() + ": " + eqn);
this.eqn = eqn.split(Pattern.quote("|"));
try {
for (Expression expression : expressionThreadLocal.get()) {
ValidationResult validationResult = expression.validate(false);
if (!validationResult.isValid()) throw new RuntimeException("Invalid expression " + String.valueOf(validationResult.getErrors()));
}
} catch (Exception e) {
Debug.crash(new RuntimeException("Invalid expression", e));
}
}
示例7: spawnPoint
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
@Override
public BlockReference spawnPoint(WorldServer world) {
int y = -1;
for (Expression expression : expressionThreadLocal.get()) {
int i = height(expression, 0, 0);
if (i > y) y = i;
}
if (y == -1) return new BlockReference().setFromBlockCoordinates(0, 100, 0);
return new BlockReference().setFromBlockCoordinates(0, y + 2, 0);
}
示例8: height
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
int height(Expression e, int x, int z) {
try {
e.setVariable("x", x);
e.setVariable("z", z);
int evaluate = (int) e.evaluate();
return evaluate < 0 ? -1 : evaluate;
} catch (Exception exception) {
return -1;
}
}
示例9: makeRegister
import net.objecthunter.exp4j.Expression; //导入依赖的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() + "'");
}
}
};
}
示例10: value
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
@Override
public void value(StringBuilder buff, long millisElapsed, int ticks) {
Expression expr = expressionTemplate.build();
int adjustedTicks = ticks + tickOffset;
double scaledTick = adjustedTicks / (double) scaleFactorTick;
expr.setVariable("tick", scaledTick);
long adjustedElapsed = millisElapsed + elapsedOffset;
double scaledElapsed = adjustedElapsed / (double) scaleFactorElapsed;
expr.setVariable("elapsed", scaledElapsed);
buff.append(expr.evaluate());
}
示例11: load
import net.objecthunter.exp4j.Expression; //导入依赖的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;
}
示例12: tryBuild
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
public static Expression tryBuild( ExpressionBuilder expB )
{
Expression exp = null;
// try
// {
exp = expB.build();
// }
// catch (Exception e) { }
return exp;
}
示例13: setVariableValues
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
public static void setVariableValues( Expression exp, HashMap<String, Integer> variableMap, String prefix )
{
for ( String key : variableMap.keySet() )
{
exp.setVariable( prefix + key, variableMap.get( key ) );
}
}
示例14: map
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
@Override
protected Double map(final Traverser.Admin<S> traverser) {
final Expression localExpression = new Expression(this.expression);
for (final String var : this.variables) {
localExpression.setVariable(var,
var.equals(CURRENT) ?
TraversalUtil.applyNullable(traverser, this.traversalRing.next()).doubleValue() :
TraversalUtil.applyNullable((S) this.getNullableScopeValue(Pop.last, var, traverser), this.traversalRing.next()).doubleValue());
}
this.traversalRing.reset();
return localExpression.evaluate();
}
示例15: main
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
public static void main(String[] args){
Function gok = new Function("gok",1){
@Override
public double apply(double... doubles) {
return Math.pow(doubles[0],2);
}
};
double val = 2d;
Expression expression = new ExpressionBuilder("gok(gok(C))").variables("C").function(gok).build().setVariable("C",2d);
System.out.print(expression.evaluate());
}