diff options
| author | Ben Culkin <scorpress@gmail.com> | 2021-03-13 09:11:12 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2021-03-13 09:11:12 -0500 |
| commit | 7efb7b9e997e0977c8343718cd8b5149805ea57b (patch) | |
| tree | 869ba045f07a6c5aa8a9c6d388941cc5a4862192 /dice/src/main/java/bjc/dicelang/neodice/diepool | |
| parent | c7c7503bd4a31e88924514d8e6fd4885fcfac042 (diff) | |
Add more documentation
Also, changed my mind on the way DiePool and its implementations should
be structured. The implementations go in the die pool file as internal
classes, because nobody should particularly care the specifics about
their die pool, only that it does what it says it should
Diffstat (limited to 'dice/src/main/java/bjc/dicelang/neodice/diepool')
4 files changed, 0 insertions, 187 deletions
diff --git a/dice/src/main/java/bjc/dicelang/neodice/diepool/ExpandDiePool.java b/dice/src/main/java/bjc/dicelang/neodice/diepool/ExpandDiePool.java deleted file mode 100644 index 97acc79..0000000 --- a/dice/src/main/java/bjc/dicelang/neodice/diepool/ExpandDiePool.java +++ /dev/null @@ -1,25 +0,0 @@ -package bjc.dicelang.neodice.diepool; - -import java.util.*; -import java.util.function.*; -import java.util.stream.*; - -import bjc.dicelang.neodice.*; - -public class ExpandDiePool<SideType> implements DiePool<SideType> { - private final Die<SideType> contained; - - private final BiFunction<Die<SideType>, Random, Stream<SideType>> expander; - - public ExpandDiePool(Die<SideType> contained, - BiFunction<Die<SideType>, Random, Stream<SideType>> expander) { - this.contained = contained; - this.expander = expander; - } - - - @Override - public Stream<SideType> roll(Random rng) { - return expander.apply(contained, rng); - } -} diff --git a/dice/src/main/java/bjc/dicelang/neodice/diepool/FixedDiePool.java b/dice/src/main/java/bjc/dicelang/neodice/diepool/FixedDiePool.java deleted file mode 100644 index 4950407..0000000 --- a/dice/src/main/java/bjc/dicelang/neodice/diepool/FixedDiePool.java +++ /dev/null @@ -1,56 +0,0 @@ -package bjc.dicelang.neodice.diepool; - -import java.util.*; -import java.util.stream.*; - -import bjc.dicelang.neodice.*; - -public class FixedDiePool<SideType> implements DiePool<SideType> { - private final List<Die<SideType>> dice; - - public FixedDiePool(List<Die<SideType>> dice) { - this.dice = dice; - } - - @SafeVarargs - public FixedDiePool(Die<SideType>...dice) { - this.dice = new ArrayList<>(dice.length); - for (Die<SideType> die : dice) { - this.dice.add(die); - } - } - - @Override - public Stream<SideType> roll(Random rng) { - return dice.stream().map((die) -> die.roll(rng)); - } - - @Override - public List<Die<SideType>> contained() { - return dice; - } - - - @Override - public String toString() { - return dice.stream() - .map(Die<SideType>::toString) - .collect(Collectors.joining(", ")); - } - - @Override - public int hashCode() { - return Objects.hash(dice); - } - - @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 Objects.equals(dice, other.dice); - } -}
\ No newline at end of file diff --git a/dice/src/main/java/bjc/dicelang/neodice/diepool/TimesDiePool.java b/dice/src/main/java/bjc/dicelang/neodice/diepool/TimesDiePool.java deleted file mode 100644 index e039e47..0000000 --- a/dice/src/main/java/bjc/dicelang/neodice/diepool/TimesDiePool.java +++ /dev/null @@ -1,54 +0,0 @@ -package bjc.dicelang.neodice.diepool; - -import java.util.*; -import java.util.stream.*; - -import bjc.dicelang.neodice.*; - -public class TimesDiePool<SideType> implements DiePool<SideType> { - private final Die<SideType> contained; - private final int numDice; - - public TimesDiePool(Die<SideType> contained, int numDice) { - this.contained = contained; - this.numDice = numDice; - } - - @Override - public Stream<SideType> roll(Random rng) { - return Stream.generate(() -> contained.roll(rng)) - .limit(numDice); - } - - @Override - public List<Die<SideType>> contained() { - List<Die<SideType>> results = new ArrayList<>(numDice); - - for (int index = 0; index < numDice; index++) { - results.add(contained); - } - - return results; - } - - @Override - public String toString() { - return String.format("%d%s", numDice, contained); - } - - @Override - public int hashCode() { - return Objects.hash(contained, numDice); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - - TimesDiePool<?> other = (TimesDiePool<?>) obj; - - return Objects.equals(contained, other.contained) && numDice == other.numDice; - } -}
\ No newline at end of file diff --git a/dice/src/main/java/bjc/dicelang/neodice/diepool/TransformDiePool.java b/dice/src/main/java/bjc/dicelang/neodice/diepool/TransformDiePool.java deleted file mode 100644 index 80b563f..0000000 --- a/dice/src/main/java/bjc/dicelang/neodice/diepool/TransformDiePool.java +++ /dev/null @@ -1,52 +0,0 @@ -package bjc.dicelang.neodice.diepool; - -import java.util.*; -import java.util.function.*; -import java.util.stream.*; - -import bjc.dicelang.neodice.*; - -public class TransformDiePool<SideType> implements DiePool<SideType> { - private final DiePool<SideType> contained; - - private UnaryOperator<Stream<SideType>> transform; - - public TransformDiePool(DiePool<SideType> contained, - UnaryOperator<Stream<SideType>> transform) { - super(); - this.contained = contained; - this.transform = transform; - } - - @Override - public Stream<SideType> roll(Random rng) { - return transform.apply(contained.roll(rng)); - } - - @Override - public List<Die<SideType>> contained() { - return contained.contained(); - } - - @Override - public int hashCode() { - return Objects.hash(contained, transform); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - - TransformDiePool<?> other = (TransformDiePool<?>) obj; - - return Objects.equals(contained, other.contained) - && Objects.equals(transform, other.transform); - } - - @Override - public String toString() { - return contained.toString() + "(transformed)"; - } -} |
