summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/FileUtils.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java12
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java22
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/IBuilder.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java109
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java19
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java55
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java28
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java21
15 files changed, 163 insertions, 183 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 1e5d7de..9a8cca3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java
@@ -1,20 +1,20 @@
package bjc.utils.funcutils;
-import java.util.stream.Collector;
-
import bjc.utils.data.IHolder;
import bjc.utils.data.IPair;
+import java.util.stream.Collector;
+
/**
* Utilities for producing implementations of {@link Collector}
- *
+ *
* @author ben
*
*/
public class CollectorUtils {
/**
* Create a collector that applies two collectors at once
- *
+ *
* @param <InitialType>
* The type of the collection to collect from
* @param <AuxType1>
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 1f73d0a..7e7b003 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java
@@ -1,5 +1,10 @@
package bjc.utils.funcutils;
+import bjc.utils.data.IHolder;
+import bjc.utils.data.IPair;
+import bjc.utils.data.Identity;
+import bjc.utils.data.Pair;
+
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
@@ -7,18 +12,13 @@ import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
-import bjc.utils.data.IHolder;
-import bjc.utils.data.IPair;
-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>> {
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,
Collector<InitialType, AuxType2, FinalType2> second) {
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 747b39f..8d0715d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/DoubleMatcher.java
@@ -8,8 +8,8 @@ import java.util.regex.Pattern;
* Uses a regex from the javadoc for Double.valueOf()
*/
class DoubleMatcher {
- private static final String Digits = "(\\p{Digit}+)";
- private static final String HexDigits = "(\\p{XDigit}+)";
+ 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
@@ -17,7 +17,7 @@ class DoubleMatcher {
*/
private static final String Exp = "[eE][+-]?" + Digits;
- private static final String fpRegex = ("[\\x00-\\x20]*" + // Optional
+ private static final String fpRegex = "[\\x00-\\x20]*" + // Optional
// leading
// "whitespace"
"[+-]?(" + // Optional sign character
@@ -64,7 +64,7 @@ class DoubleMatcher {
*/
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
- ")[pP][+-]?" + Digits + "))" + "[fFdD]?))" + "[\\x00-\\x20]*"); // Optional
+ ")[pP][+-]?" + Digits + "))" + "[fFdD]?))" + "[\\x00-\\x20]*"; // Optional
// trailing
// "whitespace"
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 82a29a2..cab444d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/EnumUtils.java
@@ -1,21 +1,21 @@
package bjc.utils.funcutils;
-import java.util.Random;
-import java.util.function.Consumer;
-
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
+import java.util.Random;
+import java.util.function.Consumer;
+
/**
* Utility methods on enums
- *
+ *
* @author ben
*
*/
public class EnumUtils {
/**
* Do an action for a random number of enum values
- *
+ *
* @param <E>
* The type of the enum
* @param clasz
@@ -35,7 +35,7 @@ public class EnumUtils {
int randomValueCount = enumValues.length - nValues;
- for (int i = 0; i <= randomValueCount; i++) {
+ for(int i = 0; i <= randomValueCount; i++) {
E rDir = valueList.randItem(rnd::nextInt);
valueList.removeMatching(rDir);
@@ -46,7 +46,7 @@ public class EnumUtils {
/**
* Get a random value from an enum
- *
+ *
* @param <E>
* The type of the enum
* @param clasz
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 35a6b3d..4c9c525 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FileUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FileUtils.java
@@ -8,15 +8,15 @@ import java.util.function.BiPredicate;
/**
* Utilities for doing things with files
- *
+ *
* @author ben
*
*/
public class FileUtils {
/**
* Traverse a directory recursively. This is a depth-first traversal
- *
- *
+ *
+ *
* @param root
* The directory to start the traversal at
* @param predicate
@@ -28,7 +28,7 @@ public class FileUtils {
* returning false stops it
* @throws IOException
* if the walk throws an exception
- *
+ *
* TODO If it becomes necessary, write another overload
* for this with all the buttons and knobs from
* walkFileTree
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 3eb086b..cb15d40 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FuncUtils.java
@@ -6,7 +6,7 @@ import java.util.function.Function;
/**
* Utility things for functions
- *
+ *
* @author ben
*
*/
@@ -14,7 +14,7 @@ public class FuncUtils {
/**
* Convert a binary function into a unary function that returns a
* function
- *
+ *
* @param <A>
* The initial type of the function
* @param <B>
@@ -34,14 +34,14 @@ public class FuncUtils {
/**
* Do the specified action the specified number of times
- *
+ *
* @param nTimes
* The number of times to do the action
* @param cons
* The action to perform
*/
public static void doTimes(int nTimes, Consumer<Integer> cons) {
- for (int i = 0; i < nTimes; i++) {
+ for(int i = 0; i < nTimes; i++) {
cons.accept(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 f1240cf..c806d50 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/FunctionalFileVisitor.java
@@ -8,8 +8,8 @@ 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,
BiPredicate<Path, BasicFileAttributes> action) {
@@ -19,18 +19,14 @@ final class FunctionalFileVisitor extends SimpleFileVisitor<Path> {
@Override
public FileVisitResult preVisitDirectory(Path dir, 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(Path file, 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/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
index 2330a40..f736dcb 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java
@@ -1,14 +1,14 @@
package bjc.utils.funcutils;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
/**
* Implements a single group partitioning pass on a list
- *
+ *
* @author ben
*
* @param <E>
@@ -17,11 +17,11 @@ import bjc.utils.funcdata.IList;
final class GroupPartIteration<E> implements Consumer<E> {
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;
@@ -40,7 +40,7 @@ final class GroupPartIteration<E> implements Consumer<E> {
public void accept(E value) {
boolean shouldStartPartition = numberInCurrentPartition >= numberPerPartition;
- if (shouldStartPartition) {
+ if(shouldStartPartition) {
returnedList.add(currentPartition);
currentPartition = new FunctionalList<>();
@@ -48,9 +48,9 @@ final class GroupPartIteration<E> implements Consumer<E> {
} else {
int currentElementCount = elementCounter.apply(value);
- boolean shouldReject = (numberInCurrentPartition + currentElementCount) >= numberPerPartition;
+ boolean shouldReject = numberInCurrentPartition + currentElementCount >= numberPerPartition;
- if (shouldReject) {
+ if(shouldReject) {
rejectedItems.add(value);
} else {
currentPartition.add(value);
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 357ce70..a96a4d6 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/IBuilder.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/IBuilder.java
@@ -2,7 +2,7 @@ package bjc.utils.funcutils;
/**
* Generic interface for objects that implement the builder pattern
- *
+ *
* @author ben
*
* @param <E>
@@ -11,7 +11,7 @@ package bjc.utils.funcutils;
public interface IBuilder<E> {
/**
* Build the object this builder is building
- *
+ *
* @return The built object
* @throws IllegalStateException
* if the data in the builder cannot be built into its
@@ -21,7 +21,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
*/
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 4e4ce80..483b47d 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
@@ -1,19 +1,19 @@
package bjc.utils.funcutils;
+import bjc.utils.data.IPair;
+import bjc.utils.funcdata.FunctionalList;
+import bjc.utils.funcdata.IList;
+
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.function.Function;
import java.util.function.Supplier;
-import bjc.utils.data.IPair;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
/**
* Utilities for manipulating FunctionalLists that don't belong in the class
* itself
- *
+ *
* @author ben
*
*/
@@ -23,15 +23,13 @@ public class ListUtils {
/**
* Collapse a string of tokens into a single string without adding any
* spaces
- *
+ *
* @param input
* The list of tokens to collapse
* @return The collapsed string of tokens
*/
public static String collapseTokens(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,7 +37,7 @@ public class ListUtils {
/**
* Collapse a string of tokens into a single string, adding the desired
* seperator after each token
- *
+ *
* @param input
* The list of tokens to collapse
* @param seperator
@@ -47,24 +45,22 @@ public class ListUtils {
* @return The collapsed string of tokens
*/
public static String collapseTokens(IList<String> input, String seperator) {
- if (input == null) {
+ if(input == null)
throw new NullPointerException("Input must not be null");
- } else if (seperator == null) {
- throw new NullPointerException("Seperator must not be 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 {
+ else {
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);
}
@@ -77,24 +73,22 @@ public class ListUtils {
/**
* Split off affixes from tokens
- *
+ *
* @param input
* The tokens to deaffix
* @param operators
* The affixes to remove
* @return The tokens that have been deaffixed
- *
+ *
*/
public static IList<String> deAffixTokens(IList<String> input, Deque<IPair<String, String>> operators) {
- if (input == null) {
+ if(input == null)
throw new NullPointerException("Input must not be null");
- } else if (operators == null) {
- throw new NullPointerException("Set of operators must not be null");
- }
+ else if(operators == null) throw new NullPointerException("Set of operators must not be null");
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));
});
@@ -105,7 +99,7 @@ public class ListUtils {
/**
* Select a number of random items from the list without replacement
- *
+ *
* @param <E>
* The type of items to select
* @param list
@@ -127,7 +121,7 @@ public class ListUtils {
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
@@ -135,7 +129,7 @@ public class ListUtils {
// N - t
// Probability of selecting the t+1'th element
- if (NumberUtils.isProbable(winningChance, totalChance, rng)) {
+ if(NumberUtils.isProbable(winningChance, totalChance, rng)) {
selected.add(element);
}
}
@@ -145,7 +139,7 @@ public class ListUtils {
/**
* Select a number of random items from the list, with replacement
- *
+ *
* @param <E>
* The type of items to select
* @param list
@@ -161,7 +155,7 @@ public class ListUtils {
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++) {
+ for(int i = 0; i < number; i++) {
selected.add(list.randItem(rng));
}
@@ -171,10 +165,10 @@ public class ListUtils {
/**
* Partition a list into a list of lists, where each element can count
* for more than one element in a partition
- *
+ *
* @param <E>
* The type of elements in the list to partition
- *
+ *
* @param input
* The list to partition
* @param counter
@@ -182,19 +176,18 @@ public class ListUtils {
* for
* @param partitionSize
* 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) {
- 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())
throw new IllegalArgumentException("" + partitionSize + " is not a valid"
+ " partition size. Must be between 1 and " + input.getSize());
- }
/*
* List that holds our results
@@ -211,14 +204,13 @@ public class ListUtils {
/*
* 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()) {
- // 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
@@ -230,7 +222,7 @@ 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
* @param lists
@@ -241,8 +233,8 @@ public class ListUtils {
public static <E> IList<E> mergeLists(IList<E>... lists) {
IList<E> returned = new FunctionalList<>();
- for (IList<E> list : lists) {
- for (E itm : list.toIterable()) {
+ for(IList<E> list : lists) {
+ for(E itm : list.toIterable()) {
returned.add(itm);
}
}
@@ -252,7 +244,7 @@ public class ListUtils {
/**
* Pad the provided list out to the desired size
- *
+ *
* @param <E>
* The type of elements in the list
* @param list
@@ -272,22 +264,22 @@ public class ListUtils {
IList<E> returned = new FunctionalList<>();
- for (E itm : list.toIterable()) {
+ for(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) {
E val = padder.get();
int newCount = counter.apply(val);
- if (newCount <= needed) {
+ if(newCount <= needed) {
returned.add(val);
threshold = 0;
@@ -298,10 +290,9 @@ public class ListUtils {
}
}
- if (threshold > MAX_NTRIESPART) {
+ if(threshold > MAX_NTRIESPART)
throw new IllegalArgumentException("Heuristic (more than " + MAX_NTRIESPART
+ " iterations of attempting to pad) detected unpaddable list ");
- }
}
return returned;
@@ -309,28 +300,26 @@ public class ListUtils {
/**
* Split tokens in a list of tokens into multiple tokens.
- *
+ *
* The intended use is for expression parsers so that you can enter
* something like 1+1 instead of 1 + 1.
- *
+ *
* @param input
* The tokens to split
* @param 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) {
- if (input == null) {
+ if(input == null)
throw new NullPointerException("Input must not be null");
- } else if (operators == null) {
- throw new NullPointerException("Set of operators must not be null");
- }
+ else if(operators == null) throw new NullPointerException("Set of operators must not be null");
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 09c3ef7..6007429 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java
@@ -29,11 +29,11 @@ public class NeoTokenSplitter {
*/
private static String WITH_MULTI_DELIM = "((?<=%1$s+)(?!%1$s)|(?<!%1$s)(?=%1$s+))";
- private StringBuilder currPatt;
- private StringBuilder currExclusionPatt;
+ private StringBuilder currPatt;
+ private StringBuilder currExclusionPatt;
- private Pattern compPatt;
- private Pattern exclusionPatt;
+ private Pattern compPatt;
+ private Pattern exclusionPatt;
/**
* Create a new token splitter.
@@ -56,15 +56,12 @@ public class NeoTokenSplitter {
* If the splitter isn't compiled.
*/
public String[] split(String inp) {
- if (compPatt == null) {
- throw new IllegalStateException("Token splitter has not been compiled yet");
- }
+ 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);
}
@@ -82,7 +79,7 @@ public class NeoTokenSplitter {
String quoteDelim = Pattern.quote(delim);
String delimPat = String.format(WITH_DELIM, quoteDelim);
- if (currPatt == null) {
+ if(currPatt == null) {
currPatt = new StringBuilder();
currExclusionPatt = new StringBuilder();
@@ -106,7 +103,7 @@ public class NeoTokenSplitter {
public void addMultiDelimiter(String delim) {
String delimPat = String.format(WITH_MULTI_DELIM, "(?:" + delim + ")");
- if (currPatt == null) {
+ if(currPatt == null) {
currPatt = new StringBuilder();
currExclusionPatt = new StringBuilder();
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 d3352df..d15e885 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java
@@ -4,14 +4,14 @@ import java.util.function.Function;
/**
* Utility functions for dealing with numbers
- *
+ *
* @author ben
*
*/
public class NumberUtils {
/**
* Compute the falling factorial of a number
- *
+ *
* @param value
* The number to compute
* @param power
@@ -19,14 +19,14 @@ public class NumberUtils {
* @return The falling factorial of the number to the power
*/
public static int fallingFactorial(int value, int power) {
- if (power == 0) {
+ if(power == 0)
return 1;
- } else if (power == 1) {
+ else if(power == 1)
return value;
- } else {
+ else {
int result = 1;
- for (int currentSub = 0; currentSub < power + 1; currentSub++) {
+ for(int currentSub = 0; currentSub < power + 1; currentSub++) {
result *= value - currentSub;
}
@@ -36,7 +36,7 @@ public class NumberUtils {
/**
* Evaluates a linear probability distribution
- *
+ *
* @param winning
* The number of winning possibilities
* @param total
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 2afb783..82e2a79 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java
@@ -8,7 +8,7 @@ import java.util.regex.Pattern;
/**
* Utility methods for operations on strings
- *
+ *
* @author ben
*
*/
@@ -16,7 +16,7 @@ public class StringUtils {
/**
* Checks if the given expression contains the specified operator in a
* situation that indicates its use as an infix operator.
- *
+ *
* @param expression
* The expression to check
* @param operator
@@ -35,7 +35,7 @@ public class StringUtils {
/**
* Check if a string consists only of one or more matches of a regular
* expression
- *
+ *
* @param input
* The string to check
* @param regex
@@ -45,15 +45,13 @@ public class StringUtils {
* of the provided regex
*/
public static boolean containsOnly(String input, String regex) {
- if (input == null) {
+ if(input == null)
throw new NullPointerException("Input must not be null");
- } else if (regex == null) {
- throw new NullPointerException("Regex must not be null");
- }
+ else if(regex == null) throw new NullPointerException("Regex must not be null");
/*
* 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
@@ -64,14 +62,14 @@ public class StringUtils {
/**
* Indent the string being built in a StringBuilder n levels
- *
+ *
* @param builder
* The builder to indent in
* @param levels
* The number of levels to indent
*/
public static void indentNLevels(StringBuilder builder, int levels) {
- for (int i = 0; i < levels; i++) {
+ for(int i = 0; i < levels; i++) {
builder.append("\t");
}
}
@@ -79,7 +77,7 @@ public class StringUtils {
/**
* Print out a deque with a special case for easily showing a deque is
* empty
- *
+ *
* @param <ContainedType>
* The type in the deque
* @param queue
@@ -94,16 +92,23 @@ 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 Pattern escapePatt = Pattern.compile(escapeString);
+ 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
@@ -139,7 +144,7 @@ public class StringUtils {
Matcher mt = doubleQuotePatt.matcher(inp);
- while (mt.find()) {
+ while(mt.find()) {
mt.appendReplacement(work, "");
res.add(work.toString());
@@ -166,11 +171,11 @@ public class StringUtils {
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;
@@ -196,7 +201,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 151b7e2..f550b65 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java
@@ -1,10 +1,10 @@
package bjc.utils.funcutils;
-import java.util.function.BiFunction;
-
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
+import java.util.function.BiFunction;
+
final class TokenDeaffixer implements BiFunction<String, String, IList<String>> {
private String token;
@@ -14,38 +14,34 @@ final class TokenDeaffixer implements BiFunction<String, String, IList<String>>
@Override
public IList<String> apply(String operatorName, String operatorRegex) {
- if (operatorName == null) {
+ if(operatorName == null)
throw new NullPointerException("Operator name must not be null");
- } else if (operatorRegex == null) {
- throw new NullPointerException("Operator regex must not be null");
- }
+ else if(operatorRegex == null) throw new NullPointerException("Operator regex must not be null");
- if (StringUtils.containsOnly(token, operatorRegex)) {
+ if(StringUtils.containsOnly(token, operatorRegex))
return new FunctionalList<>(token);
- } else if (token.startsWith(operatorName)) {
- if (token.endsWith(operatorName)) {
+ else if(token.startsWith(operatorName)) {
+ if(token.endsWith(operatorName))
return new FunctionalList<>(operatorName, token.split(operatorRegex)[1], operatorName);
- }
return new FunctionalList<>(operatorName, token.split(operatorRegex)[1]);
- } else if (token.endsWith(operatorName)) {
+ } else if(token.endsWith(operatorName))
return new FunctionalList<>(token.split(operatorRegex)[0], operatorName);
- } else if (token.contains(operatorName)) {
+ else if(token.contains(operatorName)) {
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);
}
}
return returned;
- } else {
+ } else
return new FunctionalList<>(token);
- }
}
}
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 4176088..84f5270 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java
@@ -1,11 +1,11 @@
package bjc.utils.funcutils;
-import java.util.Iterator;
-import java.util.function.BiFunction;
-
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
+import java.util.Iterator;
+import java.util.function.BiFunction;
+
final class TokenSplitter implements BiFunction<String, String, IList<String>> {
private String tokenToSplit;
@@ -15,16 +15,13 @@ final class TokenSplitter implements BiFunction<String, String, IList<String>> {
@Override
public IList<String> apply(String operatorName, String operatorRegex) {
- if (operatorName == null) {
+ if(operatorName == null)
throw new NullPointerException("Operator name must not be null");
- } else if (operatorRegex == null) {
- throw new NullPointerException("Operator regex must not be null");
- }
+ else if(operatorRegex == null) throw new NullPointerException("Operator regex must not be null");
- if (tokenToSplit.contains(operatorName)) {
- if (StringUtils.containsOnly(tokenToSplit, operatorRegex)) {
+ if(tokenToSplit.contains(operatorName)) {
+ if(StringUtils.containsOnly(tokenToSplit, operatorRegex))
return new FunctionalList<>(tokenToSplit);
- }
IList<String> splitTokens = new FunctionalList<>(tokenToSplit.split(operatorRegex));
IList<String> result = new FunctionalList<>();
@@ -34,10 +31,10 @@ final class TokenSplitter implements BiFunction<String, String, IList<String>> {
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);
}
}