From 6dcd129a10af0034b38bfe843d223c4593deee09 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Thu, 12 Nov 2020 20:05:01 -0500 Subject: Cleanup part 2 --- base/src/main/java/bjc/utils/gen/WeightedRandom.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 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 b17017b..969020e 100644 --- a/base/src/main/java/bjc/utils/gen/WeightedRandom.java +++ b/base/src/main/java/bjc/utils/gen/WeightedRandom.java @@ -38,8 +38,7 @@ public class WeightedRandom { public WeightedRandom(Random src) { values = new FunctionalList<>(); - if (src == null) - throw new NullPointerException("Source of randomness must not be null"); + if (src == null) throw new NullPointerException("Source of randomness must not be null"); source = src; } @@ -156,12 +155,10 @@ public class WeightedRandom { * @return A random value. */ public E getDescent(int factor, Random rn) { - if (values.getSize() == 0) - return null; + if (values.getSize() == 0) return null; for (IPair val : values) { - if (rn.nextInt(factor) == 0) - continue; + if (rn.nextInt(factor) == 0) continue; if (exhaust) { totalChance -= val.getLeft(); @@ -173,8 +170,7 @@ public class WeightedRandom { } IPair val = values.getByIndex(values.getSize() - 1); - if (exhaust) - values.removeMatching(val); + if (exhaust) values.removeMatching(val); return val.getRight(); } @@ -214,8 +210,7 @@ public class WeightedRandom { * @return The value at the index corresponding to the number of successes. */ public E getBinomial(int target, int bound, int trials, Random rn) { - if (values.getSize() == 0) - return null; + if (values.getSize() == 0) return null; int numSuc = 0; @@ -254,9 +249,7 @@ public class WeightedRandom { */ public WeightedRandom exhaustible() { IList> lst = new FunctionalList<>(); - for (IPair val : values) { - lst.add(val); - } + for (IPair val : values) lst.add(val); WeightedRandom res = new WeightedRandom<>(source, lst, totalChance); -- cgit v1.2.3