From 29a595f82cbba7d8fba2a6f3c7ccda53c25e7e67 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Mon, 23 Aug 2021 12:16:34 +0300 Subject: [PATCH] Use generic type inference and method references in FlowDocTest.java (#30478) --- .../test/java/jdocs/stream/FlowDocTest.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java b/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java index f6ee45791b..a874616ef2 100644 --- a/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java @@ -52,12 +52,11 @@ public class FlowDocTest extends AbstractJavaTest { final Source source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); source.map(x -> 0); // has no effect on source, since it's immutable - source.runWith(Sink.fold(0, (agg, next) -> agg + next), system); // 55 + source.runWith(Sink.fold(0, Integer::sum), system); // 55 // returns new Source, with `map()` appended final Source zeroes = source.map(x -> 0); - final Sink> fold = - Sink.fold(0, (agg, next) -> agg + next); + final Sink> fold = Sink.fold(0, Integer::sum); zeroes.runWith(fold, system); // 0 // #source-immutable @@ -71,8 +70,7 @@ public class FlowDocTest extends AbstractJavaTest { final Source source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); // note that the Future is scala.concurrent.Future - final Sink> sink = - Sink.fold(0, (aggr, next) -> aggr + next); + final Sink> sink = Sink.fold(0, Integer::sum); // connect the Source to the Sink, obtaining a RunnableFlow final RunnableGraph> runnable = source.toMat(sink, Keep.right()); @@ -90,8 +88,7 @@ public class FlowDocTest extends AbstractJavaTest { // #materialization-runWith final Source source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - final Sink> sink = - Sink.fold(0, (aggr, next) -> aggr + next); + final Sink> sink = Sink.fold(0, Integer::sum); // materialize the flow, getting the Sinks materialized value final CompletionStage sum = source.runWith(sink, system); @@ -105,8 +102,7 @@ public class FlowDocTest extends AbstractJavaTest { public void materializedMapUnique() throws Exception { // #stream-reuse // connect the Source to the Sink, obtaining a RunnableGraph - final Sink> sink = - Sink.fold(0, (aggr, next) -> aggr + next); + final Sink> sink = Sink.fold(0, Integer::sum); final RunnableGraph> runnable = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)).toMat(sink, Keep.right()); @@ -147,7 +143,7 @@ public class FlowDocTest extends AbstractJavaTest { public void creatingSourcesSinks() throws Exception { // #source-sink // Create a source from an Iterable - List list = new LinkedList(); + List list = new LinkedList<>(); list.add(1); list.add(2); list.add(3); @@ -164,7 +160,7 @@ public class FlowDocTest extends AbstractJavaTest { // Sink that folds over the stream and returns a Future // of the final result in the MaterializedMap - Sink.fold(0, (Integer aggr, Integer next) -> aggr + next); + Sink.fold(0, Integer::sum); // Sink that returns a Future in the MaterializedMap, // containing the first element of the stream