From 504ca816530efdff06bc202e0432ebd354aec304 Mon Sep 17 00:00:00 2001 From: EVE Date: Tue, 14 Mar 2017 12:07:14 -0400 Subject: Cleanup --- .../java/bjc/utils/funcutils/CollectorUtils.java | 8 +- .../bjc/utils/funcutils/CompoundCollector.java | 14 +-- .../java/bjc/utils/funcutils/DoubleMatcher.java | 8 +- .../main/java/bjc/utils/funcutils/EnumUtils.java | 14 +-- .../main/java/bjc/utils/funcutils/FileUtils.java | 8 +- .../main/java/bjc/utils/funcutils/FuncUtils.java | 8 +- .../bjc/utils/funcutils/FunctionalFileVisitor.java | 12 +-- .../bjc/utils/funcutils/GroupPartIteration.java | 22 ++--- .../main/java/bjc/utils/funcutils/IBuilder.java | 6 +- .../main/java/bjc/utils/funcutils/ListUtils.java | 109 +++++++++------------ .../java/bjc/utils/funcutils/NeoTokenSplitter.java | 19 ++-- .../main/java/bjc/utils/funcutils/NumberUtils.java | 14 +-- .../main/java/bjc/utils/funcutils/StringUtils.java | 55 ++++++----- .../java/bjc/utils/funcutils/TokenDeaffixer.java | 28 +++--- .../java/bjc/utils/funcutils/TokenSplitter.java | 21 ++-- 15 files changed, 163 insertions(+), 183 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils') 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 * The type of the collection to collect from * @param 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 implements Collector>, IPair> { private Set characteristicSet; - private Collector first; - private Collector second; + private Collector first; + private Collector second; public CompoundCollector(Collector first, Collector 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 * 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 * 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 * The initial type of the function * @param @@ -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 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 { - private BiPredicate predicate; - private BiPredicate action; + private BiPredicate predicate; + private BiPredicate action; public FunctionalFileVisitor(BiPredicate predicate, BiPredicate action) { @@ -19,18 +19,14 @@ final class FunctionalFileVisitor extends SimpleFileVisitor { @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 @@ -17,11 +17,11 @@ import bjc.utils.funcdata.IList; final class GroupPartIteration implements Consumer { private IList> returnedList; - public IList currentPartition; - private IList rejectedItems; + public IList currentPartition; + private IList rejectedItems; - private int numberInCurrentPartition; - private int numberPerPartition; + private int numberInCurrentPartition; + private int numberPerPartition; private Function elementCounter; @@ -40,7 +40,7 @@ final class GroupPartIteration implements Consumer { 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 implements Consumer { } 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 @@ -11,7 +11,7 @@ package bjc.utils.funcutils; public interface IBuilder { /** * 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 { /** * 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 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 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 deAffixTokens(IList input, Deque> 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 returned = input; - for (IPair op : operators) { + for(IPair 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 * The type of items to select * @param list @@ -127,7 +121,7 @@ public class ListUtils { Iterator 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 * The type of items to select * @param list @@ -161,7 +155,7 @@ public class ListUtils { public static IList drawWithReplacement(IList list, int number, Function rng) { IList 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 * 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 IList> groupPartition(IList input, Function 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 * The type of value in this lists * @param lists @@ -241,8 +233,8 @@ public class ListUtils { public static IList mergeLists(IList... lists) { IList returned = new FunctionalList<>(); - for (IList list : lists) { - for (E itm : list.toIterable()) { + for(IList 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 * The type of elements in the list * @param list @@ -272,22 +264,22 @@ public class ListUtils { IList 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 splitTokens(IList input, Deque> 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 returned = input; - for (IPair op : operators) { + for(IPair 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)|(? * 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> { private String token; @@ -14,38 +14,34 @@ final class TokenDeaffixer implements BiFunction> @Override public IList 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 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> { private String tokenToSplit; @@ -15,16 +15,13 @@ final class TokenSplitter implements BiFunction> { @Override public IList 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 splitTokens = new FunctionalList<>(tokenToSplit.split(operatorRegex)); IList result = new FunctionalList<>(); @@ -34,10 +31,10 @@ final class TokenSplitter implements BiFunction> { 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); } } -- cgit v1.2.3