diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-11-21 18:10:30 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-11-21 18:10:30 -0500 |
| commit | b5c2fb1ed923d43412694729b4445a66fa9f47fc (patch) | |
| tree | 2b9dc847976f3a5f7d7a2d48cff0a50e962efeb0 /dice/src/main/java/bjc/dicelang/neodice/DiePoolFactory.java | |
| parent | 785a1ed2437d9810b39deb376c163e0e3e73160f (diff) | |
Restructure new die implementation
Diffstat (limited to 'dice/src/main/java/bjc/dicelang/neodice/DiePoolFactory.java')
| -rw-r--r-- | dice/src/main/java/bjc/dicelang/neodice/DiePoolFactory.java | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/dice/src/main/java/bjc/dicelang/neodice/DiePoolFactory.java b/dice/src/main/java/bjc/dicelang/neodice/DiePoolFactory.java deleted file mode 100644 index 6d9314d..0000000 --- a/dice/src/main/java/bjc/dicelang/neodice/DiePoolFactory.java +++ /dev/null @@ -1,82 +0,0 @@ -package bjc.dicelang.neodice; - -import java.util.*; - -/** - * Various static functions which create instances of DiePool. - * - * @author Ben Culkin - * - */ -public class DiePoolFactory { - /** - * Create a die pool containing the provided dice. - * - * @param dice The dice to put into the pool. - * - * @return A pool which contains the provided dice. - */ - public static DiePool containing(Die... dice) { - return new FixedDiePool(dice); - } -} - -final class FixedDiePool implements DiePool { - private final Die[] dice; - - public FixedDiePool(Die[] dice) { - this.dice = dice; - } - - @Override - public int[] roll(Random rng) { - int[] results = new int[dice.length]; - - for (int index = 0; index < dice.length; index++) { - results[index] = dice[index].roll(rng); - } - - return results; - } - - @Override - public Die[] contained() { - return dice; - } - - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - - for (int i = 0; i < dice.length; i++) { - Die die = dice[i]; - - builder.append(die); - - // Don't add an extra trailing comma - if (i < dice.length - 1) builder.append(", "); - } - - return builder.toString(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Arrays.hashCode(dice); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - - FixedDiePool other = (FixedDiePool) obj; - - return Arrays.equals(dice, other.dice); - } -}
\ No newline at end of file |
