From 38f1e562bf1e1d9d2c837317fced7467f2e81adc Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Thu, 3 Dec 2020 19:24:23 -0500 Subject: Rename interfaces to match Java style Renames several interfaces named in the IWhatever style, which Java doesn't use --- dice/src/main/java/bjc/dicelang/neodice/IDie.java | 96 ----------------------- 1 file changed, 96 deletions(-) delete mode 100644 dice/src/main/java/bjc/dicelang/neodice/IDie.java (limited to 'dice/src/main/java/bjc/dicelang/neodice/IDie.java') diff --git a/dice/src/main/java/bjc/dicelang/neodice/IDie.java b/dice/src/main/java/bjc/dicelang/neodice/IDie.java deleted file mode 100644 index 274af66..0000000 --- a/dice/src/main/java/bjc/dicelang/neodice/IDie.java +++ /dev/null @@ -1,96 +0,0 @@ -package bjc.dicelang.neodice; - -import java.util.*; -import java.util.function.*; -import java.util.stream.*; - -import bjc.dicelang.neodice.die.*; -import bjc.dicelang.neodice.diepool.*; - -/** - * Represents a single polyhedral die. - * @author Ben Culkin - * - */ -@FunctionalInterface -public interface IDie { - /** - * Rolls this die. - * - * @param rng The source for random numbers - * - * @return The result of rolling the die. - */ - public SideType roll(Random rng); - - /** - * Returns a die pool which rolls this die the specified number of times. - * - * @param numTimes The number of times to roll this die. - * - * @return A die pool that rolls this die the specified number of times. - */ - default IDiePool times(int numTimes) { - return new ExpandDiePool<>(this, (die, rng) -> { - return Stream.generate(() -> die.roll(rng)) - .limit(numTimes); - }); - }; - - /** - * Returns a die which will reroll this die as long as the provided condition is true. - * - * @param condition The condition to reroll the die on. - * - * @return A die that rerolls when the given condition is met. - */ - default IDie reroll( - Comparator comparer, - Predicate condition) { - return RerollDie.create(comparer, this, condition, - (list) -> list.get(list.size())); - } - - /** - * Returns a die which will reroll this die up to a specified number of times, - * as long as the provided condition is true. - * - * @param condition The condition to reroll the die on. - * @param limit The maximum number of times to reroll the die. - * - * @return A die that rerolls when the given condition is met. - */ - default IDie reroll( - Comparator comparer, - Predicate condition, - int limit) { - return RerollDie.create(comparer, this, condition, - (list) -> list.get(list.size()), limit); - } - - /** - * Create an stream which gives rolls of this dice. - * - * @param rng The source for random numbers. - * - * @return An iterator which gives rolls of this dice. - */ - default Stream stream(Random rng) { - return Stream.generate(() -> this.roll(rng)); - } - - default IDie transform(Function mapper) { - return (rng) -> mapper.apply(this.roll(rng)); - } - - /** - * Create a simple polyhedral die with a fixed number of sides. - * - * @param sides The number of sides for the die. - * - * @return A die which returns a result from 1 to sides. - */ - static IDie polyhedral(int sides) { - return new PolyhedralDie(sides); - } -} \ No newline at end of file -- cgit v1.2.3