From 275a627719fc2231b16caea41130ff09f0f2b6a1 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Fri, 8 Apr 2016 13:28:09 -0400 Subject: Switch functional data to use interfaces --- .../main/java/bjc/utils/funcutils/ListUtils.java | 57 +++++++++++----------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java') 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 1d2750b..871e1cf 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java @@ -6,8 +6,9 @@ import java.util.function.Consumer; import java.util.function.Function; import bjc.utils.data.GenHolder; -import bjc.utils.data.Pair; +import bjc.utils.data.IPair; import bjc.utils.funcdata.FunctionalList; +import bjc.utils.funcdata.IFunctionalList; /** * Utilities for manipulating FunctionalLists that don't belong in the @@ -20,7 +21,7 @@ public class ListUtils { private static final int MAX_NTRIESPART = 50; private static final class TokenDeaffixer - implements BiFunction> { + implements BiFunction> { private String token; public TokenDeaffixer(String tok) { @@ -28,7 +29,7 @@ public class ListUtils { } @Override - public FunctionalList apply(String operatorName, + public IFunctionalList apply(String operatorName, String operatorRegex) { if (operatorName == null) { throw new NullPointerException( @@ -53,7 +54,7 @@ public class ListUtils { } private static final class TokenSplitter - implements BiFunction> { + implements BiFunction> { private String tokenToSplit; public TokenSplitter(String tok) { @@ -61,7 +62,7 @@ public class ListUtils { } @Override - public FunctionalList apply(String operatorName, + public IFunctionalList apply(String operatorName, String operatorRegex) { if (operatorName == null) { throw new NullPointerException( @@ -77,10 +78,10 @@ public class ListUtils { return new FunctionalList<>(tokenToSplit); } - FunctionalList splitTokens = new FunctionalList<>( + IFunctionalList splitTokens = new FunctionalList<>( tokenToSplit.split(operatorRegex)); - FunctionalList result = new FunctionalList<>(); + IFunctionalList result = new FunctionalList<>(); int tokenExpansionSize = splitTokens.getSize(); @@ -112,17 +113,17 @@ public class ListUtils { */ private static final class GroupPartIteration implements Consumer { - private FunctionalList> returnedList; - private GenHolder> currentPartition; - private FunctionalList rejectedItems; + private IFunctionalList> returnedList; + private GenHolder> currentPartition; + private IFunctionalList rejectedItems; private GenHolder numberInCurrentPartition; private int numberPerPartition; private Function elementCounter; public GroupPartIteration( - FunctionalList> returned, - GenHolder> currPart, - FunctionalList rejects, + IFunctionalList> returned, + GenHolder> currPart, + IFunctionalList rejects, GenHolder numInCurrPart, int nPerPart, Function eleCount) { this.returnedList = returned; @@ -174,8 +175,8 @@ public class ListUtils { * The number of elements to put in each partition * @return A list partitioned according to the above rules */ - public static FunctionalList> groupPartition( - FunctionalList input, Function elementCounter, + public static IFunctionalList> groupPartition( + IFunctionalList input, Function elementCounter, int numberPerPartition) { if (input == null) { throw new NullPointerException("Input list must not be null"); @@ -192,17 +193,17 @@ public class ListUtils { /* * List that holds our results */ - FunctionalList> returnedList = new FunctionalList<>(); + IFunctionalList> returnedList = new FunctionalList<>(); /* * List that holds current partition */ - GenHolder> currentPartition = new GenHolder<>( + GenHolder> currentPartition = new GenHolder<>( new FunctionalList<>()); /* * List that holds elements rejected during current pass */ - FunctionalList rejectedElements = new FunctionalList<>(); + IFunctionalList rejectedElements = new FunctionalList<>(); /* * The effective number of elements in the current partitition @@ -251,9 +252,9 @@ public class ListUtils { * @return A list of tokens split on all the operators * */ - public static FunctionalList splitTokens( - FunctionalList input, - Deque> operators) { + public static IFunctionalList splitTokens( + IFunctionalList input, + Deque> operators) { if (input == null) { throw new NullPointerException("Input must not be null"); } else if (operators == null) { @@ -261,7 +262,7 @@ public class ListUtils { "Set of operators must not be null"); } - GenHolder> returnedList = new GenHolder<>( + GenHolder> returnedList = new GenHolder<>( input); operators.forEach((operator) -> returnedList @@ -282,9 +283,9 @@ public class ListUtils { * @return The tokens that have been deaffixed * */ - public static FunctionalList deAffixTokens( - FunctionalList input, - Deque> operators) { + public static IFunctionalList deAffixTokens( + IFunctionalList input, + Deque> operators) { if (input == null) { throw new NullPointerException("Input must not be null"); } else if (operators == null) { @@ -292,7 +293,7 @@ public class ListUtils { "Set of operators must not be null"); } - GenHolder> returnedList = new GenHolder<>( + GenHolder> returnedList = new GenHolder<>( input); operators.forEach((operator) -> returnedList @@ -311,7 +312,7 @@ public class ListUtils { * The list of tokens to collapse * @return The collapsed string of tokens */ - public static String collapseTokens(FunctionalList input) { + public static String collapseTokens(IFunctionalList input) { if (input == null) { throw new NullPointerException("Input must not be null"); } @@ -329,7 +330,7 @@ public class ListUtils { * The seperator to use for seperating tokens * @return The collapsed string of tokens */ - public static String collapseTokens(FunctionalList input, + public static String collapseTokens(IFunctionalList input, String seperator) { if (input == null) { throw new NullPointerException("Input must not be null"); -- cgit v1.2.3