summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-03-30 09:01:35 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-03-30 09:01:35 -0400
commit7c4d9b7d6dba55c77fd1fd24beedcb6147d46cae (patch)
tree7878328079840b69292c3349c1b59453d0fe9494 /BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
parent4656403d47fe5636c61594886aa5bfc9cbbf8509 (diff)
Changed some of the token manipulators to not affect solo operators
The main change is that they won't handle tokens that consist only of the operator.
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java52
1 files changed, 30 insertions, 22 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 7630069..6e8c63a 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
*/
@@ -142,6 +142,7 @@ public class ListUtils {
* @param ops
* The operators to split on.
* @return A list of tokens split on all the operators
+ *
*/
public static FunctionalList<String> splitTokens(
FunctionalList<String> input,
@@ -152,25 +153,28 @@ 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> rt = new FunctionalList<>();
-
- int tkSize = splitTokens.getSize();
- splitTokens.forEachIndexed((idx, tk) -> {
-
- if (idx != tkSize && idx != 0) {
- rt.add(opName);
- rt.add(tk);
-
- } else {
- rt.add(tk);
-
- }
- });
-
- return rt;
+ if (StringUtils.containsOnly(tok, opRegex)) {
+ return new FunctionalList<>(tok);
+ } else {
+ FunctionalList<String> splitTokens =
+ new FunctionalList<>(
+ tok.split(opRegex));
+ FunctionalList<String> rt =
+ new FunctionalList<>();
+ int tkSize = splitTokens.getSize();
+ splitTokens.forEachIndexed((idx, tk) -> {
+
+ if (idx != tkSize && idx != 0) {
+ rt.add(opName);
+ rt.add(tk);
+
+ } else {
+ rt.add(tk);
+
+ }
+ });
+ return rt;
+ }
} else {
return new FunctionalList<>(tok);
}
@@ -188,6 +192,7 @@ public class ListUtils {
* @param ops
* The affixes to remove
* @return The tokens that have been deaffixed
+ *
*/
@SuppressWarnings("unchecked")
public static FunctionalList<String> deAffixTokens(
@@ -199,7 +204,10 @@ public class ListUtils {
(op) -> ret.transform((oldRet) -> oldRet.flatMap((tok) -> {
return (FunctionalList<String>) op
.merge((opName, opRegex) -> {
- if (tok.startsWith(opName)) {
+ if (StringUtils.containsOnly(tok,
+ opRegex)) {
+ return new FunctionalList<>(tok);
+ } else if (tok.startsWith(opName)) {
return new FunctionalList<>(op,
tok.split(opRegex)[1]);
} else if (tok.endsWith(opName)) {