-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added eq and not expressions to ActionLang, deprecated RoverBoostVolt…
…ageActionNode for removal
- Loading branch information
1 parent
8cf4593
commit b49393b
Showing
18 changed files
with
206 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
action-node/src/main/java/me/retrodaredevil/action/node/expression/EqualsExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package me.retrodaredevil.action.node.expression; | ||
|
||
import me.retrodaredevil.action.node.expression.result.BooleanExpressionResult; | ||
import me.retrodaredevil.action.node.expression.result.ExpressionResult; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class EqualsExpression implements BooleanExpression { | ||
private final Expression lhs; | ||
private final Expression rhs; | ||
|
||
public EqualsExpression(Expression lhs, Expression rhs) { | ||
this.lhs = lhs; | ||
this.rhs = rhs; | ||
} | ||
|
||
@Override | ||
public List<? extends BooleanExpressionResult> evaluate() { | ||
List<? extends ExpressionResult> leftResultList = lhs.evaluate(); | ||
List<? extends ExpressionResult> rightResultList = rhs.evaluate(); | ||
List<BooleanExpressionResult> resultList = new ArrayList<>(); | ||
for (ExpressionResult leftResult : leftResultList) { | ||
for (ExpressionResult rightResult : rightResultList) { | ||
resultList.add(BooleanExpressionResult.get(leftResult.equals(rightResult))); | ||
} | ||
} | ||
return resultList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
action-node/src/main/java/me/retrodaredevil/action/node/expression/NotExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.retrodaredevil.action.node.expression; | ||
|
||
import me.retrodaredevil.action.node.expression.result.BooleanExpressionResult; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class NotExpression implements BooleanExpression { | ||
private final Expression expression; | ||
|
||
public NotExpression(Expression expression) { | ||
this.expression = requireNonNull(expression); | ||
} | ||
|
||
@Override | ||
public List<? extends BooleanExpressionResult> evaluate() { | ||
List<? extends BooleanExpressionResult> results = ExpressionConvert.convertTo(expression.evaluate(), BooleanExpressionResult.class); | ||
// TODO use unmodifiable list | ||
return results.stream() | ||
.map(BooleanExpressionResult::not) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ode/src/main/java/me/retrodaredevil/action/node/expression/node/EqualsExpressionNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package me.retrodaredevil.action.node.expression.node; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import me.retrodaredevil.action.node.environment.ActionEnvironment; | ||
import me.retrodaredevil.action.node.expression.EqualsExpression; | ||
import me.retrodaredevil.action.node.expression.Expression; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
@JsonTypeName("eq") | ||
public class EqualsExpressionNode implements ExpressionNode { | ||
private final ExpressionNode lhs; | ||
private final ExpressionNode rhs; | ||
|
||
@JsonCreator | ||
public EqualsExpressionNode( | ||
@JsonProperty(value = "lhs", required = true) ExpressionNode lhs, | ||
@JsonProperty(value = "rhs", required = true) ExpressionNode rhs) { | ||
this.lhs = requireNonNull(lhs); | ||
this.rhs = requireNonNull(rhs); | ||
} | ||
|
||
@Override | ||
public Expression createExpression(ActionEnvironment actionEnvironment) { | ||
return new EqualsExpression( | ||
lhs.createExpression(actionEnvironment), | ||
rhs.createExpression(actionEnvironment) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...n-node/src/main/java/me/retrodaredevil/action/node/expression/node/NotExpressionNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.retrodaredevil.action.node.expression.node; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import me.retrodaredevil.action.node.environment.ActionEnvironment; | ||
import me.retrodaredevil.action.node.expression.Expression; | ||
import me.retrodaredevil.action.node.expression.NotExpression; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
@JsonTypeName("not") | ||
public class NotExpressionNode implements ExpressionNode { | ||
private final ExpressionNode expressionNode; | ||
|
||
@JsonCreator | ||
public NotExpressionNode( | ||
@JsonProperty(value = "expression", required = true) ExpressionNode expressionNode) { | ||
this.expressionNode = requireNonNull(expressionNode); | ||
} | ||
|
||
@Override | ||
public Expression createExpression(ActionEnvironment actionEnvironment) { | ||
return new NotExpression(expressionNode.createExpression(actionEnvironment)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...-node/src/main/java/me/retrodaredevil/action/node/expression/result/ExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package me.retrodaredevil.action.node.expression.result; | ||
|
||
public interface ExpressionResult { | ||
@Override | ||
boolean equals(Object other); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...n/java/me/retrodaredevil/action/node/expression/result/SimpleNumericExpressionResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package me.retrodaredevil.action.node.expression.result; | ||
|
||
import java.util.Objects; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
final class SimpleNumericExpressionResult implements NumericExpressionResult { | ||
private final Number number; | ||
|
||
SimpleNumericExpressionResult(Number number) { | ||
this.number = requireNonNull(number); | ||
} | ||
|
||
@Override | ||
public Number getNumber() { | ||
return number; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof NumericExpressionResult)) return false; | ||
NumericExpressionResult that = (NumericExpressionResult) o; | ||
Number thatNumber = that.getNumber(); | ||
return number.equals(thatNumber) || number.doubleValue() == thatNumber.doubleValue(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(number.doubleValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
queue { | ||
race { | ||
racer(all : eq(const(5), const(5.0))) : print("5 = 5.0!") | ||
racer(pass) : print("This should not happen!") | ||
} | ||
race { | ||
racer(all : eq(const(4), const(5.0))) : print("4 = 5.0! (bad)") | ||
racer(all : not : eq(const(4), const(5.0))) : print("4 != 5.0!") | ||
racer(pass) : print("This should not happen!") | ||
} | ||
|
||
race { | ||
racer(all : eq(const("hello"), const hello)) : print("hello = hello") | ||
racer(pass) : print("This should not happen!") | ||
} | ||
race { | ||
racer(all : eq(const("Hello"), const hello)) : print("Hello = hello (bad)") | ||
racer(all : not : eq(const("Hello"), const hello)) : print("Hello != hello") | ||
racer(pass) : print("This should not happen!") | ||
} | ||
} |