From 4e49eb8800a8be885f9b95c61cbe1008b1fed09f Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 28 Mar 2016 20:00:39 -0400 Subject: Added utility method to collapses lists into a string --- .../main/java/bjc/utils/funcutils/ListUtils.java | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) 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 b1a9dfd..7630069 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java @@ -95,8 +95,8 @@ public class ListUtils { /* * List that holds current partition */ - GenHolder> currPart = - new GenHolder<>(new FunctionalList<>()); + GenHolder> currPart = new GenHolder<>( + new FunctionalList<>()); /* * List that holds elements rejected during current pass */ @@ -152,12 +152,10 @@ public class ListUtils { (op) -> ret.transform((oldRet) -> oldRet.flatMap((tok) -> { return op.merge((opName, opRegex) -> { if (tok.contains(opName)) { - FunctionalList splitTokens = - new FunctionalList<>( - tok.split(opRegex)); + FunctionalList splitTokens = new FunctionalList<>( + tok.split(opRegex)); - FunctionalList rt = - new FunctionalList<>(); + FunctionalList rt = new FunctionalList<>(); int tkSize = splitTokens.getSize(); splitTokens.forEachIndexed((idx, tk) -> { @@ -201,18 +199,31 @@ public class ListUtils { (op) -> ret.transform((oldRet) -> oldRet.flatMap((tok) -> { return (FunctionalList) op .merge((opName, opRegex) -> { - if (tok.startsWith(opName)) { - return new FunctionalList<>(op, - tok.split(opRegex)[1]); - } else if (tok.endsWith(opName)) { - return new FunctionalList<>( - tok.split(opRegex)[0], op); - } else { - return new FunctionalList<>(tok); - } - }); + if (tok.startsWith(opName)) { + return new FunctionalList<>(op, + tok.split(opRegex)[1]); + } else if (tok.endsWith(opName)) { + return new FunctionalList<>( + tok.split(opRegex)[0], op); + } else { + return new FunctionalList<>(tok); + } + }); }))); return ret.unwrap((l) -> l); } + + /** + * 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(FunctionalList input) { + return input.reduceAux("", + (currString, state) -> state + currString, (s) -> s); + } } -- cgit v1.2.3