Skip to content

Instantly share code, notes, and snippets.

@pdeva
Created July 2, 2014 18:11
Show Gist options
  • Save pdeva/67a914b5d0318f7d306f to your computer and use it in GitHub Desktop.
Save pdeva/67a914b5d0318f7d306f to your computer and use it in GitHub Desktop.
private static Map<Long, Long> multiDataPointsToPerTxnSummedValue(List<MultiDataPoint> countsList)
{
Map<DateTime, Map<Long, Long>> timeStampToTxnIdToCountsMap = new HashMap<>();
for (MultiDataPoint multiDataPoint : countsList)
{
timeStampToTxnIdToCountsMap.put(multiDataPoint.getTimestamp(), convertToPerTxnData(multiDataPoint.getData()));
}
return timeStampToTxnIdToCountsMap.entrySet().stream()
.flatMap(e -> e.getValue().entrySet().stream().map(ex ->
new Object()
{
Long txId = ex.getKey();
DataPoint dataPoint = new DataPoint(e.getKey(), ex.getValue());
}
))
.collect(
groupingBy(t -> t.txId, mapping(t -> t.dataPoint, Collectors.summingLong(dataPoint -> dataPoint.getValue().longValue())))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment