本文整理汇总了Java中net.objecthunter.exp4j.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于net.objecthunter.exp4j包,在下文中一共展示了Expression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: build
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
public Expression build(){
Expression expression = super.build();
expression.setVariable("o", TickDataRow.OPEN)
.setVariable("h", TickDataRow.HIGH)
.setVariable("l", TickDataRow.LOW)
.setVariable("c", TickDataRow.CLOSE)
.setVariable("v", TickDataRow.VOLUME);
return expression;
}
开发者ID:gorkemgok,项目名称:Tick4J,代码行数:10,代码来源:TALibExpressionBuilder.java
示例17: test
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
@Test
public void test() {
Expression expression = new TALibExpressionBuilder(set,"C>SMA(c,20)").build();
set.begin();
while (set.next()){
expression.setVariable("C", set.getRow().getClose());
double expressionResult = expression.evaluate();
System.out.println(expressionResult);
assertNotEquals(expressionResult, 0);
}
set.reset();
}
开发者ID:gorkemgok,项目名称:Tick4J,代码行数:13,代码来源:Exp4JTALibFunctionTest.java
示例18: join
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
@Override
public Recommendation join(Recommendation rec, ArticleStatsTuple stats) throws Exception {
if(stats != null) {
if(stats.getInLinks() < 1) {
// This should normally not happen (if stats records do not have resolved redirects)
LOG.warn("Recommendation does not have any in-links: " + rec + "; stats: " + stats);
stats.setInLinks(1);
}
double cpi = rec.getScore();
// Initialize ExpressionBuilder in join method (non-serializable)
Expression cpiExpression;
cpiExpression = new ExpressionBuilder(cpiExpressionStr)
.variables("x", "y", "z")
.build()
.setVariable("z", articleCount)
.setVariable("x", cpi)
.setVariable("y", stats.getInLinks());
cpi = cpiExpression.evaluate();
// Test for too large values
if(cpi > Integer.MAX_VALUE) {
throw new Exception("Too large CPI score: CPI > Interger.MAX_VALUE: " + cpi + " (before: "
+ rec.getScore() + "; expr=" + cpiExpressionStr + "; article count="
+ articleCount + "; in-links=" + stats.getInLinks());
}
rec.setScore(cpi);
} else {
// throw new Exception("Recommendation does not have stats records: " + rec);
LOG.warn("Recommendation does not have a stats record: " + rec);
}
return rec;
}
开发者ID:wikimedia,项目名称:citolytics,代码行数:37,代码来源:ComputeComplexCPI.java
示例19: execute
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
@Override
public boolean execute(MessageEvent event) throws Exception {
String[] args = event.getMessage().split(" ");
StringBuilder sb = new StringBuilder();
for (int i = 1; i < args.length; i++) {
sb.append(args[i]).append(" ");
}
Expression e = new ExpressionBuilder(sb.toString()).build();
event.respond(String.valueOf(e.evaluate()));
return true;
}
开发者ID:harry2258,项目名称:AlfredV2-FTB-IRC-,代码行数:12,代码来源:Math.java
示例20: getExpression
import net.objecthunter.exp4j.Expression; //导入依赖的package包/类
Expression getExpression(String eqn) {
return new ExpressionBuilder(eqn).variable("x").variable("z").build();
}
开发者ID:ictrobot,项目名称:CubesEquationTerrainGenerator,代码行数:4,代码来源:EquationTerrainGenerator.java
注:本文中的net.objecthunter.exp4j.Expression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论