summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-09-09 21:46:16 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-09-09 21:47:34 -0300
commitd766896972c9e9be4a9e0021ec5f4f0665901865 (patch)
tree1f6473300ef86e0697d682360bea0d28fc144baa /BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
parent40f3a28569366c4357fbda11d2fff3b77686d84f (diff)
Update
Most of it is documentation changes. The rest is more work on BlockReaders, as well as a simple command language for configuring them.
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java45
1 files changed, 30 insertions, 15 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
index 52a2437..c0daa1e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
@@ -95,13 +95,19 @@ public class ListUtils {
E element = null;
for (final int index = 0; itr.hasNext(); element = itr.next()) {
- // n - m
+ /*
+ * n - m
+ */
final int winningChance = number - selected.getSize();
- // N - t
+ /*
+ * N - t
+ */
final int totalChance = total - (index - 1);
- // Probability of selecting the t+1'th element
+ /*
+ * Probability of selecting the t+1'th element
+ */
if (NumberUtils.isProbable(winningChance, totalChance, rng)) {
selected.add(element);
}
@@ -185,17 +191,20 @@ public class ListUtils {
&& !rejected.isEmpty(); numberOfIterations++) {
input.forEach(it);
- if (rejected.isEmpty()) // Nothing was rejected, so
- // we're
- // done
+ if (rejected.isEmpty()) {
+ /*
+ * Nothing was rejected, so we're done
+ */
return returned;
+ }
}
- throw new IllegalArgumentException("Heuristic (more than " + MAX_NTRIESPART
- + " iterations of partitioning) detected unpartitionable list " + input.toString()
- + "\nThe following elements were not partitioned: " + rejected.toString()
- + "\nCurrent group in formation: " + it.currentPartition.toString()
- + "\nPreviously formed groups: " + returned.toString());
+
+ final String fmt = "Heuristic (more than %d iterations of partitioning) detected an unpartitionable list. (%s)\nThe following elements were not partitioned: %s\nCurrent group in formation: %s\nPreviously formed groups: %s\n";
+
+ final String msg = String.format(fmt, MAX_NTRIESPART, input.toString(), rejected.toString(), it.currentPartition.toString(), returned.toString());
+
+ throw new IllegalArgumentException(msg);
}
/**
@@ -250,7 +259,9 @@ public class ListUtils {
}
if (count % size != 0) {
- // We need to pad
+ /*
+ * We need to pad
+ */
int needed = count % size;
int threshold = 0;
@@ -269,9 +280,13 @@ public class ListUtils {
}
}
- if (threshold > MAX_NTRIESPART)
- throw new IllegalArgumentException("Heuristic (more than " + MAX_NTRIESPART
- + " iterations of attempting to pad) detected unpaddable list ");
+ if (threshold > MAX_NTRIESPART) {
+ final String fmt = "Heuristic (more than %d iterations of attempting to pad) detected an unpaddable list. (%s)\nPartially padded list: %S";
+
+ final String msg = String.format(fmt, MAX_NTRIESPART, list.toString(), returned.toString());
+
+ throw new IllegalArgumentException(msg);
+ }
}
return returned;