summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/funcutils/CollectorUtils.java
blob: a92c2d1fc8cbd73359e7f30b1292ad59a9aa70c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package bjc.utils.funcutils;

import java.util.stream.Collector;

import bjc.data.Holder;
import bjc.data.Pair;

/**
 * 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 first
	 *                      The first collector to use.
	 *
	 * @param second
	 *                      The second collector to use.
	 *
	 * @return A collector that functions as mentioned above.
	 */
	public static <InitialType, AuxType1, AuxType2, FinalType1, FinalType2>
			Collector<InitialType, Holder<Pair<AuxType1, AuxType2>>,
					Pair<FinalType1, FinalType2>>
			compoundCollect(final Collector<InitialType, AuxType1, FinalType1> first,
					final Collector<InitialType, AuxType2, FinalType2> second) {
		return new CompoundCollector<>(first, second);
	}
}