summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java
diff options
context:
space:
mode:
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java')
-rw-r--r--dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java68
1 files changed, 31 insertions, 37 deletions
diff --git a/dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java b/dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java
index ac630a8..bf9254e 100644
--- a/dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java
+++ b/dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java
@@ -10,30 +10,29 @@ public class OperatorDiceExpression implements IDiceExpression {
/*
* The operator to use for combining the dice
*/
- private DiceExpressionType type;
+ private DiceExpressionType type;
/*
* The dice on the left side of the expression
*/
- private IDiceExpression left;
+ private IDiceExpression left;
/*
* The dice on the right side of the expression
*/
- private IDiceExpression right;
+ private IDiceExpression right;
/**
* Create a new compound expression using the specified parameters
*
* @param rght
- * The die on the right side of the expression
+ * The die on the right side of the expression
* @param lft
- * The die on the left side of the expression
+ * The die on the left side of the expression
* @param type
- * The operator to use for combining the dices
+ * The operator to use for combining the dices
*/
- public OperatorDiceExpression(IDiceExpression rght,
- IDiceExpression lft, DiceExpressionType type) {
+ public OperatorDiceExpression(IDiceExpression rght, IDiceExpression lft, DiceExpressionType type) {
this.right = rght;
this.left = lft;
this.type = type;
@@ -45,42 +44,37 @@ public class OperatorDiceExpression implements IDiceExpression {
* Handle each operator
*/
switch (type) {
- case ADD:
- return right.roll() + left.roll();
- case SUBTRACT:
- return right.roll() - left.roll();
- case MULTIPLY:
- return right.roll() * left.roll();
- case DIVIDE:
- /*
- * Round to keep results as integers. We don't really have
- * any need for floating-point dice, and continuous
- * probability is a pain
- */
- try {
- return right.roll() / left.roll();
- } catch (ArithmeticException aex) {
- UnsupportedOperationException usex = new UnsupportedOperationException(
- "Attempted to divide by zero."
- + " Problematic expression is "
- + left);
+ case ADD:
+ return right.roll() + left.roll();
+ case SUBTRACT:
+ return right.roll() - left.roll();
+ case MULTIPLY:
+ return right.roll() * left.roll();
+ case DIVIDE:
+ /*
+ * Round to keep results as integers. We don't really
+ * have any need for floating-point dice, and continuous
+ * probability is a pain
+ */
+ try {
+ return right.roll() / left.roll();
+ } catch (ArithmeticException aex) {
+ UnsupportedOperationException usex = new UnsupportedOperationException(
+ "Attempted to divide by zero." + " Problematic expression is " + left);
- usex.initCause(aex);
+ usex.initCause(aex);
- throw usex;
- }
- default:
- throw new IllegalArgumentException(
- "Got passed a invalid ScalarExpressionType ("
- + type + "). WAT");
+ throw usex;
+ }
+ default:
+ throw new IllegalArgumentException(
+ "Got passed a invalid ScalarExpressionType (" + type + "). WAT");
}
}
@Override
public String toString() {
- return "dice-exp[type=" + type + ", l="
- + left.toString() + ", r="
- + right.toString() + "]";
+ return "dice-exp[type=" + type + ", l=" + left.toString() + ", r=" + right.toString() + "]";
}
}