-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParallelAggregator.java
64 lines (54 loc) · 1.76 KB
/
ParallelAggregator.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.aksw.commons.collector.domain;
import java.util.stream.Collector;
import org.aksw.commons.collector.core.CollectorFromParallelAggregator;
/**
* Aggregator suitable for parallel processing.
* Extends {@link Aggregator} with a method to combine accumulators.
*
* @author raven
*
*/
public interface ParallelAggregator<I, E, O, ACC extends Accumulator<I, E, O>>
extends Aggregator<I, E, O>
{
@Override
ACC createAccumulator();
/**
* Combine accumulators. This method is allowed to mutate any of if its arguments,
* hence accumulators should be considered exhausted after combination.
*
* @param a First participant of combination
* @param b Second participant of combination
* @return Combined accumulator
*/
ACC combine(ACC a, ACC b);
// O getValueEmpty();
/**
* Combine method that works on Objects. Exact type signatures are typically
* too unwieldy to be carried around in user code.
* Delegates to {@link #combine(Accumulator, Accumulator)} thus its notes apply.
*
* @param x First participant of combination
* @param y Second participant of combination
* @return Combined accumulator
*/
default ACC combineRaw(Object x, Object y) {
@SuppressWarnings("unchecked")
ACC a = (ACC)x;
@SuppressWarnings("unchecked")
ACC b = (ACC)y;
ACC result = combine(a, b);
return result;
}
default Collector<I, ?, O> asCollector() {
return asCollector(null);
}
/**
* Wrap this aggregator as a Java8 collector.
*
* @return The collector view of this aggregator
*/
default Collector<I, ?, O> asCollector(E env) {
return new CollectorFromParallelAggregator<>(this, env);
}
}