diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-17 15:57:20 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-17 15:57:20 -0400 |
| commit | d9437c1d328ccc2b26bd0aae19c2aff7140e466b (patch) | |
| tree | a2292224ba16766fe3dc99140e90089e24aea9c7 /dice-lang/src/main/java/bjc/dicelang/CompoundDice.java | |
| parent | 4fcefd106eb23295592e9cc23a0c5d63a28f9e76 (diff) | |
Minor cleanups
Diffstat (limited to 'dice-lang/src/main/java/bjc/dicelang/CompoundDice.java')
| -rw-r--r-- | dice-lang/src/main/java/bjc/dicelang/CompoundDice.java | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/dice-lang/src/main/java/bjc/dicelang/CompoundDice.java b/dice-lang/src/main/java/bjc/dicelang/CompoundDice.java index 6f7319a..8d2aadd 100644 --- a/dice-lang/src/main/java/bjc/dicelang/CompoundDice.java +++ b/dice-lang/src/main/java/bjc/dicelang/CompoundDice.java @@ -13,48 +13,65 @@ public class CompoundDice implements IDiceExpression { /** * The left die of the expression */ - private IDiceExpression l; + private IDiceExpression leftDice; /** * The right die of the expression */ - private IDiceExpression r; + private IDiceExpression rightDice; /** * Create a new compound dice using the specified dice * - * @param l + * @param left * The die to use on the left - * @param r + * @param right * The die to use on the right */ - public CompoundDice(IDiceExpression l, IDiceExpression r) { - this.l = l; - this.r = r; + public CompoundDice(IDiceExpression left, IDiceExpression right) { + this.leftDice = left; + this.rightDice = right; } /** * Create a new compound dice from two dice strings * - * @param l - * The left side dice - * @param r - * The right side dice + * @param leftExp + * The left side dice as a string + * @param rightExp + * The right side dice as a string */ - public CompoundDice(String l, String r) { - this(ComplexDice.fromString(l), ComplexDice.fromString(r)); + public CompoundDice(String leftExp, String rightExp) { + this(ComplexDice.fromString(leftExp), + ComplexDice.fromString(rightExp)); } /** * Create a new compound dice from an array of dice strings * * @param exps - * An array of dice strings + * An array of two dice strings */ public CompoundDice(String[] exps) { this(exps[0], exps[1]); } + @Override + public boolean canOptimize() { + return leftDice.canOptimize() && rightDice.canOptimize(); + } + + @Override + public int optimize() { + if (!canOptimize()) { + throw new UnsupportedOperationException( + "Cannot optimize this compound dice"); + } + + return Integer + .parseInt(leftDice.optimize() + "" + rightDice.optimize()); + } + /* * (non-Javadoc) * @@ -65,7 +82,7 @@ public class CompoundDice implements IDiceExpression { /* * Make the combination of the two dice */ - return Integer.parseInt(l.roll() + "" + r.roll()); + return Integer.parseInt(leftDice.roll() + "" + rightDice.roll()); } /* @@ -75,16 +92,7 @@ public class CompoundDice implements IDiceExpression { */ @Override public String toString() { - return "compound[l=" + l.toString() + ", r=" + r.toString() + "]"; - } - - @Override - public int optimize() { - return Integer.parseInt(l.optimize() + "" + r.optimize()); - } - - @Override - public boolean canOptimize() { - return l.canOptimize() && r.canOptimize(); + return "compound[l=" + leftDice.toString() + ", r=" + + rightDice.toString() + "]"; } }
\ No newline at end of file |
