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/funcutils/CollectorUtils.java | |
| parent | 507f506093c84ae764d0c26b24d9d055e8613aae (diff) | |
Added interface to JDK collector API
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java | 41 |
1 files changed, 41 insertions, 0 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 new file mode 100644 index 0000000..a44059b --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/CollectorUtils.java @@ -0,0 +1,41 @@ +package bjc.utils.funcutils; + +import java.util.stream.Collector; + +import bjc.utils.data.IHolder; +import bjc.utils.data.IPair; + +/** + * Utilities for producing implementations of {@link Collector} + * + * @author ben + * + */ +public class CollectorUtils { + /** + * Create a collector that applies two collectors at once + * + * @param <InitialType> + * The type of the collection to collect from + * @param <AuxType1> + * The intermediate type of the first collector + * @param <AuxType2> + * The intermediate type of the second collector + * @param <FinalType1> + * The final type of the first collector + * @param <FinalType2> + * The final type of the second collector + * @param firstCollector + * The first collector to use + * @param secondCollector + * 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) { + return new CompoundCollector<>(firstCollector, secondCollector); + } +} |
