diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/funcutils')
5 files changed, 27 insertions, 99 deletions
diff --git a/base/src/main/java/bjc/utils/funcutils/ListUtils.java b/base/src/main/java/bjc/utils/funcutils/ListUtils.java index 672a12d..e3662af 100644 --- a/base/src/main/java/bjc/utils/funcutils/ListUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/ListUtils.java @@ -28,8 +28,7 @@ public class ListUtils { * @return The collapsed string of tokens. */ public static String collapseTokens(final IList<String> input) { - if (input == null) - throw new NullPointerException("Input must not be null"); + if (input == null) throw new NullPointerException("Input must not be null"); return collapseTokens(input, ""); } @@ -48,11 +47,8 @@ public class ListUtils { */ public static String collapseTokens(final IList<String> input, final String seperator) { - if (input == null) { - throw new NullPointerException("Input must not be null"); - } else if (seperator == null) { - throw new NullPointerException("Seperator must not be null"); - } + if (input == null) throw new NullPointerException("Input must not be null"); + else if (seperator == null) throw new NullPointerException("Seperator must not be null"); if (input.getSize() < 1) { return ""; @@ -65,9 +61,7 @@ public class ListUtils { for (final String itm : input.toIterable()) { state.append(itm); - if (i != input.getSize()) { - state.append(seperator); - } + if (i != input.getSize()) state.append(seperator); i += 1; } @@ -143,9 +137,7 @@ public class ListUtils { final Function<Integer, Integer> rng) { final IList<E> selected = new FunctionalList<>(new ArrayList<>(number)); - for (int i = 0; i < number; i++) { - selected.add(list.randItem(rng)); - } + for (int i = 0; i < number; i++) selected.add(list.randItem(rng)); return selected; } @@ -198,10 +190,8 @@ public class ListUtils { numberOfIterations++) { input.forEach(it); - if (rejected.isEmpty()) { - /* Nothing was rejected, so we're done. */ - return returned; - } + /* Nothing was rejected, so we're done. */ + if (rejected.isEmpty()) return returned; } final String fmt @@ -229,9 +219,7 @@ public class ListUtils { final IList<E> returned = new FunctionalList<>(); for (final IList<E> list : lists) { - for (final E itm : list.toIterable()) { - returned.add(itm); - } + for (final E itm : list.toIterable()) returned.add(itm); } return returned; @@ -343,9 +331,7 @@ public class ListUtils { /* * Special-case small usages. */ - if (list.size() == 0) { - return permutes; - } + if (list.size() == 0) return permutes; if (list.size() == 1) { permutes.add(list); @@ -383,9 +369,7 @@ public class ListUtils { } List<T> currentPermute = new ArrayList<>(list.size()); - for (T elm : list) { - currentPermute.add(elm); - } + for (T elm : list) currentPermute.add(elm); permutes.add(currentPermute); int j = list.size() - 1; @@ -421,9 +405,7 @@ public class ListUtils { auxC[j] = q; currentPermute = new ArrayList<>(list.size()); - for (T elm : list) { - currentPermute.add(elm); - } + for (T elm : list) currentPermute.add(elm); permutes.add(currentPermute); j = list.size() - 1; diff --git a/base/src/main/java/bjc/utils/funcutils/SetUtils.java b/base/src/main/java/bjc/utils/funcutils/SetUtils.java index 83c191b..babdb8e 100644 --- a/base/src/main/java/bjc/utils/funcutils/SetUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/SetUtils.java @@ -63,9 +63,7 @@ public class SetUtils { public static <T> Set<T> toSet(T... elms) { Set<T> set = new HashSet<>(); - for (T elm : elms) { - set.add(elm); - } + for (T elm : elms) set.add(elm); return set; } diff --git a/base/src/main/java/bjc/utils/funcutils/StringUtils.java b/base/src/main/java/bjc/utils/funcutils/StringUtils.java index b7a6835..b029e1d 100644 --- a/base/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -1,19 +1,12 @@ package bjc.utils.funcutils; -import java.util.ArrayList; -import java.util.Deque; -import java.util.Iterator; -import java.util.List; -import java.util.Scanner; - +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.ibm.icu.text.BreakIterator; -import bjc.data.BooleanToggle; import bjc.utils.ioutils.LevelSplitter; -import bjc.utils.parserutils.TokenUtils; /** * Utility methods for operations on strings. @@ -35,10 +28,8 @@ public class StringUtils { * provided regex. */ public static boolean containsOnly(final String input, final String rRegex) { - if (input == null) - throw new NullPointerException("Input must not be null"); - else if (rRegex == null) - throw new NullPointerException("Regex must not be null"); + if (input == null) throw new NullPointerException("Input must not be null"); + else if (rRegex == null) throw new NullPointerException("Regex must not be null"); /* * This regular expression is fairly simple. @@ -60,9 +51,7 @@ public class StringUtils { * The number of levels to indent. */ public static void indentNLevels(final StringBuilder builder, final int levels) { - for (int i = 0; i < levels; i++) { - builder.append("\t"); - } + for (int i = 0; i < levels; i++) builder.append("\t"); } /** @@ -168,11 +157,8 @@ public class StringUtils { * @return The sequence as an English list. */ public static String toEnglishList(final Object[] objects, final boolean and) { - if (and) { - return toEnglishList(objects, "and"); - } - - return toEnglishList(objects, "or"); + if (and) return toEnglishList(objects, "and"); + else return toEnglishList(objects, "or"); } /** @@ -188,9 +174,7 @@ public class StringUtils { it.setText(value); int count = 0; - while (it.next() != BreakIterator.DONE) { - count++; - } + while (it.next() != BreakIterator.DONE) count++; return count; } @@ -209,8 +193,7 @@ public class StringUtils { Matcher mat = Pattern.compile(pattern).matcher(value); int num = 0; - while (mat.find()) - num += 1; + while (mat.find()) num += 1; return num; } @@ -246,41 +229,13 @@ public class StringUtils { int idx = strang.indexOf(vx); if (idx == -1) { - if (allowFail) - return strang; - - return null; + if (allowFail) return strang; + else return null; } return strang.substring(0, strang.indexOf(vx)); } - /** - * Split a line into a series of space-separated arguments, including string - * literals. - * - * @param com - * The command to split from - * @return The split arguments. - */ - public static List<String> processArguments(String com) { - List<String> strings = new ArrayList<>(); - - BooleanToggle togg = new BooleanToggle(); - - for (String strang : TokenUtils.removeDQuotedStrings(com)) { - if (togg.get()) { - strings.add(TokenUtils.descapeString(strang)); - } else { - for (String strung : strang.split("\\s+")) { - strings.add(strung); - } - } - } - - return strings; - } - private static class LineIterator implements Iterator<String> { private Scanner scn; @@ -306,16 +261,13 @@ public class StringUtils { boolean doLoop = true; do { - if (!scn.hasNextLine()) - break; + if (!scn.hasNextLine()) break; tmp = scn.nextLine().trim(); // Skip blank lines - if (skipBlanks && tmp.equals("")) - continue; - if (processComments && tmp.startsWith(commentInd)) - continue; + if (skipBlanks && tmp.equals("")) continue; + if (processComments && tmp.startsWith(commentInd)) continue; doLoop = tmp.endsWith("\\") && !tmp.endsWith("\\\\"); diff --git a/base/src/main/java/bjc/utils/funcutils/TestUtils.java b/base/src/main/java/bjc/utils/funcutils/TestUtils.java index 3aa20a2..c7aeec1 100644 --- a/base/src/main/java/bjc/utils/funcutils/TestUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/TestUtils.java @@ -22,9 +22,7 @@ public class TestUtils { */ @SafeVarargs public static <T> void assertIteratorEquals(Iterator<T> src, T... vals) { - for (T val : vals) { - assertEquals(val, src.next()); - } + for (T val : vals) assertEquals(val, src.next()); } /** diff --git a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java index 7f54f73..1b5c821 100644 --- a/base/src/main/java/bjc/utils/funcutils/TreeUtils.java +++ b/base/src/main/java/bjc/utils/funcutils/TreeUtils.java @@ -39,9 +39,7 @@ public class TreeUtils { /* We're at a matching leaf node. Add it. */ IList<T> finalPath = new FunctionalList<>(); - for (T ePath : path) { - finalPath.add(ePath); - } + for (T ePath : path) finalPath.add(ePath); finalPath.add(subtree.getHead()); |
