diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-07-28 16:44:36 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-07-28 16:44:36 -0400 |
| commit | dca8e9f586fd595a7995f07788318fb92b8cce79 (patch) | |
| tree | 4fdf216d4a30c2c663d4a429f79cfa471c8579c4 /BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java | |
| parent | b1317e5e62bb044cd8a676cb3fc2da86e9922caf (diff) | |
Format/Cleanup pass
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java index 00ec653..e446b64 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java @@ -50,6 +50,29 @@ public interface IList<ContainedType> { boolean anyMatch(Predicate<ContainedType> matchPredicate); /** + * Reduce the contents of this list using a collector + * + * @param <StateType> + * The intermediate accumulation type + * @param <ReducedType> + * The final, reduced type + * @param collector + * The collector to use for reduction + * @return The reduced list + */ + public default <StateType, ReducedType> ReducedType collect( + Collector<ContainedType, StateType, ReducedType> collector) { + BiConsumer<StateType, ContainedType> accumulator = collector + .accumulator(); + + return reduceAux(collector.supplier().get(), (value, state) -> { + accumulator.accept(state, value); + + return state; + }, collector.finisher()); + } + + /** * Combine this list with another one into a new list and merge the * results. Works sort of like a combined zip/map over resulting pairs. * Does not change the underlying list. @@ -136,8 +159,8 @@ public interface IList<ContainedType> { * The predicate to match by * @return A list containing all elements that match the predicate */ - IList<ContainedType> - getMatching(Predicate<ContainedType> matchPredicate); + IList<ContainedType> getMatching( + Predicate<ContainedType> matchPredicate); /** * Retrieve the size of the wrapped list @@ -164,8 +187,8 @@ public interface IList<ContainedType> { * The function to apply to each element in the list * @return A new list containing the mapped elements of this list. */ - <MappedType> IList<MappedType> - map(Function<ContainedType, MappedType> elementTransformer); + <MappedType> IList<MappedType> map( + Function<ContainedType, MappedType> elementTransformer); /** * Zip two lists into a list of pairs @@ -178,8 +201,8 @@ public interface IList<ContainedType> { * @return A list containing pairs of this element and the specified * list */ - <OtherType> IList<IPair<ContainedType, OtherType>> - pairWith(IList<OtherType> rightList); + <OtherType> IList<IPair<ContainedType, OtherType>> pairWith( + IList<OtherType> rightList); /** * Partition this list into a list of sublists @@ -199,16 +222,6 @@ public interface IList<ContainedType> { void prepend(ContainedType item); /** - * Select a random item from this list, using the provided random - * number generator. - * - * @param rnd - * The random number generator to use. - * @return A random element from this list. - */ - ContainedType randItem(Function<Integer, Integer> rnd); - - /** * Select a random item from the list, using a default random number * generator * @@ -219,6 +232,16 @@ public interface IList<ContainedType> { } /** + * Select a random item from this list, using the provided random + * number generator. + * + * @param rnd + * The random number generator to use. + * @return A random element from this list. + */ + ContainedType randItem(Function<Integer, Integer> rnd); + + /** * Reduce this list to a single value, using a accumulative approach. * * @param <StateType> @@ -310,27 +333,4 @@ public interface IList<ContainedType> { * @return An iterable view onto the list */ public Iterable<ContainedType> toIterable(); - - /** - * Reduce the contents of this list using a collector - * - * @param <StateType> - * The intermediate accumulation type - * @param <ReducedType> - * The final, reduced type - * @param collector - * The collector to use for reduction - * @return The reduced list - */ - public default <StateType, ReducedType> ReducedType collect( - Collector<ContainedType, StateType, ReducedType> collector) { - BiConsumer<StateType, ContainedType> accumulator = - collector.accumulator(); - - return reduceAux(collector.supplier().get(), (value, state) -> { - accumulator.accept(state, value); - - return state; - }, collector.finisher()); - } }
\ No newline at end of file |
