-
Notifications
You must be signed in to change notification settings - Fork 8
/
Blog1.java
37 lines (34 loc) · 1.4 KB
/
Blog1.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
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.stream.Collectors;
import static java.lang.Double.parseDouble;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.summarizingDouble;
public class Blog1 {
public static void main(String[] args) throws Exception {
var start = System.currentTimeMillis();
calculate();
System.err.format("Took %,d ms\n", System.currentTimeMillis() - start);
}
private static void calculate() throws Exception {
var allStats = new BufferedReader(new FileReader("measurements.txt"))
.lines()
.parallel()
.collect(
groupingBy(line -> line.substring(0, line.indexOf(';')),
summarizingDouble(line ->
parseDouble(line.substring(line.indexOf(';') + 1)))));
var result = allStats.entrySet().stream().collect(Collectors.toMap(
Entry::getKey,
e -> {
var stats = e.getValue();
return String.format("%.1f/%.1f/%.1f",
stats.getMin(), stats.getAverage(), stats.getMax());
},
(l, r) -> r,
TreeMap::new));
System.out.println(result);
}
}