@@ -20,29 +20,29 @@ public Thread newThread(Runnable r) {
2020 return t ;
2121 }
2222 });
23-
2423/*
2524 public List<String> findPriceSequential(String product) {
2625 return shops.stream()
2726 .map(shop -> shop.getName() + " price is " + shop.calculatePrice(product))
28- .collect(Collectors.<String> toList());
27+ .collect(Collectors.toList());
2928 }
3029
3130 public List<String> findPriceParallel(String product) {
3231 return shops.parallelStream()
3332 .map(shop -> shop.getName() + " price is " + shop.calculatePrice(product))
34- .collect(Collectors.<String> toList());
33+ .collect(Collectors.toList());
3534 }
3635
3736 public List<String> findPrice(String product) {
3837 List<CompletableFuture<String>> priceFutures =
3938 shops.stream()
40- .map(shop -> CompletableFuture.supplyAsync(() -> shop.getName() + " price is " + shop.calculatePrice(product)))
41- .collect(Collectors.<CompletableFuture<String>>toList());
39+ .map(shop -> CompletableFuture.supplyAsync(() -> shop.getName() + " price is "
40+ + shop.calculatePrice(product), executor))
41+ .collect(Collectors.toList());
4242
4343 List<String> prices = priceFutures.stream()
4444 .map(CompletableFuture::join)
45- .collect(Collectors.<String> toList());
45+ .collect(Collectors.toList());
4646 return prices;
4747 //return sequence(priceFutures).join();
4848 }
@@ -52,15 +52,15 @@ public List<String> findPriceSequential(String product) {
5252 .map (shop -> shop .getPrice (product ))
5353 .map (Quote ::parse )
5454 .map (Discount ::applyDiscount )
55- .collect (Collectors .< String > toList ());
55+ .collect (Collectors .toList ());
5656 }
5757
5858 public List <String > findPriceParallel (String product ) {
5959 return shops .parallelStream ()
6060 .map (shop -> shop .getPrice (product ))
6161 .map (Quote ::parse )
6262 .map (Discount ::applyDiscount )
63- .collect (Collectors .< String > toList ());
63+ .collect (Collectors .toList ());
6464 }
6565
6666 public List <String > findPrice (String product ) {
@@ -69,7 +69,7 @@ public List<String> findPrice(String product) {
6969
7070 return priceFutures .stream ()
7171 .map (CompletableFuture ::join )
72- .collect (Collectors .< String > toList ());
72+ .collect (Collectors .toList ());
7373 }
7474
7575 public Stream <CompletableFuture <String >> findPriceStream (String product ) {
@@ -85,5 +85,7 @@ public void printPricesStream() {
8585 .map (f -> f .thenAccept (s -> System .out .println (s + " (done in " + ((System .nanoTime () - start ) / 1_000_000 ) + " msecs)" )))
8686 .toArray (size -> new CompletableFuture [size ]);
8787 CompletableFuture .allOf (futures ).join ();
88+ System .out .println ("All shops have now responded in " + ((System .nanoTime () - start ) / 1_000_000 ) + " msecs" );
8889 }
90+
8991}
0 commit comments