@Test public void testCf4ForTwoFiles() throws IOException { Cfs .countLines(METAMORPHOSIS, DISCOURSE_ON_THE_METHOD, DIVINE_COMEDY) .thenAccept(n -> assertEquals(10423, n.intValue())) .join(); }
public static CompletableFuture<Integer> countLines(String...paths) { CompletableFuture[] cfs = Stream .of(paths) .map(p -> AsyncFiles.readAll(p).thenApply(body -> body.split("\n").length)) .toArray(size -> new CompletableFuture[size]); return CompletableFuture .allOf(cfs) .thenApply(__ -> Stream .of(cfs) .mapToInt(cf -> (int) cf.join()) .sum()); }
Cfs { public static CompletableFuture<Integer> countLines(String...paths) { CompletableFuture[] cfs = Stream .of(paths) .map(p -> AsyncFiles.readAll(p).thenApply(body -> body.split("\n").length)) .toArray(size -> new CompletableFuture[size]); return CompletableFuture .allOf(cfs) .thenApply(__ -> Stream .of(cfs) .mapToInt(cf -> (int) cf.join()) .sum()); } }
Cfs { public static CompletableFuture<Integer> countLines(String...paths) { CompletableFuture[] cfs = Stream .of(paths) .map(p -> AsyncFiles.readAll(p).thenApply(body -> body.split("\n").length)) .toArray(size -> new CompletableFuture[size]); return CompletableFuture .allOf(cfs) .thenApply(__ -> Stream .of(cfs) .mapToInt(cf -> (int) cf.join()) .sum()); }  }
Cfs { public static CompletableFuture<Integer> countLines(String...paths) { CompletableFuture[] cfs = Stream .of(paths) .map(p -> AsyncFiles.readAll(p).thenApply(body -> body.split("\n").length)) .toArray(size -> new CompletableFuture[size]); return CompletableFuture .allOf(cfs) .thenApply(__ -> Stream .of(cfs) .mapToInt(cf -> (int) cf.join()) .sum()); }  static CompletableFuture<Integer> countLines(String...paths); }
Cfs { public static CompletableFuture<Integer> countLines(String...paths) { CompletableFuture[] cfs = Stream .of(paths) .map(p -> AsyncFiles.readAll(p).thenApply(body -> body.split("\n").length)) .toArray(size -> new CompletableFuture[size]); return CompletableFuture .allOf(cfs) .thenApply(__ -> Stream .of(cfs) .mapToInt(cf -> (int) cf.join()) .sum()); }  static CompletableFuture<Integer> countLines(String...paths);  }