diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-28 20:00:39 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-28 20:00:39 -0400 |
| commit | 4e49eb8800a8be885f9b95c61cbe1008b1fed09f (patch) | |
| tree | 138a079d3dd236a9279c0cfed2363e2f38408d4c /BJC-Utils2/src | |
| parent | f4c758dc79b704865ac5ae96c6e48aac6ab1d097 (diff) | |
Added utility method to collapses lists into a string
Diffstat (limited to 'BJC-Utils2/src')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java | 45 |
1 files 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<FunctionalList<E>> currPart = - new GenHolder<>(new FunctionalList<>()); + GenHolder<FunctionalList<E>> 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<String> splitTokens = - new FunctionalList<>( - tok.split(opRegex)); + FunctionalList<String> splitTokens = new FunctionalList<>( + tok.split(opRegex)); - FunctionalList<String> rt = - new FunctionalList<>(); + FunctionalList<String> 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<String>) 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<String> input) { + return input.reduceAux("", + (currString, state) -> state + currString, (s) -> s); + } } |
