diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-09-28 13:44:04 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-09-28 13:44:04 -0400 |
| commit | f7a10e0e57d6f0ea83643c3d5763ff405af73337 (patch) | |
| tree | 7a56cbf7e5a8b6fa738d2cf469a86eea14d5d89a /BJC-Utils2/src/main/java/bjc/utils/funcutils | |
| parent | ba0a3f53a88842a94ea6a1a6d45f61416b593e47 (diff) | |
Formatting pass
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils')
5 files changed, 71 insertions, 57 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 f7210b5..0a1efd5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java @@ -31,9 +31,14 @@ 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 60eb163..257f005 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CompoundCollector.java @@ -12,13 +12,16 @@ import bjc.utils.data.IPair; import bjc.utils.data.Identity; import bjc.utils.data.Pair; -final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, FinalType2> - implements - Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, IPair<FinalType1, FinalType2>> { - private Set<java.util.stream.Collector.Characteristics> characteristicSet; +final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, + FinalType2> implements + Collector<InitialType, IHolder<IPair<AuxType1, AuxType2>>, + IPair<FinalType1, FinalType2>> { + private Set< + java.util.stream.Collector.Characteristics> characteristicSet; private Collector<InitialType, AuxType1, FinalType1> firstCollector; - private Collector<InitialType, AuxType2, FinalType2> secondCollector; + private Collector<InitialType, AuxType2, + FinalType2> secondCollector; public CompoundCollector( Collector<InitialType, AuxType1, FinalType1> firstCollector, @@ -31,11 +34,13 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override - public BiConsumer<IHolder<IPair<AuxType1, AuxType2>>, InitialType> accumulator() { + public BiConsumer<IHolder<IPair<AuxType1, AuxType2>>, + InitialType> accumulator() { BiConsumer<AuxType1, InitialType> firstAccumulator = firstCollector .accumulator(); - BiConsumer<AuxType2, InitialType> secondAccumulator = secondCollector - .accumulator(); + BiConsumer<AuxType2, + InitialType> secondAccumulator = secondCollector + .accumulator(); return (state, value) -> { state.doWith((statePair) -> { @@ -48,15 +53,16 @@ final class CompoundCollector<InitialType, AuxType1, AuxType2, FinalType1, Final } @Override - public Set<java.util.stream.Collector.Characteristics> characteristics() { + 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) -> { @@ -69,7 +75,8 @@ 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) -> { 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 d65603b..3b03406 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java @@ -216,8 +216,10 @@ public class ListUtils { /* * Run up to a certain number of passes */ - for (int numberOfIterations = 0; numberOfIterations < MAX_NTRIESPART - && !rejectedElements.isEmpty(); numberOfIterations++) { + for (int numberOfIterations = 0; + numberOfIterations < MAX_NTRIESPART + && !rejectedElements.isEmpty(); + numberOfIterations++) { input.forEach(new GroupPartIteration<>(returnedList, currentPartition, rejectedElements, numberInCurrentPartition, numberPerPartition, @@ -261,42 +263,6 @@ public class ListUtils { return returnedList; } - /** - * Split tokens in a list of tokens into multiple tokens. - * - * The intended use is for expression parsers so that you can enter - * something like 1+1 instead of 1 + 1. - * - * @param input - * The tokens to split - * @param operators - * Pairs of operators to split on and regexes that match - * those operators - * @return A list of tokens split on all the operators - * - */ - public static IList<String> splitTokens(IList<String> input, - Deque<IPair<String, String>> operators) { - if (input == null) { - throw new NullPointerException("Input must not be null"); - } else if (operators == null) { - throw new NullPointerException( - "Set of operators must not be null"); - } - - IHolder<IList<String>> returnedList = new Identity<>(input); - - operators.forEach((operator) -> { - returnedList.transform((oldReturn) -> { - return oldReturn.flatMap((token) -> { - return operator.merge(new TokenSplitter(token)); - }); - }); - }); - - return returnedList.getValue(); - } - public static <E> IList<E> padList(IList<E> list, Function<E, Integer> counter, int size, Supplier<E> padSource) { @@ -337,4 +303,40 @@ public class ListUtils { return ret; } + + /** + * Split tokens in a list of tokens into multiple tokens. + * + * The intended use is for expression parsers so that you can enter + * something like 1+1 instead of 1 + 1. + * + * @param input + * The tokens to split + * @param operators + * Pairs of operators to split on and regexes that match + * those operators + * @return A list of tokens split on all the operators + * + */ + public static IList<String> splitTokens(IList<String> input, + Deque<IPair<String, String>> operators) { + if (input == null) { + throw new NullPointerException("Input must not be null"); + } else if (operators == null) { + throw new NullPointerException( + "Set of operators must not be null"); + } + + IHolder<IList<String>> returnedList = new Identity<>(input); + + operators.forEach((operator) -> { + returnedList.transform((oldReturn) -> { + return oldReturn.flatMap((token) -> { + return operator.merge(new TokenSplitter(token)); + }); + }); + }); + + return returnedList.getValue(); + } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java index 1f8f61d..419c787 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java @@ -26,8 +26,8 @@ public class NumberUtils { } else { int result = 1; - for (int currentSub = 0; currentSub < power - + 1; currentSub++) { + for (int currentSub = 0; currentSub < power + 1; + currentSub++) { result *= value - currentSub; } 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 6ddf420..7573bfb 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/StringUtils.java @@ -85,8 +85,8 @@ public class StringUtils { * @return A string version of the deque, with allowance for an empty * deque */ - public static <ContainedType> String printDeque( - Deque<ContainedType> queue) { + public static < + ContainedType> String printDeque(Deque<ContainedType> queue) { return queue.isEmpty() ? "(none)" : queue.toString(); } } |
