diff options
| author | EVE <EVE@EVE-PC> | 2017-03-13 16:41:45 -0400 |
|---|---|---|
| committer | EVE <EVE@EVE-PC> | 2017-03-13 16:41:45 -0400 |
| commit | 01136c6796e21f023713e026674576d8e623462d (patch) | |
| tree | e77886fe0e0adaf3c0430fba9ce248ef83f74fe4 /dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java | |
| parent | 870d769cfc152171d27b2331a7c590d0b307ad48 (diff) | |
Formatting
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/v1/OperatorDiceExpression.java | 68 |
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() + "]"; } } |
