// 11. Zwróć firmę która dokonała zakupów na największą kwotę
public static void exercise11X(List<Company> 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<Company> exercise11(List<Company> 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<Company> 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()));
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}