From 292642a5b426a9aa541f3f588faf4ee24e1b0e8b Mon Sep 17 00:00:00 2001 From: JSiggelkow Date: Mon, 29 Jul 2024 23:00:30 +0200 Subject: [PATCH] Refactor getTotalSoldUnitsInMillionsPerMaker method Simplify the calculation and grouping of total sold units by using `Collectors.groupingBy` and `Collectors.summingDouble` directly on the console stream. --- Queries.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Queries.java b/Queries.java index ffd2926..f961570 100644 --- a/Queries.java +++ b/Queries.java @@ -52,15 +52,8 @@ public List getSoldUnitsInMillionsPerYearFromAllOutdatedConsoles() { } public Map getTotalSoldUnitsInMillionsPerMaker() { - Function>, Maker> entrySetToMaker = entrySet -> entrySet.getKey(); - Function>, Double> entrySetToSoldUnits = - entrySet -> - entrySet.getValue().stream() - .mapToDouble(console -> console.soldUnitsInMillions()) - .sum(); - - return getAllConsolesByMaker().entrySet().stream() - .collect(Collectors.toMap(entrySetToMaker, entrySetToSoldUnits)); + return consoles.stream() + .collect(Collectors.groupingBy(Console::maker, Collectors.summingDouble(Console::soldUnitsInMillions))); } public boolean isAllConsolesWithMoreThan50MillionSoldUnits() {