// 11. Zwróć firmę która dokonała zakupów na największą kwotę public static void exercise11X(List companies){ companies .stream() .collect(Collectors.groupingBy(Company::getName, Collectors.mapping(c -> c.getPurchaseList().stream().mapToDouble(p -> p.getQuantity() * p.getProduct().getPrice()).sum() , Collectors.toList()))); companies .stream() .collect(Collectors.toMap(Company::getName, c -> c.getPurchaseList().stream().mapToDouble(p -> p.getQuantity() * p.getProduct().getPrice()).sum(), (c1,c2) -> c1+c2)) .entrySet() .stream() .max(Comparator.comparingDouble(Entry::getValue)); } public static Optional exercise11(List companies){ return companies .stream() .max(Comparator.comparingDouble(c -> c.getPurchaseList().stream().mapToDouble(p -> p.getQuantity() * p.getProduct().getPrice()).sum())); } // 14. Wypisz firmy które 15 stycznia 2018 kupiły "Network Switch" public static void exercise14(List companies){ companies .stream() .filter(c -> c.getPurchaseList().stream().map(p -> p.getPurchaseDate()).anyMatch(d -> d.isEqual(LocalDate.of(2018, 1, 15)))) .filter(c -> c.getPurchaseList().stream().map(p -> p.getProduct().getName()).anyMatch(n -> n.equalsIgnoreCase("network switch"))) .forEach(c -> System.out.println(c.getName() + " " + c.getCityHeadquarters())); }