I have a list of Records. Which has two fields: LocalDateTime instant and a Double data.
I want to groupBy all the records by Hour and create a Map<Integer, Double>. Where the keys (Integer) are hours and values(Double) are last Data of that hour - first Data of that hour.
What I have done so far is following:
Function<Record, Integer> keyFunc = rec->rec.getInstant().getHour();
Map<Integer, List<Record>> valueMap = records.stream().collect(Collectors.groupingBy(keyFunc));
I want the value map to hold Double instead of List<Records>.
For Example: List records can be following:
Instant Data
01:01:24 23.7
01:02:34 24.2
01:05:23 30.2
...
01:59:27 50.2
02:03:23 54.4
02:04:23 56.3
...
02:58:23 70.3
...
etc
Resulting map should be:
Key Value
1 26.5 (50.2-23.7)
2 15.9 (70.3-54.4)
...
values(Double) are last Data of that hour - first Data of that hour.?