diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-05-10 21:58:08 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-05-10 21:58:08 -0400 |
| commit | fff6dc5d43539af05ae2679640240b8545b36947 (patch) | |
| tree | 89dc91bdc013415b76351a22126bffe86a750d7d /BJC-Utils2/src/main/java/bjc/utils/funcdata | |
| parent | 507f506093c84ae764d0c26b24d9d055e8613aae (diff) | |
Added interface to JDK collector API
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java | 29 | ||||
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java | 1 |
2 files changed, 26 insertions, 4 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 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<ContainedType> { - /** * Add an item to this list * @@ -302,12 +302,35 @@ public interface IList<ContainedType> { * 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<ContainedType> toIterable(); + 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 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<KeyType, ValueType> { - /** * Check if this map contains the specified key * |
