summaryrefslogtreecommitdiff
path: root/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-04-22 14:48:25 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-04-22 14:48:25 -0400
commit0fa4f162f4e42a455dbb7e7459854b9467337863 (patch)
tree64e22da06f641f2ad1d2e1f0dc6f818b404c8661 /dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java
parenta3e0b3da5d7b0ec8dcae92a428f8e3f1c6cd6e8e (diff)
Formatting changes
Diffstat (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java')
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java96
1 files changed, 48 insertions, 48 deletions
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java
index 87cbeb1..c97471d 100644
--- a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java
+++ b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java
@@ -49,20 +49,40 @@ final class ArithmeticCollapser implements IOperatorCollapser {
return reducedState;
}
- private IPair<IResult, ITree<IDiceASTNode>> reduceStates(
- IPair<IResult, ITree<IDiceASTNode>> accumulatedState,
- IPair<IResult, ITree<IDiceASTNode>> currentState) {
- return accumulatedState
- .bind((accumulatedValue, accumulatedTree) -> {
- return currentState
- .bind((currentValue, currentTree) -> {
- accumulatedTree.addChild(currentTree);
+ private IFunctionalList<IResult> combineArrayResults(
+ IResult accumulatedValue, IResult currentValue) {
+ IFunctionalList<IResult> currentList = ((ArrayResult) currentValue)
+ .getValue();
+ IFunctionalList<IResult> accumulatedList = ((ArrayResult) accumulatedValue)
+ .getValue();
- return doArithmeticCollapse(
- accumulatedValue, accumulatedTree,
- currentValue);
- });
+ if (currentList.getSize() != accumulatedList.getSize()) {
+ throw new UnsupportedOperationException(
+ "Can only apply operations to equal-length arrays");
+ }
+
+ IFunctionalList<IResult> resultList = currentList.combineWith(
+ accumulatedList, (currentNode, accumulatedNode) -> {
+ boolean currentNotInt = currentNode
+ .getType() != ResultType.INTEGER;
+ boolean accumulatedNotInt = accumulatedNode
+ .getType() != ResultType.INTEGER;
+
+ if (currentNotInt || accumulatedNotInt) {
+ throw new UnsupportedOperationException(
+ "Nesting of array operations isn't allowed");
+ }
+
+ int accumulatedInt = ((IntegerResult) accumulatedNode)
+ .getValue();
+ int currentInt = ((IntegerResult) currentNode)
+ .getValue();
+
+ IResult combinedValue = new IntegerResult(
+ valueOp.apply(accumulatedInt, currentInt));
+ return combinedValue;
});
+ return resultList;
}
private IPair<IResult, ITree<IDiceASTNode>> doArithmeticCollapse(
@@ -106,42 +126,6 @@ final class ArithmeticCollapser implements IOperatorCollapser {
accumulatedTree);
}
- private IFunctionalList<IResult> combineArrayResults(
- IResult accumulatedValue, IResult currentValue) {
- IFunctionalList<IResult> currentList = ((ArrayResult) currentValue)
- .getValue();
- IFunctionalList<IResult> accumulatedList = ((ArrayResult) accumulatedValue)
- .getValue();
-
- if (currentList.getSize() != accumulatedList.getSize()) {
- throw new UnsupportedOperationException(
- "Can only apply operations to equal-length arrays");
- }
-
- IFunctionalList<IResult> resultList = currentList.combineWith(
- accumulatedList, (currentNode, accumulatedNode) -> {
- boolean currentNotInt = currentNode
- .getType() != ResultType.INTEGER;
- boolean accumulatedNotInt = accumulatedNode
- .getType() != ResultType.INTEGER;
-
- if (currentNotInt || accumulatedNotInt) {
- throw new UnsupportedOperationException(
- "Nesting of array operations isn't allowed");
- }
-
- int accumulatedInt = ((IntegerResult) accumulatedNode)
- .getValue();
- int currentInt = ((IntegerResult) currentNode)
- .getValue();
-
- IResult combinedValue = new IntegerResult(
- valueOp.apply(accumulatedInt, currentInt));
- return combinedValue;
- });
- return resultList;
- }
-
private IFunctionalList<IResult> halfCombineLists(
IFunctionalList<IResult> list, IResult scalar,
boolean scalarLeft) {
@@ -172,4 +156,20 @@ final class ArithmeticCollapser implements IOperatorCollapser {
return combinedValue;
});
}
+
+ private IPair<IResult, ITree<IDiceASTNode>> reduceStates(
+ IPair<IResult, ITree<IDiceASTNode>> accumulatedState,
+ IPair<IResult, ITree<IDiceASTNode>> currentState) {
+ return accumulatedState
+ .bind((accumulatedValue, accumulatedTree) -> {
+ return currentState
+ .bind((currentValue, currentTree) -> {
+ accumulatedTree.addChild(currentTree);
+
+ return doArithmeticCollapse(
+ accumulatedValue, accumulatedTree,
+ currentValue);
+ });
+ });
+ }
} \ No newline at end of file