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


Java Expression类代码示例

本文整理汇总了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;
      }
    }
  }
}
 
开发者ID:ictrobot,项目名称:CubesEquationTerrainGenerator,代码行数:17,代码来源:EquationTerrainGenerator.java

示例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;
	}
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:24,代码来源:DungeonFileParser.java

示例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;
		}
	}
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:27,代码来源:EquationHelper.java

示例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);
}
 
开发者ID:Scoutdrago3,项目名称:MusicToGraph,代码行数:40,代码来源:Expressions.java

示例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;
}
 
开发者ID:ictrobot,项目名称:CubesEquationTerrainGenerator,代码行数:9,代码来源:EquationTerrainGenerator.java

示例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));
  }
}
 
开发者ID:ictrobot,项目名称:CubesEquationTerrainGenerator,代码行数:13,代码来源:EquationTerrainGenerator.java

示例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);
}
 
开发者ID:ictrobot,项目名称:CubesEquationTerrainGenerator,代码行数:11,代码来源:EquationTerrainGenerator.java

示例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;
  }
}
 
开发者ID:ictrobot,项目名称:CubesEquationTerrainGenerator,代码行数:11,代码来源:EquationTerrainGenerator.java

示例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() + "'");
            }
        }
    };
}
 
开发者ID:GideonLeGrange,项目名称:modbus-mqtt,代码行数:41,代码来源:ModbusMqttService.java

示例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());
}
 
开发者ID:awslabs,项目名称:aws-iot-mqtt-load-generator,代码行数:16,代码来源:ExpressionFunction.java

示例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;
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:38,代码来源:Global.java

示例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;
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:13,代码来源:EquationHelper.java

示例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 ) );
	}
}
 
开发者ID:infinity8,项目名称:Roguelike,代码行数:8,代码来源:EquationHelper.java

示例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();
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:13,代码来源:MathStep.java

示例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());
}
 
开发者ID:gorkemgok,项目名称:Tick4J,代码行数:13,代码来源:CallIndicator.java


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