summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/funcutils
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/bjc/utils/funcutils')
-rw-r--r--base/src/main/java/bjc/utils/funcutils/CollectorUtils.java17
-rw-r--r--base/src/main/java/bjc/utils/funcutils/CompoundCollector.java16
-rw-r--r--base/src/main/java/bjc/utils/funcutils/EnumUtils.java21
-rw-r--r--base/src/main/java/bjc/utils/funcutils/FileUtils.java19
-rw-r--r--base/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java12
-rw-r--r--base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java25
-rw-r--r--base/src/main/java/bjc/utils/funcutils/IBuilder.java11
-rw-r--r--base/src/main/java/bjc/utils/funcutils/Isomorphism.java22
-rw-r--r--base/src/main/java/bjc/utils/funcutils/LambdaLock.java16
-rw-r--r--base/src/main/java/bjc/utils/funcutils/ListUtils.java126
-rw-r--r--base/src/main/java/bjc/utils/funcutils/NumberUtils.java28
-rw-r--r--base/src/main/java/bjc/utils/funcutils/StringUtils.java74
-rw-r--r--base/src/main/java/bjc/utils/funcutils/TreeUtils.java3
-rw-r--r--base/src/main/java/bjc/utils/funcutils/TriConsumer.java12
14 files changed, 192 insertions, 210 deletions
diff --git a/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java b/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java
index 2da5967..419c216 100644
--- a/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java
@@ -15,28 +15,27 @@ public class CollectorUtils {
* Create a collector that applies two collectors at once.
*
* @param <InitialType>
- * The type of the collection to collect from.
+ * The type of the collection to collect from.
*
* @param <AuxType1>
- * The intermediate type of the first collector.
+ * The intermediate type of the first collector.
*
* @param <AuxType2>
- * The intermediate type of the second collector.
+ * The intermediate type of the second collector.
*
* @param <FinalType1>
- * The final type of the first collector.
+ * The final type of the first collector.
*
* @param <FinalType2>
- * The final type of the second collector.
+ * The final type of the second collector.
*
* @param first
- * The first collector to use.
+ * The first collector to use.
*
* @param second
- * The second collector to use.
+ * The second collector to use.
*
- * @return
- * A collector that functions as mentioned above.
+ * @return A collector that functions as mentioned above.
*/
public static <InitialType, AuxType1, AuxType2, FinalType1, FinalType2> Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> compoundCollect(
final Collector<InitialType, AuxType1, FinalType1> first,
diff --git a/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java b/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java
index 928c3f4..53b4b8d 100644
--- a/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java
+++ b/base/src/main/java/bjc/utils/funcutils/CompoundCollector.java
@@ -12,7 +12,7 @@ import bjc.utils.data.IPair;
import bjc.utils.data.Identity;
import bjc.utils.data.Pair;
-/**
+/**
* Implementation of a collecter that uses two collectors.
*
* @author Ben Culkin
@@ -22,7 +22,7 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final
/* Our characteristics. */
private final Set<java.util.stream.Collector.Characteristics> characteristicSet;
- /* The first collector. */
+ /* The first collector. */
private final Collector<InitialType, AuxType1, FinalType1> first;
/* The second collector. */
private final Collector<InitialType, AuxType2, FinalType2> second;
@@ -31,10 +31,10 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final
* Create a collector that uses two collectors.
*
* @param first
- * The first collector.
+ * The first collector.
*
* @param second
- * The second collector.
+ * The second collector.
*/
public CompoundCollector(final Collector<InitialType, AuxType1, FinalType1> first,
final Collector<InitialType, AuxType2, FinalType2> second) {
@@ -48,7 +48,7 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final
@Override
public BiConsumer<IHolder<IPair<AuxType1, AuxType2>>, InitialType> accumulator() {
- final BiConsumer<AuxType1, InitialType> firstAccumulator = first.accumulator();
+ final BiConsumer<AuxType1, InitialType> firstAccumulator = first.accumulator();
final BiConsumer<AuxType2, InitialType> secondAccumulator = second.accumulator();
return (state, value) -> {
@@ -68,7 +68,7 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final
@Override
public BinaryOperator<IHolder<IPair<AuxType1, AuxType2>>> combiner() {
- final BinaryOperator<AuxType1> firstCombiner = first.combiner();
+ final BinaryOperator<AuxType1> firstCombiner = first.combiner();
final BinaryOperator<AuxType2> secondCombiner = second.combiner();
return (leftState, rightState) -> {
@@ -85,7 +85,7 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final
return state -> {
return state.unwrap(pair -> {
return pair.bind((left, right) -> {
- final FinalType1 finalLeft = first.finisher().apply(left);
+ final FinalType1 finalLeft = first.finisher().apply(left);
final FinalType2 finalRight = second.finisher().apply(right);
return new Pair<>(finalLeft, finalRight);
@@ -97,7 +97,7 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final
@Override
public Supplier<IHolder<IPair<AuxType1, AuxType2>>> supplier() {
return () -> {
- final AuxType1 initialLeft = first.supplier().get();
+ final AuxType1 initialLeft = first.supplier().get();
final AuxType2 initialRight = second.supplier().get();
return new Identity<>(new Pair<>(initialLeft, initialRight));
diff --git a/base/src/main/java/bjc/utils/funcutils/EnumUtils.java b/base/src/main/java/bjc/utils/funcutils/EnumUtils.java
index 2039b97..20c5972 100644
--- a/base/src/main/java/bjc/utils/funcutils/EnumUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/EnumUtils.java
@@ -16,19 +16,19 @@ public class EnumUtils {
* Do an action for a random number of enum values.
*
* @param <E>
- * The type of the enum.
+ * The type of the enum.
*
* @param clasz
- * The enum class.
+ * The enum class.
*
* @param nValues
- * The number of values to execute the action on.
+ * The number of values to execute the action on.
*
* @param action
- * The action to perform on random values.
+ * The action to perform on random values.
*
* @param rnd
- * The source of randomness to use.
+ * The source of randomness to use.
*/
public static <E extends Enum<E>> void doForValues(final Class<E> clasz, final int nValues,
final Consumer<E> action, final Random rnd) {
@@ -38,7 +38,7 @@ public class EnumUtils {
final int randomValueCount = enumValues.length - nValues;
- for (int i = 0; i <= randomValueCount; i++) {
+ for(int i = 0; i <= randomValueCount; i++) {
final E rDir = valueList.randItem(rnd::nextInt);
valueList.removeMatching(rDir);
@@ -51,16 +51,15 @@ public class EnumUtils {
* Get a random value from an enum.
*
* @param <E>
- * The type of the enum.
+ * The type of the enum.
*
* @param clasz
- * The class of the enum.
+ * The class of the enum.
*
* @param rnd
- * The random source to use.
+ * The random source to use.
*
- * @return
- * A random value from the specified enum.
+ * @return A random value from the specified enum.
*/
public static <E extends Enum<E>> E getRandomValue(final Class<E> clasz, final Random rnd) {
final E[] enumValues = clasz.getEnumConstants();
diff --git a/base/src/main/java/bjc/utils/funcutils/FileUtils.java b/base/src/main/java/bjc/utils/funcutils/FileUtils.java
index 6b897df..0fd3db0 100644
--- a/base/src/main/java/bjc/utils/funcutils/FileUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/FileUtils.java
@@ -13,27 +13,26 @@ import java.util.function.BiPredicate;
*/
public class FileUtils {
/*
- * @NOTE
- * If it becomes necessary, write another overload
- * for this with all the buttons and knobs from
- * walkFileTree.
+ * @NOTE If it becomes necessary, write another overload for this with
+ * all the buttons and knobs from walkFileTree.
*/
/**
* Traverse a directory recursively. This is a depth-first traversal.
*
* @param root
- * The directory to start the traversal at.
+ * The directory to start the traversal at.
*
* @param predicate
- * The predicate to determine whether or not to traverse
- * a directory.
+ * The predicate to determine whether or not to traverse a
+ * directory.
*
* @param action
- * The action to invoke upon each file in the directory. Returning
- * true means to continue the traversal, returning false stops it.
+ * The action to invoke upon each file in the directory.
+ * Returning true means to continue the traversal, returning
+ * false stops it.
*
* @throws IOException
- * If the walk throws an exception.
+ * If the walk throws an exception.
*
*/
public static void traverseDirectory(final Path root, final BiPredicate<Path, BasicFileAttributes> predicate,
diff --git a/base/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java b/base/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java
index b0dd162..fb2a697 100644
--- a/base/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java
+++ b/base/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java
@@ -14,18 +14,18 @@ import java.util.function.BiPredicate;
*/
final class FunctionalFileVisitor extends SimpleFileVisitor<Path> {
/* Our predicate to pick files. */
- private final BiPredicate<Path, BasicFileAttributes> predicate;
+ private final BiPredicate<Path, BasicFileAttributes> predicate;
/* Our action to aply to files. */
- private final BiPredicate<Path, BasicFileAttributes> action;
+ private final BiPredicate<Path, BasicFileAttributes> action;
/**
* Create a new file visitor, powered by functions.
*
* @param predicate
- * The predicate to use to pick which files to traverse.
+ * The predicate to use to pick which files to traverse.
*
* @param action
- * The function to execute on every file.
+ * The function to execute on every file.
*/
public FunctionalFileVisitor(final BiPredicate<Path, BasicFileAttributes> predicate,
final BiPredicate<Path, BasicFileAttributes> action) {
@@ -35,14 +35,14 @@ final class FunctionalFileVisitor extends SimpleFileVisitor<Path> {
@Override
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
- if (predicate.test(dir, attrs)) return FileVisitResult.CONTINUE;
+ if(predicate.test(dir, attrs)) return FileVisitResult.CONTINUE;
return FileVisitResult.SKIP_SUBTREE;
}
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
- if (action.test(file, attrs)) return FileVisitResult.CONTINUE;
+ if(action.test(file, attrs)) return FileVisitResult.CONTINUE;
return FileVisitResult.TERMINATE;
}
diff --git a/base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java b/base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
index 9e4b43a..a406c1c 100644
--- a/base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
+++ b/base/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
@@ -12,19 +12,19 @@ import bjc.utils.funcdata.IList;
* @author ben
*
* @param <E>
- * The type of element in the list being partitioned
+ * The type of element in the list being partitioned
*/
final class GroupPartIteration<E> implements Consumer<E> {
/* The list we're returning. */
private final IList<IList<E>> returnedList;
/* The current partition of the list. */
- public IList<E> currentPartition;
+ public IList<E> currentPartition;
/* The items rejected from the current partition. */
private final IList<E> rejectedItems;
/* The number of items in the current partition. */
- private int numberInCurrentPartition;
+ private int numberInCurrentPartition;
/* The number of items in each partition. */
private final int numberPerPartition;
@@ -35,17 +35,18 @@ final class GroupPartIteration<E> implements Consumer<E> {
* Create a new group partitioning iteration.
*
* @param returned
- * The list containing all of the existing partitions.
+ * The list containing all of the existing partitions.
*
* @param rejects
- * The items that have been rejected from a partition for being too
- * large.
+ * The items that have been rejected from a partition for being
+ * too large.
*
* @param nPerPart
- * The combined value of items that should go into each partition.
+ * The combined value of items that should go into each
+ * partition.
*
* @param eleCount
- * The function to use to determine the value of an item.
+ * The function to use to determine the value of an item.
*/
public GroupPartIteration(final IList<IList<E>> returned, final IList<E> rejects, final int nPerPart,
final Function<E, Integer> eleCount) {
@@ -62,7 +63,7 @@ final class GroupPartIteration<E> implements Consumer<E> {
public void accept(final E value) {
final boolean shouldStartPartition = numberInCurrentPartition >= numberPerPartition;
- if (shouldStartPartition) {
+ if(shouldStartPartition) {
returnedList.add(currentPartition);
currentPartition = new FunctionalList<>();
@@ -70,10 +71,10 @@ final class GroupPartIteration<E> implements Consumer<E> {
} else {
final int currentElementCount = elementCounter.apply(value);
- final boolean shouldReject =
- (numberInCurrentPartition + currentElementCount) >= numberPerPartition;
+ final boolean shouldReject = (numberInCurrentPartition
+ + currentElementCount) >= numberPerPartition;
- if (shouldReject) {
+ if(shouldReject) {
rejectedItems.add(value);
} else {
currentPartition.add(value);
diff --git a/base/src/main/java/bjc/utils/funcutils/IBuilder.java b/base/src/main/java/bjc/utils/funcutils/IBuilder.java
index 6cbb838..f8dd2fc 100644
--- a/base/src/main/java/bjc/utils/funcutils/IBuilder.java
+++ b/base/src/main/java/bjc/utils/funcutils/IBuilder.java
@@ -6,18 +6,17 @@ package bjc.utils.funcutils;
* @author ben
*
* @param <E>
- * The type of object being built.
+ * The type of object being built.
*/
public interface IBuilder<E> {
/**
* Build the object this builder is building.
*
- * @return
- * The built object.
+ * @return The built object.
*
* @throws IllegalStateException
- * If the data in the builder cannot be built into its
- * corresponding object at this point in time.
+ * If the data in the builder cannot be built into its
+ * corresponding object at this point in time.
*/
public E build();
@@ -25,7 +24,7 @@ public interface IBuilder<E> {
* Reset the state of this builder to its initial state.
*
* @throws UnsupportedOperationException
- * If the builder doesn't support resetting its state.
+ * If the builder doesn't support resetting its state.
*/
public default void reset() {
throw new UnsupportedOperationException("Builder doesn't support state resetting");
diff --git a/base/src/main/java/bjc/utils/funcutils/Isomorphism.java b/base/src/main/java/bjc/utils/funcutils/Isomorphism.java
index d86ee9f..9559540 100644
--- a/base/src/main/java/bjc/utils/funcutils/Isomorphism.java
+++ b/base/src/main/java/bjc/utils/funcutils/Isomorphism.java
@@ -8,25 +8,25 @@ import java.util.function.Function;
* @author bjculkin
*
* @param <S>
- * The source type of the isomorphism.
+ * The source type of the isomorphism.
*
* @param <D>
- * The destination type of isomorphism.
+ * The destination type of isomorphism.
*/
public class Isomorphism<S, D> {
/* The function to the destination type. */
- private Function<S, D> toFunc;
+ private Function<S, D> toFunc;
/* The function to the source type. */
- private Function<D, S> fromFunc;
+ private Function<D, S> fromFunc;
/**
* Create a new isomorphism.
*
* @param to
- * The 'forward' function, from the source to the definition.
+ * The 'forward' function, from the source to the definition.
*
* @param from
- * The 'backward' function, from the definition to the source.
+ * The 'backward' function, from the definition to the source.
*/
public Isomorphism(Function<S, D> to, Function<D, S> from) {
toFunc = to;
@@ -37,10 +37,9 @@ public class Isomorphism<S, D> {
* Apply the isomorphism forward.
*
* @param val
- * The source value.
+ * The source value.
*
- * @return
- * The destination value.
+ * @return The destination value.
*/
public D to(S val) {
return toFunc.apply(val);
@@ -50,10 +49,9 @@ public class Isomorphism<S, D> {
* Apply the isomorphism backward.
*
* @param val
- * The destination value.
+ * The destination value.
*
- * @return
- * The source value.
+ * @return The source value.
*/
public S from(D val) {
return fromFunc.apply(val);
diff --git a/base/src/main/java/bjc/utils/funcutils/LambdaLock.java b/base/src/main/java/bjc/utils/funcutils/LambdaLock.java
index 2506d53..0130a77 100644
--- a/base/src/main/java/bjc/utils/funcutils/LambdaLock.java
+++ b/base/src/main/java/bjc/utils/funcutils/LambdaLock.java
@@ -26,7 +26,7 @@ public class LambdaLock {
* Create a new lambda-enabled lock.
*
* @param lck
- * The lock to wrap.
+ * The lock to wrap.
*/
public LambdaLock(final ReadWriteLock lck) {
readLock = lck.readLock();
@@ -37,10 +37,9 @@ public class LambdaLock {
* Execute an action with the read lock taken.
*
* @param supp
- * The action to call.
+ * The action to call.
*
- * @return
- * The result of the action.
+ * @return The result of the action.
*/
public <T> T read(final Supplier<T> supp) {
readLock.lock();
@@ -56,10 +55,9 @@ public class LambdaLock {
* Execute an action with the write lock taken.
*
* @param supp
- * The action to call.
+ * The action to call.
*
- * @return
- * The result of the action.
+ * @return The result of the action.
*/
public <T> T write(final Supplier<T> supp) {
writeLock.lock();
@@ -75,7 +73,7 @@ public class LambdaLock {
* Execute an action with the read lock taken.
*
* @param action
- * The action to call.
+ * The action to call.
*/
public void read(final Runnable action) {
readLock.lock();
@@ -91,7 +89,7 @@ public class LambdaLock {
* Execute an action with the write lock taken.
*
* @param action
- * The action to call.
+ * The action to call.
*/
public void write(final Runnable action) {
writeLock.lock();
diff --git a/base/src/main/java/bjc/utils/funcutils/ListUtils.java b/base/src/main/java/bjc/utils/funcutils/ListUtils.java
index 2441a80..20ae7b2 100644
--- a/base/src/main/java/bjc/utils/funcutils/ListUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/ListUtils.java
@@ -23,13 +23,12 @@ public class ListUtils {
* spaces.
*
* @param input
- * The list of tokens to collapse.
+ * The list of tokens to collapse.
*
- * @return
- * The collapsed string of tokens.
+ * @return The collapsed string of tokens.
*/
public static String collapseTokens(final IList<String> input) {
- if (input == null) throw new NullPointerException("Input must not be null");
+ if(input == null) throw new NullPointerException("Input must not be null");
return collapseTokens(input, "");
}
@@ -39,33 +38,32 @@ public class ListUtils {
* separator after each token.
*
* @param input
- * The list of tokens to collapse.
+ * The list of tokens to collapse.
*
* @param seperator
- * The separator to use for separating tokens.
+ * The separator to use for separating tokens.
*
- * @return
- * The collapsed string of tokens.
+ * @return The collapsed string of tokens.
*/
public static String collapseTokens(final IList<String> input, final String seperator) {
- if (input == null) {
+ if(input == null) {
throw new NullPointerException("Input must not be null");
- } else if (seperator == null) {
+ } else if(seperator == null) {
throw new NullPointerException("Seperator must not be null");
}
- if (input.getSize() < 1) {
+ if(input.getSize() < 1) {
return "";
- } else if (input.getSize() == 1) {
+ } else if(input.getSize() == 1) {
return input.first();
} else {
final StringBuilder state = new StringBuilder();
int i = 1;
- for (final String itm : input.toIterable()) {
+ for(final String itm : input.toIterable()) {
state.append(itm);
- if (i != input.getSize()) {
+ if(i != input.getSize()) {
state.append(seperator);
}
@@ -80,21 +78,20 @@ public class ListUtils {
* Select a number of random items from the list without replacement.
*
* @param <E>
- * The type of items to select.
+ * The type of items to select.
*
* @param list
- * The list to select from.
+ * The list to select from.
*
* @param number
- * The number of items to selet.
+ * The number of items to selet.
*
* @param rng
- * A function that creates a random number from 0 to the
- * desired number.
+ * A function that creates a random number from 0 to the desired
+ * number.
*
- * @return
- * A new list containing the desired number of items randomly
- * selected from the specified list without replacement.
+ * @return A new list containing the desired number of items randomly
+ * selected from the specified list without replacement.
*/
public static <E> IList<E> drawWithoutReplacement(final IList<E> list, final int number,
final Function<Integer, Integer> rng) {
@@ -105,7 +102,7 @@ public class ListUtils {
final Iterator<E> itr = list.toIterable().iterator();
E element = null;
- for (final int index = 0; itr.hasNext(); element = itr.next()) {
+ for(final int index = 0; itr.hasNext(); element = itr.next()) {
/* n - m */
final int winningChance = number - selected.getSize();
@@ -113,7 +110,7 @@ public class ListUtils {
final int totalChance = total - (index - 1);
/* Probability of selecting the t+1'th element */
- if (NumberUtils.isProbable(winningChance, totalChance, rng)) {
+ if(NumberUtils.isProbable(winningChance, totalChance, rng)) {
selected.add(element);
}
}
@@ -125,27 +122,26 @@ public class ListUtils {
* Select a number of random items from the list, with replacement.
*
* @param <E>
- * The type of items to select.
+ * The type of items to select.
*
* @param list
- * The list to select from.
+ * The list to select from.
*
* @param number
- * The number of items to select.
+ * The number of items to select.
*
* @param rng
- * A function that creates a random number from 0 to the
- * desired number.
+ * A function that creates a random number from 0 to the desired
+ * number.
*
- * @return
- * A new list containing the desired number of items randomly
- * selected from the specified list.
+ * @return A new list containing the desired number of items randomly
+ * selected from the specified list.
*/
public static <E> IList<E> drawWithReplacement(final IList<E> list, final int number,
final Function<Integer, Integer> rng) {
final IList<E> selected = new FunctionalList<>(new ArrayList<>(number));
- for (int i = 0; i < number; i++) {
+ for(int i = 0; i < number; i++) {
selected.add(list.randItem(rng));
}
@@ -157,27 +153,26 @@ public class ListUtils {
* for more than one element in a partition.
*
* @param <E>
- * The type of elements in the list to partition.
+ * The type of elements in the list to partition.
*
* @param input
- * The list to partition.
+ * The list to partition.
*
* @param counter
- * The function to determine the count for each element for.
+ * The function to determine the count for each element for.
*
* @param partitionSize
- * The number of elements to put in each partition.
+ * The number of elements to put in each partition.
*
- * @return
- * A list partitioned according to the above rules.
+ * @return A list partitioned according to the above rules.
*/
public static <E> IList<IList<E>> groupPartition(final IList<E> input, final Function<E, Integer> counter,
final int partitionSize) {
- if (input == null) {
+ if(input == null) {
throw new NullPointerException("Input list must not be null");
- } else if (counter == null) {
+ } else if(counter == null) {
throw new NullPointerException("Counter must not be null");
- } else if (partitionSize < 1 || partitionSize > input.getSize()) {
+ } else if(partitionSize < 1 || partitionSize > input.getSize()) {
final String fmt = "%d is not a valid partition size. Must be between 1 and %d";
final String msg = String.format(fmt, partitionSize, input.getSize());
@@ -193,20 +188,20 @@ public class ListUtils {
final GroupPartIteration<E> it = new GroupPartIteration<>(returned, rejected, partitionSize, counter);
/* Run up to a certain number of passes. */
- for (int numberOfIterations = 0; numberOfIterations < MAX_NTRIESPART
+ for(int numberOfIterations = 0; numberOfIterations < MAX_NTRIESPART
&& !rejected.isEmpty(); numberOfIterations++) {
input.forEach(it);
- if (rejected.isEmpty()) {
+ if(rejected.isEmpty()) {
/* Nothing was rejected, so we're done. */
return returned;
}
}
-
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());
+ final String msg = String.format(fmt, MAX_NTRIESPART, input.toString(), rejected.toString(),
+ it.currentPartition.toString(), returned.toString());
throw new IllegalArgumentException(msg);
}
@@ -215,20 +210,19 @@ public class ListUtils {
* Merge the contents of a bunch of lists together into a single list.
*
* @param <E>
- * The type of value in this lists.
+ * The type of value in this lists.
*
* @param lists
- * The values in the lists to merge.
+ * The values in the lists to merge.
*
- * @return
- * A list containing all the elements of the lists.
+ * @return A list containing all the elements of the lists.
*/
@SafeVarargs
public static <E> IList<E> mergeLists(final IList<E>... lists) {
final IList<E> returned = new FunctionalList<>();
- for (final IList<E> list : lists) {
- for (final E itm : list.toIterable()) {
+ for(final IList<E> list : lists) {
+ for(final E itm : list.toIterable()) {
returned.add(itm);
}
}
@@ -240,25 +234,24 @@ public class ListUtils {
* Pad the provided list out to the desired size.
*
* @param <E>
- * The type of elements in the list.
+ * The type of elements in the list.
*
* @param list
- * The list to pad out.
+ * The list to pad out.
*
* @param counter
- * The function to count elements with.
+ * The function to count elements with.
*
* @param size
- * The desired size of the list.
+ * The desired size of the list.
*
* @param padder
- * The function to get elements to pad with.
+ * The function to get elements to pad with.
*
- * @return
- * The list, padded to the desired size.
+ * @return The list, padded to the desired size.
*
* @throws IllegalArgumentException
- * If the list couldn't be padded to the desired size.
+ * If the list couldn't be padded to the desired size.
*/
public static <E> IList<E> padList(final IList<E> list, final Function<E, Integer> counter, final int size,
final Supplier<E> padder) {
@@ -266,22 +259,22 @@ public class ListUtils {
final IList<E> returned = new FunctionalList<>();
- for (final E itm : list.toIterable()) {
+ for(final E itm : list.toIterable()) {
count += counter.apply(itm);
returned.add(itm);
}
- if (count % size != 0) {
+ if(count % size != 0) {
/* We need to pad */
int needed = count % size;
int threshold = 0;
- while (needed > 0 && threshold <= MAX_NTRIESPART) {
+ while(needed > 0 && threshold <= MAX_NTRIESPART) {
final E val = padder.get();
final int newCount = counter.apply(val);
- if (newCount <= needed) {
+ if(newCount <= needed) {
returned.add(val);
threshold = 0;
@@ -292,10 +285,11 @@ public class ListUtils {
}
}
- if (threshold > MAX_NTRIESPART) {
+ 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());
+ final String msg = String.format(fmt, MAX_NTRIESPART, list.toString(),
+ returned.toString());
throw new IllegalArgumentException(msg);
}
diff --git a/base/src/main/java/bjc/utils/funcutils/NumberUtils.java b/base/src/main/java/bjc/utils/funcutils/NumberUtils.java
index c3d52fa..c29fafe 100644
--- a/base/src/main/java/bjc/utils/funcutils/NumberUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/NumberUtils.java
@@ -12,23 +12,22 @@ public class NumberUtils {
* Compute the falling factorial of a number.
*
* @param value
- * The number to compute.
+ * The number to compute.
*
* @param power
- * The power to do the falling factorial for.
+ * The power to do the falling factorial for.
*
- * @return
- * The falling factorial of the number to the power.
+ * @return The falling factorial of the number to the power.
*/
public static int fallingFactorial(final int value, final int power) {
- if (power == 0) {
+ if(power == 0) {
return 1;
- } else if (power == 1) {
+ } else if(power == 1) {
return value;
} else {
int result = 1;
- for (int currentSub = 0; currentSub < power + 1; currentSub++) {
+ for(int currentSub = 0; currentSub < power + 1; currentSub++) {
result *= value - currentSub;
}
@@ -40,13 +39,13 @@ public class NumberUtils {
* Evaluates a linear probability distribution.
*
* @param winning
- * The number of winning possibilities.
+ * The number of winning possibilities.
*
* @param total
- * The number of total possibilities.
+ * The number of total possibilities.
*
* @param rng
- * The function to use to generate a random possibility.
+ * The function to use to generate a random possibility.
*
* @return Whether or not a random possibility was a winning one.
*/
@@ -58,16 +57,15 @@ public class NumberUtils {
* Check if a number is in an inclusive range.
*
* @param min
- * The minimum value of the range.
+ * The minimum value of the range.
*
* @param max
- * The maximum value of the range.
+ * The maximum value of the range.
*
* @param i
- * The number to check.
+ * The number to check.
*
- * @return
- * Whether the number is in the range.
+ * @return Whether the number is in the range.
*/
public static boolean between(final int min, final int max, final int i) {
return i >= min && i <= max;
diff --git a/base/src/main/java/bjc/utils/funcutils/StringUtils.java b/base/src/main/java/bjc/utils/funcutils/StringUtils.java
index ba4ebca..fa7e59e 100644
--- a/base/src/main/java/bjc/utils/funcutils/StringUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/StringUtils.java
@@ -17,19 +17,18 @@ public class StringUtils {
* expression.
*
* @param input
- * The string to check.
+ * The string to check.
*
* @param rRegex
- * The regex to see if the string only contains matches of.
+ * The regex to see if the string only contains matches of.
*
- * @return
- * Whether or not the string consists only of multiple matches of
- * the provided regex.
+ * @return Whether or not the string consists only of multiple matches
+ * of the provided regex.
*/
public static boolean containsOnly(final String input, final String rRegex) {
- if (input == null)
+ if(input == null)
throw new NullPointerException("Input must not be null");
- else if (rRegex == null) throw new NullPointerException("Regex must not be null");
+ else if(rRegex == null) throw new NullPointerException("Regex must not be null");
/*
* This regular expression is fairly simple.
@@ -46,13 +45,13 @@ public class StringUtils {
* Indent the string being built in a StringBuilder n levels.
*
* @param builder
- * The builder to indent in.
+ * The builder to indent in.
*
* @param levels
- * The number of levels to indent.
+ * The number of levels to indent.
*/
public static void indentNLevels(final StringBuilder builder, final int levels) {
- for (int i = 0; i < levels; i++) {
+ for(int i = 0; i < levels; i++) {
builder.append("\t");
}
}
@@ -62,14 +61,13 @@ public class StringUtils {
* empty.
*
* @param <ContainedType>
- * The type in the deque.
+ * The type in the deque.
*
* @param queue
- * The deque to print.
+ * The deque to print.
*
- * @return
- * A string version of the deque, with allowance for an empty
- * deque.
+ * @return A string version of the deque, with allowance for an empty
+ * deque.
*/
public static <ContainedType> String printDeque(final Deque<ContainedType> queue) {
return queue.isEmpty() ? "(none)" : queue.toString();
@@ -79,26 +77,26 @@ public class StringUtils {
* Converts a sequence to an English list.
*
* @param objects
- * The sequence to convert to an English list.
+ * The sequence to convert to an English list.
*
* @param join
- * The string to use for separating the last element from the rest.
+ * The string to use for separating the last element from the
+ * rest.
*
* @param comma
- * The string to use as a comma
+ * The string to use as a comma
*
- * @return
- * The sequence as an English list.
+ * @return The sequence as an English list.
*/
public static String toEnglishList(final Object[] objects, final String join, final String comma) {
- if (objects == null) throw new NullPointerException("Sequence must not be null");
+ if(objects == null) throw new NullPointerException("Sequence must not be null");
final StringBuilder sb = new StringBuilder();
final String joiner = join;
final String coma = comma;
- switch (objects.length) {
+ switch(objects.length) {
case 0:
/* Empty list. */
break;
@@ -114,7 +112,7 @@ public class StringUtils {
break;
default:
/* Three or more items. */
- for (int i = 0; i < objects.length - 1; i++) {
+ for(int i = 0; i < objects.length - 1; i++) {
sb.append(objects[i].toString());
sb.append(coma + " ");
}
@@ -137,13 +135,13 @@ public class StringUtils {
* Converts a sequence to an English list.
*
* @param objects
- * The sequence to convert to an English list.
+ * The sequence to convert to an English list.
*
* @param join
- * The string to use for separating the last element from the rest.
+ * The string to use for separating the last element from the
+ * rest.
*
- * @return
- * The sequence as an English list.
+ * @return The sequence as an English list.
*/
public static String toEnglishList(final Object[] objects, final String join) {
return toEnglishList(objects, join, ",");
@@ -153,16 +151,15 @@ public class StringUtils {
* Converts a sequence to an English list.
*
* @param objects
- * The sequence to convert to an English list.
+ * The sequence to convert to an English list.
*
* @param and
- * Whether to use 'and' or 'or'.
+ * Whether to use 'and' or 'or'.
*
- * @return
- * The sequence as an English list.
+ * @return The sequence as an English list.
*/
public static String toEnglishList(final Object[] objects, final boolean and) {
- if (and) {
+ if(and) {
return toEnglishList(objects, "and");
} else {
return toEnglishList(objects, "or");
@@ -173,17 +170,16 @@ public class StringUtils {
* Count the number of graphemes in a string.
*
* @param value
- * The string to check.
+ * The string to check.
*
- * @return
- * The number of graphemes in the string.
+ * @return The number of graphemes in the string.
*/
public static int graphemeCount(final String value) {
final BreakIterator it = BreakIterator.getCharacterInstance();
it.setText(value);
int count = 0;
- while (it.next() != BreakIterator.DONE) {
+ while(it.next() != BreakIterator.DONE) {
count++;
}
@@ -194,14 +190,14 @@ public class StringUtils {
* Count the number of times a pattern matches in a given string.
*
* @param value
- * The string to count occurances in.
+ * The string to count occurances in.
*
* @param pattern
- * The pattern to count occurances of.
+ * The pattern to count occurances of.
*/
public static int countMatches(final String value, final String pattern) {
Matcher mat = Pattern.compile(pattern).matcher(value);
-
+
int num = 0;
while(mat.find())
num += 1;
diff --git a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java
index 3308fb8..1bdd7b3 100644
--- a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java
+++ b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java
@@ -29,7 +29,8 @@ public class TreeUtils {
}
/* Find a path in a tree. */
- private static <T> void findPath(ITree<T> subtree, LinkedList<T> path, Predicate<T> leafMarker, IList<IList<T>> paths) {
+ private static <T> void findPath(ITree<T> subtree, LinkedList<T> path, Predicate<T> leafMarker,
+ IList<IList<T>> paths) {
if(subtree.getChildrenCount() == 0 && leafMarker.test(subtree.getHead())) {
/* We're at a matching leaf node. Add it. */
IList<T> finalPath = new FunctionalList<>();
diff --git a/base/src/main/java/bjc/utils/funcutils/TriConsumer.java b/base/src/main/java/bjc/utils/funcutils/TriConsumer.java
index a41cde0..7b15097 100644
--- a/base/src/main/java/bjc/utils/funcutils/TriConsumer.java
+++ b/base/src/main/java/bjc/utils/funcutils/TriConsumer.java
@@ -6,13 +6,13 @@ package bjc.utils.funcutils;
* @author EVE
*
* @param <A>
- * Type of the first argument.
+ * Type of the first argument.
*
* @param <B>
- * Type of the second argument.
+ * Type of the second argument.
*
* @param <C>
- * Type of the third argument.
+ * Type of the third argument.
*/
@FunctionalInterface
public interface TriConsumer<A, B, C> {
@@ -20,13 +20,13 @@ public interface TriConsumer<A, B, C> {
* Perform the action.
*
* @param a
- * The first parameter.
+ * The first parameter.
*
* @param b
- * The second parameter.
+ * The second parameter.
*
* @param c
- * The third parameter.
+ * The third parameter.
*/
public void accept(A a, B b, C c);
}