diff options
| author | Ben Culkin <scorpress@gmail.com> | 2021-03-13 10:13:01 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2021-03-13 10:13:01 -0500 |
| commit | ee6a9305a1009e6f1e3e99d5de3cfba5305a5d1b (patch) | |
| tree | 814ed2184dbc7c10eff387103e5b5b63cfb2e74f /dice/src/main/java/bjc/dicelang/neodice/die/RerollDie.java | |
| parent | 7efb7b9e997e0977c8343718cd8b5149805ea57b (diff) | |
Update documentation
Also, did the same thing for Die I did for DiePool, where I moved the
specific classes to the same file as the interface.
Diffstat (limited to 'dice/src/main/java/bjc/dicelang/neodice/die/RerollDie.java')
| -rw-r--r-- | dice/src/main/java/bjc/dicelang/neodice/die/RerollDie.java | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/dice/src/main/java/bjc/dicelang/neodice/die/RerollDie.java b/dice/src/main/java/bjc/dicelang/neodice/die/RerollDie.java deleted file mode 100644 index 7925c9d..0000000 --- a/dice/src/main/java/bjc/dicelang/neodice/die/RerollDie.java +++ /dev/null @@ -1,92 +0,0 @@ -package bjc.dicelang.neodice.die; - -import java.util.*; -import java.util.function.*; - -import bjc.dicelang.neodice.*; -import bjc.esodata.*; - -public class RerollDie<SideType> implements Die<SideType> { - private final Die<SideType> contained; - - private final Predicate<SideType> condition; - private final Function<MinMaxList<SideType>, SideType> chooser; - - private final Comparator<SideType> comparer; - - private int limit = Integer.MAX_VALUE; - - private RerollDie( - Comparator<SideType> comparer, - Die<SideType> contained, - Predicate<SideType> condition, - Function<MinMaxList<SideType>, SideType> chooser) { - this.comparer = comparer; - - this.contained = contained; - - this.condition = condition; - this.chooser = chooser; - } - - private RerollDie( - Comparator<SideType> comparer, - Die<SideType> contained, - Predicate<SideType> condition, - Function<MinMaxList<SideType>, SideType> chooser, - int limit) { - this(comparer, contained, condition, chooser); - - this.limit = limit; - } - - @Override - public SideType roll(Random rng) { - SideType roll = contained.roll(rng); - - MinMaxList<SideType> newRolls = new MinMaxList<>(comparer, roll); - - int rerollCount = 0; - while (condition.test(roll) && rerollCount < limit) { - roll = contained.roll(rng); - newRolls.add(roll); - - rerollCount += 1; - } - - return chooser.apply(newRolls); - } - - public static <Side extends Comparable<Side>> Die<Side> create( - Die<Side> contained, - Predicate<Side> condition, - Function<MinMaxList<Side>, Side> chooser) { - return new RerollDie<>(Comparator.naturalOrder(), contained, condition, chooser); - } - - public static <Side extends Comparable<Side>> Die<Side> create( - Die<Side> contained, - Predicate<Side> condition, - Function<MinMaxList<Side>, Side> chooser, - int limit) { - return new RerollDie<>(Comparator.naturalOrder(), contained, condition, chooser, limit); - } - - - public static <Side> Die<Side> create( - Comparator<Side> comparer, - Die<Side> contained, - Predicate<Side> condition, - Function<MinMaxList<Side>, Side> chooser) { - return new RerollDie<Side>(comparer, contained, condition, chooser); - } - - public static <Side> Die<Side> create( - Comparator<Side> comparer, - Die<Side> contained, - Predicate<Side> condition, - Function<MinMaxList<Side>, Side> chooser, - int limit) { - return new RerollDie<Side>(comparer, contained, condition, chooser, limit); - } -}
\ No newline at end of file |
