diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils')
7 files changed, 52 insertions, 61 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java index a44059b..f7210b5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java @@ -31,11 +31,9 @@ public class CollectorUtils { * The second collector to use * @return A collector that functions as mentioned above */ - public static <InitialType, AuxType1, AuxType2, FinalType1, FinalType2> - Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> - compoundCollect( - Collector<InitialType, AuxType1, FinalType1> firstCollector, - Collector<InitialType, AuxType2, FinalType2> secondCollector) { + public static <InitialType, AuxType1, AuxType2, FinalType1, FinalType2> Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> compoundCollect( + Collector<InitialType, AuxType1, FinalType1> firstCollector, + Collector<InitialType, AuxType2, FinalType2> secondCollector) { return new CompoundCollector<>(firstCollector, secondCollector); } } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java index ed8d05f..60eb163 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java @@ -6,6 +6,7 @@ import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collector; + import bjc.utils.data.IHolder; import bjc.utils.data.IPair; import bjc.utils.data.Identity; @@ -30,19 +31,11 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override - public Supplier<IHolder<IPair<AuxType1, AuxType2>>> supplier() { - return () -> new Identity<>( - new Pair<>(firstCollector.supplier().get(), - secondCollector.supplier().get())); - } - - @Override - public BiConsumer<IHolder<IPair<AuxType1, AuxType2>>, InitialType> - accumulator() { - BiConsumer<AuxType1, InitialType> firstAccumulator = - firstCollector.accumulator(); - BiConsumer<AuxType2, InitialType> secondAccumulator = - secondCollector.accumulator(); + public BiConsumer<IHolder<IPair<AuxType1, AuxType2>>, InitialType> accumulator() { + BiConsumer<AuxType1, InitialType> firstAccumulator = firstCollector + .accumulator(); + BiConsumer<AuxType2, InitialType> secondAccumulator = secondCollector + .accumulator(); return (state, value) -> { state.doWith((statePair) -> { @@ -55,10 +48,15 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override + public Set<java.util.stream.Collector.Characteristics> characteristics() { + return characteristicSet; + } + + @Override public BinaryOperator<IHolder<IPair<AuxType1, AuxType2>>> combiner() { BinaryOperator<AuxType1> firstCombiner = firstCollector.combiner(); - BinaryOperator<AuxType2> secondCombiner = - secondCollector.combiner(); + BinaryOperator<AuxType2> secondCombiner = secondCollector + .combiner(); return (leftState, rightState) -> { return leftState.unwrap((leftPair) -> { @@ -71,8 +69,7 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override - public Function<IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> - finisher() { + public Function<IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> finisher() { return (state) -> { return state.unwrap((pair) -> { return pair.bind((leftVal, rightVal) -> { @@ -85,8 +82,9 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override - public Set<java.util.stream.Collector.Characteristics> - characteristics() { - return characteristicSet; + public Supplier<IHolder<IPair<AuxType1, AuxType2>>> supplier() { + return () -> new Identity<>( + new Pair<>(firstCollector.supplier().get(), + secondCollector.supplier().get())); } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java index 34a7ee0..81781f6 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/GroupPartIteration.java @@ -16,17 +16,17 @@ import bjc.utils.funcdata.IList; * The type of element in the list being partitioned */ final class GroupPartIteration<E> implements Consumer<E> { - private IList<IList<E>> returnedList; - private IHolder<IList<E>> currentPartition; - private IList<E> rejectedItems; - private IHolder<Integer> numberInCurrentPartition; - private int numberPerPartition; - private Function<E, Integer> elementCounter; + private IList<IList<E>> returnedList; + private IHolder<IList<E>> currentPartition; + private IList<E> rejectedItems; + private IHolder<Integer> numberInCurrentPartition; + private int numberPerPartition; + private Function<E, Integer> elementCounter; public GroupPartIteration(IList<IList<E>> returned, - IHolder<IList<E>> currPart, - IList<E> rejects, IHolder<Integer> numInCurrPart, - int nPerPart, Function<E, Integer> eleCount) { + IHolder<IList<E>> currPart, IList<E> rejects, + IHolder<Integer> numInCurrPart, int nPerPart, + Function<E, Integer> eleCount) { this.returnedList = returned; this.currentPartition = currPart; this.rejectedItems = rejects; 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 913ccc4..f09a794 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java @@ -78,8 +78,7 @@ public class ListUtils { * @return The tokens that have been deaffixed * */ - public static IList<String> deAffixTokens( - IList<String> input, + public static IList<String> deAffixTokens(IList<String> input, Deque<IPair<String, String>> operators) { if (input == null) { throw new NullPointerException("Input must not be null"); @@ -88,8 +87,7 @@ public class ListUtils { "Set of operators must not be null"); } - IHolder<IList<String>> returnedList = new Identity<>( - input); + IHolder<IList<String>> returnedList = new Identity<>(input); operators.forEach((operator) -> returnedList .transform((oldReturn) -> oldReturn.flatMap((token) -> { @@ -115,9 +113,8 @@ public class ListUtils { * selected from the specified list without replacement */ - public static <E> IList<E> drawWithoutReplacement( - IList<E> list, int numberOfItems, - Function<Integer, Integer> rng) { + public static <E> IList<E> drawWithoutReplacement(IList<E> list, + int numberOfItems, Function<Integer, Integer> rng) { IList<E> selectedItems = new FunctionalList<>( new ArrayList<>(numberOfItems)); @@ -153,9 +150,8 @@ public class ListUtils { * @return A new list containing the desired number of items randomly * selected from the specified list */ - public static <E> IList<E> drawWithReplacement( - IList<E> list, int numberOfItems, - Function<Integer, Integer> rng) { + public static <E> IList<E> drawWithReplacement(IList<E> list, + int numberOfItems, Function<Integer, Integer> rng) { IList<E> selectedItems = new FunctionalList<>( new ArrayList<>(numberOfItems)); @@ -181,9 +177,8 @@ public class ListUtils { * The number of elements to put in each partition * @return A list partitioned according to the above rules */ - public static <E> IList<IList<E>> groupPartition( - IList<E> input, Function<E, Integer> elementCounter, - int numberPerPartition) { + public static <E> IList<IList<E>> groupPartition(IList<E> input, + Function<E, Integer> elementCounter, int numberPerPartition) { if (input == null) { throw new NullPointerException("Input list must not be null"); } else if (elementCounter == null) { @@ -254,8 +249,7 @@ public class ListUtils { * @return A list containing all the elements of the lists */ @SafeVarargs - public static <E> IList<E> mergeLists( - IList<E>... lists) { + public static <E> IList<E> mergeLists(IList<E>... lists) { IList<E> returnedList = new FunctionalList<>(); for (IList<E> list : lists) { @@ -279,8 +273,7 @@ public class ListUtils { * @return A list of tokens split on all the operators * */ - public static IList<String> splitTokens( - IList<String> input, + public static IList<String> splitTokens(IList<String> input, Deque<IPair<String, String>> operators) { if (input == null) { throw new NullPointerException("Input must not be null"); @@ -289,8 +282,7 @@ public class ListUtils { "Set of operators must not be null"); } - IHolder<IList<String>> returnedList = new Identity<>( - input); + IHolder<IList<String>> returnedList = new Identity<>(input); operators.forEach((operator) -> { returnedList.transform((oldReturn) -> { diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java index 9401b7e..6ddf420 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -75,10 +75,15 @@ public class StringUtils { } /** - * Print out a deque with a special case for easily showing a deque is empty - * @param <ContainedType> The type in the deque - * @param queue The deque to print - * @return A string version of the deque, with allowance for an empty deque + * Print out a deque with a special case for easily showing a deque is + * empty + * + * @param <ContainedType> + * The type in the deque + * @param queue + * The deque to print + * @return A string version of the deque, with allowance for an empty + * deque */ public static <ContainedType> String printDeque( Deque<ContainedType> queue) { diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java index 6ed4ecf..709538b 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenDeaffixer.java @@ -14,8 +14,7 @@ final class TokenDeaffixer } @Override - public IList<String> apply(String operatorName, - String operatorRegex) { + public IList<String> apply(String operatorName, String operatorRegex) { if (operatorName == null) { throw new NullPointerException( "Operator name must not be null"); diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java index b9693a7..e2d59d3 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/TokenSplitter.java @@ -14,8 +14,7 @@ final class TokenSplitter } @Override - public IList<String> apply(String operatorName, - String operatorRegex) { + public IList<String> apply(String operatorName, String operatorRegex) { if (operatorName == null) { throw new NullPointerException( "Operator name must not be null"); |
