summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils
diff options
context:
space:
mode:
authorEVE <EVE@EVE-PC>2017-03-13 16:42:21 -0400
committerEVE <EVE@EVE-PC>2017-03-13 16:42:21 -0400
commit27bf571d6413c3cc6a5d664b5bddd38d21d7b1cd (patch)
tree847fb52acb091c1c613d37b8477094d5762c6988 /BJC-Utils2/src/main/java/bjc/utils/funcutils
parentaa807a96cae2c47259fb38f710640883060339e9 (diff)
Formatting
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java22
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java19
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java83
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java23
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/FileUtils.java25
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java13
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java20
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/IBuilder.java11
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java127
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java32
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java13
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java75
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java11
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java13
15 files changed, 248 insertions, 251 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java
index eb3695e..1e5d7de 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java
@@ -16,26 +16,24 @@ 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
*/
- public static <InitialType, AuxType1, AuxType2, FinalType1, FinalType2>
- Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>>
- compoundCollect(
- Collector<InitialType, AuxType1, FinalType1> first,
- Collector<InitialType, AuxType2, FinalType2> second) {
+ public static <InitialType, AuxType1, AuxType2, FinalType1, FinalType2> Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> compoundCollect(
+ Collector<InitialType, AuxType1, FinalType1> first,
+ Collector<InitialType, AuxType2, FinalType2> second) {
return new CompoundCollector<>(first, second);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java
index de5fe85..1f73d0a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java
@@ -13,15 +13,14 @@ import bjc.utils.data.Identity;
import bjc.utils.data.Pair;
final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, FinalType2>
- implements Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> {
+ implements Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> {
- private Set<java.util.stream.Collector.Characteristics> characteristicSet;
+ private Set<java.util.stream.Collector.Characteristics> characteristicSet;
- private Collector<InitialType, AuxType1, FinalType1> first;
- private Collector<InitialType, AuxType2, FinalType2> second;
+ private Collector<InitialType, AuxType1, FinalType1> first;
+ private Collector<InitialType, AuxType2, FinalType2> second;
- public CompoundCollector(
- Collector<InitialType, AuxType1, FinalType1> first,
+ public CompoundCollector(Collector<InitialType, AuxType1, FinalType1> first,
Collector<InitialType, AuxType2, FinalType2> second) {
this.first = first;
this.second = second;
@@ -69,9 +68,7 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final
return (state) -> {
return state.unwrap((pair) -> {
return pair.bind((left, right) -> {
- return new Pair<>(
- first.finisher().apply(left),
- second.finisher().apply(right));
+ return new Pair<>(first.finisher().apply(left), second.finisher().apply(right));
});
});
};
@@ -80,9 +77,7 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final
@Override
public Supplier<IHolder<IPair<AuxType1, AuxType2>>> supplier() {
return () -> {
- return new Identity<>(new Pair<>(
- first.supplier().get(),
- second.supplier().get()));
+ return new Identity<>(new Pair<>(first.supplier().get(), second.supplier().get()));
};
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java
index d6e77c7..747b39f 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java
@@ -10,56 +10,63 @@ import java.util.regex.Pattern;
class DoubleMatcher {
private static final String Digits = "(\\p{Digit}+)";
private static final String HexDigits = "(\\p{XDigit}+)";
-
+
/*
* an exponent is 'e' or 'E' followed by an optionally signed decimal
* integer.
*/
private static final String Exp = "[eE][+-]?" + Digits;
- private static final String fpRegex = ("[\\x00-\\x20]*" + // Optional leading "whitespace"
- "[+-]?(" + // Optional sign character
- "NaN|" + // "NaN" string
- "Infinity|" + // "Infinity" string
+ private static final String fpRegex = ("[\\x00-\\x20]*" + // Optional
+ // leading
+ // "whitespace"
+ "[+-]?(" + // Optional sign character
+ "NaN|" + // "NaN" string
+ "Infinity|" + // "Infinity" string
- /* A decimal floating-point string representing a finite positive
- * number without a leading sign has at most five basic pieces:
- * Digits . Digits ExponentPart FloatTypeSuffix
- *
- * Since this method allows integer-only strings as input
- * in addition to strings of floating-point literals, the
- * two sub-patterns below are simplifications of the grammar
- * productions from section 3.10.2 of
- * The Java™ Language Specification.
- */
+ /*
+ * A decimal floating-point string representing a finite
+ * positive number without a leading sign has at most
+ * five basic pieces: Digits . Digits ExponentPart
+ * FloatTypeSuffix
+ *
+ * Since this method allows integer-only strings as
+ * input in addition to strings of floating-point
+ * literals, the two sub-patterns below are
+ * simplifications of the grammar productions from
+ * section 3.10.2 of The Java™ Language Specification.
+ */
- /*
- * Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
- */
- "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
+ /*
+ * Digits ._opt Digits_opt ExponentPart_opt
+ * FloatTypeSuffix_opt
+ */
+ "(((" + Digits + "(\\.)?(" + Digits + "?)(" + Exp + ")?)|" +
- /*
- * . Digits ExponentPart_opt FloatTypeSuffix_opt
- */
- "(\\.("+Digits+")("+Exp+")?)|"+
+ /*
+ * . Digits ExponentPart_opt FloatTypeSuffix_opt
+ */
+ "(\\.(" + Digits + ")(" + Exp + ")?)|" +
- /*
- * Hexadecimal strings
- */
- "((" +
- /*
- * 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
- */
- "(0[xX]" + HexDigits + "(\\.)?)|" +
+ /*
+ * Hexadecimal strings
+ */
+ "((" +
+ /*
+ * 0[xX] HexDigits ._opt BinaryExponent
+ * FloatTypeSuffix_opt
+ */
+ "(0[xX]" + HexDigits + "(\\.)?)|" +
- /*
- * 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
- */
- "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
+ /*
+ * 0[xX] HexDigits_opt . HexDigits BinaryExponent
+ * FloatTypeSuffix_opt
+ */
+ "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
- ")[pP][+-]?" + Digits + "))" +
- "[fFdD]?))" +
- "[\\x00-\\x20]*"); // Optional trailing "whitespace"
+ ")[pP][+-]?" + Digits + "))" + "[fFdD]?))" + "[\\x00-\\x20]*"); // Optional
+ // trailing
+ // "whitespace"
public static final Pattern floatingLiteral = Pattern.compile("\\A" + fpRegex + "\\Z");
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java
index 9be6080..82a29a2 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java
@@ -17,18 +17,18 @@ 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(Class<E> clasz,
- int nValues, Consumer<E> action, Random rnd) {
+ public static <E extends Enum<E>> void doForValues(Class<E> clasz, int nValues, Consumer<E> action,
+ Random rnd) {
E[] enumValues = clasz.getEnumConstants();
IList<E> valueList = new FunctionalList<>(enumValues);
@@ -48,15 +48,14 @@ 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
*/
- public static <E extends Enum<E>> E getRandomValue(Class<E> clasz,
- Random rnd) {
+ public static <E extends Enum<E>> E getRandomValue(Class<E> clasz, Random rnd) {
E[] enumValues = clasz.getEnumConstants();
return new FunctionalList<>(enumValues).randItem(rnd::nextInt);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FileUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FileUtils.java
index 6fc09ff..35a6b3d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FileUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FileUtils.java
@@ -18,24 +18,23 @@ public class FileUtils {
*
*
* @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
*
- * TODO If it becomes necessary, write another overload for
- * this with all the buttons and knobs from walkFileTree
+ * TODO If it becomes necessary, write another overload
+ * for this with all the buttons and knobs from
+ * walkFileTree
*/
- public static void traverseDirectory(Path root,
- BiPredicate<Path, BasicFileAttributes> predicate,
- BiPredicate<Path, BasicFileAttributes> action)
- throws IOException {
+ public static void traverseDirectory(Path root, BiPredicate<Path, BasicFileAttributes> predicate,
+ BiPredicate<Path, BasicFileAttributes> action) throws IOException {
Files.walkFileTree(root, new FunctionalFileVisitor(predicate, action));
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java
index 679af52..3eb086b 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java
@@ -16,13 +16,13 @@ public class FuncUtils {
* function
*
* @param <A>
- * The initial type of the function
+ * The initial type of the function
* @param <B>
- * The intermediate type of the function
+ * The intermediate type of the function
* @param <C>
- * The terminal type of the function
+ * The terminal type of the function
* @param func
- * The function to transform
+ * The function to transform
* @return The function transformed into a unary function returning a
* function
*/
@@ -36,9 +36,9 @@ public class FuncUtils {
* Do the specified action the specified number of times
*
* @param nTimes
- * The number of times to do the action
+ * The number of times to do the action
* @param cons
- * The action to perform
+ * The action to perform
*/
public static void doTimes(int nTimes, Consumer<Integer> cons) {
for (int i = 0; i < nTimes; i++) {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java
index cd833d9..f1240cf 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java
@@ -8,19 +8,17 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.function.BiPredicate;
final class FunctionalFileVisitor extends SimpleFileVisitor<Path> {
- private BiPredicate<Path, BasicFileAttributes> predicate;
- private BiPredicate<Path, BasicFileAttributes> action;
+ private BiPredicate<Path, BasicFileAttributes> predicate;
+ private BiPredicate<Path, BasicFileAttributes> action;
- public FunctionalFileVisitor(
- BiPredicate<Path, BasicFileAttributes> predicate,
+ public FunctionalFileVisitor(BiPredicate<Path, BasicFileAttributes> predicate,
BiPredicate<Path, BasicFileAttributes> action) {
this.predicate = predicate;
this.action = action;
}
@Override
- public FileVisitResult preVisitDirectory(
- Path dir, BasicFileAttributes attrs) throws IOException {
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
if (predicate.test(dir, attrs)) {
return FileVisitResult.CONTINUE;
}
@@ -29,8 +27,7 @@ final class FunctionalFileVisitor extends SimpleFileVisitor<Path> {
}
@Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- throws IOException {
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (action.test(file, attrs)) {
return FileVisitResult.CONTINUE;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
index fc58b6a..2330a40 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
@@ -12,21 +12,21 @@ 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> {
- private IList<IList<E>> returnedList;
+ private IList<IList<E>> returnedList;
- public IList<E> currentPartition;
- private IList<E> rejectedItems;
+ public IList<E> currentPartition;
+ private IList<E> rejectedItems;
- private int numberInCurrentPartition;
- private int numberPerPartition;
+ private int numberInCurrentPartition;
+ private int numberPerPartition;
- private Function<E, Integer> elementCounter;
+ private Function<E, Integer> elementCounter;
- public GroupPartIteration(IList<IList<E>> returned, IList<E> rejects,
- int nPerPart, Function<E, Integer> eleCount) {
+ public GroupPartIteration(IList<IList<E>> returned, IList<E> rejects, int nPerPart,
+ Function<E, Integer> eleCount) {
this.returnedList = returned;
this.rejectedItems = rejects;
this.numberPerPartition = nPerPart;
@@ -49,7 +49,7 @@ final class GroupPartIteration<E> implements Consumer<E> {
int currentElementCount = elementCounter.apply(value);
boolean shouldReject = (numberInCurrentPartition + currentElementCount) >= numberPerPartition;
-
+
if (shouldReject) {
rejectedItems.add(value);
} else {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/IBuilder.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/IBuilder.java
index a55e8e0..357ce70 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/IBuilder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/IBuilder.java
@@ -6,7 +6,7 @@ package bjc.utils.funcutils;
* @author ben
*
* @param <E>
- * The type of object being built
+ * The type of object being built
*/
public interface IBuilder<E> {
/**
@@ -14,8 +14,8 @@ public interface IBuilder<E> {
*
* @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();
@@ -23,10 +23,9 @@ 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");
+ throw new UnsupportedOperationException("Builder doesn't support state resetting");
}
}
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 ad7dbad..4e4ce80 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
@@ -11,8 +11,8 @@ import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
/**
- * Utilities for manipulating FunctionalLists that don't belong in the
- * class itself
+ * Utilities for manipulating FunctionalLists that don't belong in the class
+ * itself
*
* @author ben
*
@@ -25,7 +25,7 @@ public class ListUtils {
* spaces
*
* @param input
- * The list of tokens to collapse
+ * The list of tokens to collapse
* @return The collapsed string of tokens
*/
public static String collapseTokens(IList<String> input) {
@@ -41,9 +41,9 @@ public class ListUtils {
* seperator after each token
*
* @param input
- * The list of tokens to collapse
+ * The list of tokens to collapse
* @param seperator
- * The seperator to use for seperating tokens
+ * The seperator to use for seperating tokens
* @return The collapsed string of tokens
*/
public static String collapseTokens(IList<String> input, String seperator) {
@@ -61,10 +61,10 @@ public class ListUtils {
StringBuilder state = new StringBuilder();
int i = 1;
- for(String itm : input.toIterable()) {
+ for (String itm : input.toIterable()) {
state.append(itm);
- if(i != input.getSize()) {
+ if (i != input.getSize()) {
state.append(seperator);
}
@@ -79,14 +79,13 @@ public class ListUtils {
* Split off affixes from tokens
*
* @param input
- * The tokens to deaffix
+ * The tokens to deaffix
* @param operators
- * The affixes to remove
+ * The affixes to remove
* @return The tokens that have been deaffixed
*
*/
- public static IList<String> deAffixTokens(IList<String> input,
- Deque<IPair<String, String>> operators) {
+ public static IList<String> deAffixTokens(IList<String> input, Deque<IPair<String, String>> operators) {
if (input == null) {
throw new NullPointerException("Input must not be null");
} else if (operators == null) {
@@ -95,7 +94,7 @@ public class ListUtils {
IList<String> returned = input;
- for(IPair<String, String> op : operators) {
+ for (IPair<String, String> op : operators) {
returned = returned.flatMap(token -> {
return op.merge(new TokenDeaffixer(token));
});
@@ -108,28 +107,27 @@ 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
*/
- public static <E> IList<E> drawWithoutReplacement(
- IList<E> list, int number, Function<Integer, Integer> rng) {
+ public static <E> IList<E> drawWithoutReplacement(IList<E> list, int number, Function<Integer, Integer> rng) {
IList<E> selected = new FunctionalList<>(new ArrayList<>(number));
int total = list.getSize();
-
+
Iterator<E> itr = list.toIterable().iterator();
E element = null;
- for(int index = 0; itr.hasNext(); element = itr.next()) {
+ for (int index = 0; itr.hasNext(); element = itr.next()) {
int winningChance = number - selected.getSize();
// n - m
@@ -149,19 +147,18 @@ 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 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
*/
- public static <E> IList<E> drawWithReplacement(IList<E> list,
- int number, Function<Integer, Integer> rng) {
+ public static <E> IList<E> drawWithReplacement(IList<E> list, int number, Function<Integer, Integer> rng) {
IList<E> selected = new FunctionalList<>(new ArrayList<>(number));
for (int i = 0; i < number; i++) {
@@ -176,28 +173,27 @@ 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
*/
- public static <E> IList<IList<E>> groupPartition(
- IList<E> input, Function<E, Integer> counter, int partitionSize) {
+ public static <E> IList<IList<E>> groupPartition(IList<E> input, Function<E, Integer> counter,
+ int partitionSize) {
if (input == null) {
throw new NullPointerException("Input list must not be null");
} else if (counter == null) {
throw new NullPointerException("Counter must not be null");
} else if (partitionSize < 1 || partitionSize > input.getSize()) {
- throw new IllegalArgumentException(
- "" + partitionSize + " is not a valid"
- + " partition size. Must be between 1 and "
- + input.getSize());
+ throw new IllegalArgumentException("" + partitionSize + " is not a valid"
+ + " partition size. Must be between 1 and " + input.getSize());
}
/*
@@ -225,25 +221,20 @@ public class ListUtils {
}
}
- 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());
+ 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());
}
/**
* 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
*/
@SafeVarargs
@@ -251,7 +242,7 @@ public class ListUtils {
IList<E> returned = new FunctionalList<>();
for (IList<E> list : lists) {
- for(E itm : list.toIterable()) {
+ for (E itm : list.toIterable()) {
returned.add(itm);
}
}
@@ -263,27 +254,25 @@ 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
* @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(IList<E> list,
- Function<E, Integer> counter, int size,
- Supplier<E> padder) {
+ public static <E> IList<E> padList(IList<E> list, Function<E, Integer> counter, int size, Supplier<E> padder) {
int count = 0;
IList<E> returned = new FunctionalList<>();
-
- for(E itm : list.toIterable()) {
+
+ for (E itm : list.toIterable()) {
count += counter.apply(itm);
returned.add(itm);
@@ -310,8 +299,7 @@ public class ListUtils {
}
if (threshold > MAX_NTRIESPART) {
- throw new IllegalArgumentException("Heuristic (more than "
- + MAX_NTRIESPART
+ throw new IllegalArgumentException("Heuristic (more than " + MAX_NTRIESPART
+ " iterations of attempting to pad) detected unpaddable list ");
}
}
@@ -326,15 +314,14 @@ public class ListUtils {
* something like 1+1 instead of 1 + 1.
*
* @param input
- * The tokens to split
+ * The tokens to split
* @param operators
- * Pairs of operators to split on and regexes that match
- * those operators
+ * Pairs of operators to split on and regexes that match
+ * those operators
* @return A list of tokens split on all the operators
*
*/
- public static IList<String> splitTokens(IList<String> input,
- Deque<IPair<String, String>> operators) {
+ public static IList<String> splitTokens(IList<String> input, Deque<IPair<String, String>> operators) {
if (input == null) {
throw new NullPointerException("Input must not be null");
} else if (operators == null) {
@@ -343,7 +330,7 @@ public class ListUtils {
IList<String> returned = input;
- for(IPair<String, String> op : operators) {
+ for (IPair<String, String> op : operators) {
returned = returned.flatMap(token -> {
return op.merge(new TokenSplitter(token));
});
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java
index 91cbeb5..09c3ef7 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java
@@ -11,9 +11,8 @@ public class NeoTokenSplitter {
/*
* This string is a format template for the delimiter matching regex
*
- * It does two things
- * 1. Match the provided delimiter by positive lookahead
- * 2. Match the provided delimiter by positive lookbehind
+ * It does two things 1. Match the provided delimiter by positive
+ * lookahead 2. Match the provided delimiter by positive lookbehind
*
* Thus, it will only match in places where the delimiter is, but won't
* actually match the delimiter, leaving split to put it into the stream
@@ -48,21 +47,24 @@ public class NeoTokenSplitter {
*
* The splitter must be compiled first.
*
- * @param inp The string to split.
+ * @param inp
+ * The string to split.
*
* @return The split string, including delimiters.
*
- * @throws IllegalStateException If the splitter isn't compiled.
+ * @throws IllegalStateException
+ * If the splitter isn't compiled.
*/
public String[] split(String inp) {
- if(compPatt == null) {
+ if (compPatt == null) {
throw new IllegalStateException("Token splitter has not been compiled yet");
}
/*
* Don't split something that matches only an operator
*/
- if(exclusionPatt.matcher(inp).matches()) return new String[] {inp};
+ if (exclusionPatt.matcher(inp).matches())
+ return new String[] { inp };
return compPatt.split(inp);
}
@@ -73,14 +75,15 @@ public class NeoTokenSplitter {
*
* The provided string is regex-escaped before being used.
*
- * @param delim The delimiter to match on.
+ * @param delim
+ * The delimiter to match on.
*/
public void addDelimiter(String delim) {
String quoteDelim = Pattern.quote(delim);
String delimPat = String.format(WITH_DELIM, quoteDelim);
- if(currPatt == null) {
- currPatt = new StringBuilder();
+ if (currPatt == null) {
+ currPatt = new StringBuilder();
currExclusionPatt = new StringBuilder();
currPatt.append("(?:" + delimPat + ")");
@@ -97,13 +100,14 @@ public class NeoTokenSplitter {
* The provided string should be a pattern to match one or more
* occurances of.
*
- * @param delim The delimiter to split on.
+ * @param delim
+ * The delimiter to split on.
*/
public void addMultiDelimiter(String delim) {
String delimPat = String.format(WITH_MULTI_DELIM, "(?:" + delim + ")");
- if(currPatt == null) {
- currPatt = new StringBuilder();
+ if (currPatt == null) {
+ currPatt = new StringBuilder();
currExclusionPatt = new StringBuilder();
currPatt.append("(?:" + delimPat + ")");
@@ -121,7 +125,7 @@ public class NeoTokenSplitter {
* Makes this splitter ready to use.
*/
public void compile() {
- compPatt = Pattern.compile(currPatt.toString());
+ compPatt = Pattern.compile(currPatt.toString());
exclusionPatt = Pattern.compile(currExclusionPatt.toString());
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java
index 24c2014..d3352df 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java
@@ -13,9 +13,9 @@ 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
*/
public static int fallingFactorial(int value, int power) {
@@ -38,15 +38,14 @@ 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
*/
- public static boolean isProbable(int winning, int total,
- Function<Integer, Integer> rng) {
+ public static boolean isProbable(int winning, int total, Function<Integer, Integer> rng) {
return rng.apply(total) < winning;
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
index 2307f11..2afb783 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
@@ -18,18 +18,18 @@ public class StringUtils {
* situation that indicates its use as an infix operator.
*
* @param expression
- * The expression to check
+ * The expression to check
* @param operator
- * The operator to see if it is contained
+ * The operator to see if it is contained
* @return Whether or not the given expression contains the specified
* operator as a infix operator
*/
public static boolean containsInfixOperator(String expression, String operator) {
- // Bit annoying to have to use a full class name, but what are you
+ // Bit annoying to have to use a full class name, but what are
+ // you
// going to do?
return org.apache.commons.lang3.StringUtils.countMatches(expression, operator) == 1
- && !expression.equalsIgnoreCase(operator)
- && !expression.startsWith(operator);
+ && !expression.equalsIgnoreCase(operator) && !expression.startsWith(operator);
}
/**
@@ -37,9 +37,10 @@ public class StringUtils {
* expression
*
* @param input
- * The string to check
+ * The string to check
* @param regex
- * 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
*/
@@ -54,9 +55,9 @@ public class StringUtils {
* This regular expression is fairly simple.
*
* First, we match the beginning of the string. Then, we start a
- * non-capturing group whose contents are the passed in regex. That
- * group is then matched one or more times and the pattern matches
- * to the end of the string
+ * non-capturing group whose contents are the passed in regex.
+ * That group is then matched one or more times and the pattern
+ * matches to the end of the string
*/
return input.matches("\\A(?:" + regex + ")+\\Z");
}
@@ -65,9 +66,9 @@ 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(StringBuilder builder, int levels) {
for (int i = 0; i < levels; i++) {
@@ -80,9 +81,9 @@ 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
*/
@@ -93,29 +94,44 @@ public class StringUtils {
/*
* This regex matches java-style string escapes
*/
- private static String escapeString =
- "\\\\([btnfr\"'\\\\]" // Match shortform escape sequences like \t or \"
- + "|[0-3]?[0-7]{1,2}" // Match octal escape sequences
- + "|u[0-9a-fA-F]{4})"; // Match unicode escape sequences
+ private static String escapeString = "\\\\([btnfr\"'\\\\]" // Match
+ // shortform
+ // escape
+ // sequences
+ // like
+ // \t or
+ // \"
+ + "|[0-3]?[0-7]{1,2}" // Match octal escape sequences
+ + "|u[0-9a-fA-F]{4})"; // Match unicode escape sequences
private static Pattern escapePatt = Pattern.compile(escapeString);
/*
* This regular expression matches java style double quoted strings
*/
- private static Pattern doubleQuotePatt = Pattern.compile("(\"("
- + "[^\\\\\"]+" // Match one or more characters that aren't quotes or slashes
+ private static Pattern doubleQuotePatt = Pattern.compile("(\"(" + "[^\\\\\"]+" // Match
+ // one
+ // or
+ // more
+ // characters
+ // that
+ // aren't
+ // quotes
+ // or
+ // slashes
+ "|" + escapeString + ")" // Match escape sequences
- + "*\")"); // Match all of those things zero or more times, followed by a closing quote
+ + "*\")"); // Match all of those things zero or more
+ // times, followed by a closing quote
/**
* Remove double quoted strings from a string.
*
* Splits a string around instances of java-style double-quoted strings.
*
- * @param inp The string to split.
+ * @param inp
+ * The string to split.
*
* @return An list containing alternating bits of the string and the
- * embedded double-quoted strings that seperated them.
+ * embedded double-quoted strings that seperated them.
*/
public static List<String> removeDQuotedStrings(String inp) {
StringBuffer work = new StringBuffer();
@@ -123,7 +139,7 @@ public class StringUtils {
Matcher mt = doubleQuotePatt.matcher(inp);
- while(mt.find()) {
+ while (mt.find()) {
mt.appendReplacement(work, "");
res.add(work.toString());
@@ -140,20 +156,21 @@ public class StringUtils {
/**
* Replace escape characters with their actual equivalents.
*
- * @param inp The string to replace escape sequences in.
+ * @param inp
+ * The string to replace escape sequences in.
*
* @return The string with escape sequences replaced by their equivalent
- * characters.
+ * characters.
*/
public static String descapeString(String inp) {
StringBuffer work = new StringBuffer();
Matcher escapeFinder = escapePatt.matcher(inp);
- while(escapeFinder.find()) {
+ while (escapeFinder.find()) {
String escapeSeq = escapeFinder.group();
String escapeRep = "";
- switch(escapeSeq) {
+ switch (escapeSeq) {
case "\\b":
escapeRep = "\b";
break;
@@ -179,7 +196,7 @@ public class StringUtils {
escapeRep = "\\";
break;
default:
- if(escapeSeq.startsWith("u")) {
+ if (escapeSeq.startsWith("u")) {
escapeRep = handleUnicodeEscape(escapeSeq.substring(1));
} else {
escapeRep = handleOctalEscape(escapeSeq);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java
index 0ce6dc1..151b7e2 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java
@@ -5,8 +5,7 @@ import java.util.function.BiFunction;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
-final class TokenDeaffixer
- implements BiFunction<String, String, IList<String>> {
+final class TokenDeaffixer implements BiFunction<String, String, IList<String>> {
private String token;
public TokenDeaffixer(String tok) {
@@ -24,7 +23,7 @@ final class TokenDeaffixer
if (StringUtils.containsOnly(token, operatorRegex)) {
return new FunctionalList<>(token);
} else if (token.startsWith(operatorName)) {
- if(token.endsWith(operatorName)) {
+ if (token.endsWith(operatorName)) {
return new FunctionalList<>(operatorName, token.split(operatorRegex)[1], operatorName);
}
@@ -35,11 +34,11 @@ final class TokenDeaffixer
String[] tokenParts = token.split(operatorRegex);
IList<String> returned = new FunctionalList<>();
-
- for(int i = 0; i < tokenParts.length; i++) {
+
+ for (int i = 0; i < tokenParts.length; i++) {
returned.add(tokenParts[i]);
- if(i < tokenParts.length - 1) {
+ if (i < tokenParts.length - 1) {
returned.add(operatorName);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java
index f04b68d..4176088 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java
@@ -6,8 +6,7 @@ import java.util.function.BiFunction;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
-final class TokenSplitter
- implements BiFunction<String, String, IList<String>> {
+final class TokenSplitter implements BiFunction<String, String, IList<String>> {
private String tokenToSplit;
public TokenSplitter(String tok) {
@@ -17,11 +16,9 @@ final class TokenSplitter
@Override
public IList<String> apply(String operatorName, String operatorRegex) {
if (operatorName == null) {
- throw new NullPointerException(
- "Operator name must not be null");
+ throw new NullPointerException("Operator name must not be null");
} else if (operatorRegex == null) {
- throw new NullPointerException(
- "Operator regex must not be null");
+ throw new NullPointerException("Operator regex must not be null");
}
if (tokenToSplit.contains(operatorName)) {
@@ -37,10 +34,10 @@ final class TokenSplitter
String elm = itr.next();
- for(int i = 0; itr.hasNext(); elm = itr.next()) {
+ for (int i = 0; itr.hasNext(); elm = itr.next()) {
result.add(elm);
- if(i != tokenExpansionSize) {
+ if (i != tokenExpansionSize) {
result.add(operatorName);
}
}