I've a stream of MetricGroup, where:
public class MetricGroup {
private String application;
private int uploadedDocs;
private long uploadedKbs;
// getters and setters
}
I need to sumarize all application metrics. I mean, for each application (MetricGroup.application) I need to add all metric.uploadedDocs into a sumMetric.uploadedDocs and metric.uploadedKds into a sumMetric.uploadedKbs.
I figure out I need some kind of groupingBy
Stream.of(
new MetricGroup("app1", 1,100),
new MetricGroup("app1", 1,300),
new MetricGroup("app2", 1,200)
)
.collect(Collector.groupingBy(MetricGroup::getApplication, accumulator??, combiner??)
The result would be a stream with:
< MetricGroup("app1", 2, 400) , MetricGroup("app2", 1, 200) >
Any ideas?