From 8923edffdb36b790014ff47301e53f7ede93ea0d Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Wed, 11 Oct 2017 22:49:16 -0300 Subject: Cleanup more --- .../main/java/bjc/utils/gen/WeightedRandom.java | 39 ++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'base/src/main/java/bjc/utils/gen/WeightedRandom.java') diff --git a/base/src/main/java/bjc/utils/gen/WeightedRandom.java b/base/src/main/java/bjc/utils/gen/WeightedRandom.java index 18225ef..abba36a 100644 --- a/base/src/main/java/bjc/utils/gen/WeightedRandom.java +++ b/base/src/main/java/bjc/utils/gen/WeightedRandom.java @@ -15,32 +15,25 @@ import bjc.utils.funcdata.IList; * @author ben * * @param - * The type of values that are randomly selected. + * The type of values that are randomly selected. */ public class WeightedRandom { - /* - * The list of probabilities for each result - */ + /* The list of probabilities for each result */ private final IList probabilities; - - /* - * The list of possible results to pick from - */ + /* The list of possible results to pick from */ private final IList results; - /* - * The source for any needed random numbers - */ + /* The source for any needed random numbers */ private final Random source; - + /* The total chance for all values. */ private int totalChance; /** * Create a new weighted random generator with the specified source of - * randomness + * randomness. * * @param src - * The source of randomness to use. + * The source of randomness to use. */ public WeightedRandom(final Random src) { probabilities = new FunctionalList<>(); @@ -55,9 +48,10 @@ public class WeightedRandom { * Add a probability for a specific result to be given. * * @param chance - * The chance to get this result. + * The chance to get this result. + * * @param result - * The result to get when the chance comes up. + * The result to get when the chance comes up. */ public void addProbability(final int chance, final E result) { probabilities.add(chance); @@ -69,11 +63,12 @@ public class WeightedRandom { /** * Generate a weighted random value. * - * @return A random value selected in a weighted fashion. + * @return + * A random value selected in a weighted fashion. */ public E generateValue() { - final IHolder value = new Identity<>(source.nextInt(totalChance)); - final IHolder current = new Identity<>(); + final IHolder value = new Identity<>(source.nextInt(totalChance)); + final IHolder current = new Identity<>(); final IHolder picked = new Identity<>(true); probabilities.forEachIndexed((index, probability) -> { @@ -94,7 +89,8 @@ public class WeightedRandom { /** * Return a list of values that can be generated by this generator * - * @return A list of all the values that can be generated + * @return + * A list of all the values that can be generated */ public IList getResults() { return results; @@ -104,7 +100,8 @@ public class WeightedRandom { * Return a list containing values that can be generated paired with the * probability of those values being generated * - * @return A list of pairs of values and value probabilities + * @return + * A list of pairs of values and value probabilities */ public IList> getValues() { return probabilities.pairWith(results); -- cgit v1.2.3