From fff6dc5d43539af05ae2679640240b8545b36947 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 10 May 2016 21:58:08 -0400 Subject: Added interface to JDK collector API --- .../src/main/java/bjc/utils/funcdata/IList.java | 29 +++++++++++++++++++--- .../src/main/java/bjc/utils/funcdata/IMap.java | 1 - 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata') 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 b6363e7..00ec653 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java @@ -6,6 +6,7 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; +import java.util.stream.Collector; import bjc.utils.data.IPair; @@ -18,7 +19,6 @@ import bjc.utils.data.IPair; * The type in this list */ public interface IList { - /** * Add an item to this list * @@ -302,12 +302,35 @@ public interface IList { * The type of array to return * @return The list, as an array */ - ContainedType[] toArray(ContainedType[] arrType); + public ContainedType[] toArray(ContainedType[] arrType); /** * Convert the list into a iterable * * @return An iterable view onto the list */ - Iterable toIterable(); + public Iterable toIterable(); + + /** + * Reduce the contents of this list using a collector + * + * @param + * The intermediate accumulation type + * @param + * The final, reduced type + * @param collector + * The collector to use for reduction + * @return The reduced list + */ + public default ReducedType collect( + Collector collector) { + BiConsumer accumulator = + collector.accumulator(); + + return reduceAux(collector.supplier().get(), (value, state) -> { + accumulator.accept(state, value); + + return state; + }, collector.finisher()); + } } \ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java index f5f7a26..243e58a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java @@ -16,7 +16,6 @@ import java.util.function.Function; * */ public interface IMap { - /** * Check if this map contains the specified key * -- cgit v1.2.3