From 77fcc58d1facffbc3af50be8c05985350e9f1355 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 17 Apr 2016 15:01:44 -0400 Subject: Code maintenace and changes --- .../java/bjc/utils/funcutils/TokenDeaffixer.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java new file mode 100644 index 0000000..1cf5d44 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java @@ -0,0 +1,39 @@ +package bjc.utils.funcutils; + +import java.util.function.BiFunction; + +import bjc.utils.funcdata.FunctionalList; +import bjc.utils.funcdata.IFunctionalList; + +final class TokenDeaffixer implements + BiFunction> { + private String token; + + public TokenDeaffixer(String tok) { + token = tok; + } + + @Override + public IFunctionalList apply(String operatorName, + String operatorRegex) { + 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"); + } + + if (StringUtils.containsOnly(token, operatorRegex)) { + return new FunctionalList<>(token); + } else if (token.startsWith(operatorName)) { + return new FunctionalList<>(operatorName, + token.split(operatorRegex)[1]); + } else if (token.endsWith(operatorName)) { + return new FunctionalList<>(token.split(operatorRegex)[0], + operatorName); + } else { + return new FunctionalList<>(token); + } + } +} \ No newline at end of file -- cgit v1.2.3