#19441: Use Optional instead of Option in javadsl
This commit is contained in:
parent
ecc916abfd
commit
7a39063f2e
7 changed files with 48 additions and 68 deletions
|
|
@ -4,6 +4,7 @@
|
|||
package docs.stream;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import akka.stream.ClosedShape;
|
||||
import org.junit.AfterClass;
|
||||
|
|
@ -213,21 +214,21 @@ public class CompositionDocTest {
|
|||
|
||||
//#mat-combine-4a
|
||||
static class MyClass {
|
||||
private Promise<Option<Integer>> p;
|
||||
private Promise<Optional<Integer>> p;
|
||||
private OutgoingConnection conn;
|
||||
|
||||
public MyClass(Promise<Option<Integer>> p, OutgoingConnection conn) {
|
||||
public MyClass(Promise<Optional<Integer>> p, OutgoingConnection conn) {
|
||||
this.p = p;
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
p.success(Option.empty());
|
||||
p.success(Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
static class Combiner {
|
||||
static Future<MyClass> f(Promise<Option<Integer>> p,
|
||||
static Future<MyClass> f(Promise<Optional<Integer>> p,
|
||||
Pair<Future<OutgoingConnection>, Future<String>> rest) {
|
||||
return rest.first().map(new Mapper<OutgoingConnection, MyClass>() {
|
||||
public MyClass apply(OutgoingConnection c) {
|
||||
|
|
@ -242,13 +243,13 @@ public class CompositionDocTest {
|
|||
public void materializedValues() throws Exception {
|
||||
//#mat-combine-1
|
||||
// Materializes to Promise<BoxedUnit> (red)
|
||||
final Source<Integer, Promise<Option<Integer>>> source = Source.<Integer>maybe();
|
||||
final Source<Integer, Promise<Optional<Integer>>> source = Source.<Integer>maybe();
|
||||
|
||||
// Materializes to BoxedUnit (black)
|
||||
final Flow<Integer, Integer, BoxedUnit> flow1 = Flow.of(Integer.class).take(100);
|
||||
|
||||
// Materializes to Promise<Option<>> (red)
|
||||
final Source<Integer, Promise<Option<Integer>>> nestedSource =
|
||||
final Source<Integer, Promise<Optional<Integer>>> nestedSource =
|
||||
source.viaMat(flow1, Keep.left()).named("nestedSource");
|
||||
//#mat-combine-1
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@ package docs.stream;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
|
@ -225,7 +222,7 @@ public class FlowDocTest {
|
|||
//#flow-mat-combine
|
||||
|
||||
// An empty source that can be shut down explicitly from the outside
|
||||
Source<Integer, Promise<Option<Integer>>> source = Source.<Integer>maybe();
|
||||
Source<Integer, Promise<Optional<Integer>>> source = Source.<Integer>maybe();
|
||||
|
||||
// A flow that internally throttles elements to 1/second, and returns a Cancellable
|
||||
// which can be used to shut down the stream
|
||||
|
|
@ -236,7 +233,7 @@ public class FlowDocTest {
|
|||
|
||||
|
||||
// By default, the materialized value of the leftmost stage is preserved
|
||||
RunnableGraph<Promise<Option<Integer>>> r1 = source.via(flow).to(sink);
|
||||
RunnableGraph<Promise<Optional<Integer>>> r1 = source.via(flow).to(sink);
|
||||
|
||||
// Simple selection of materialized values by using Keep.right
|
||||
RunnableGraph<Cancellable> r2 = source.viaMat(flow, Keep.right()).to(sink);
|
||||
|
|
@ -245,17 +242,17 @@ public class FlowDocTest {
|
|||
// Using runWith will always give the materialized values of the stages added
|
||||
// by runWith() itself
|
||||
Future<Integer> r4 = source.via(flow).runWith(sink, mat);
|
||||
Promise<Option<Integer>> r5 = flow.to(sink).runWith(source, mat);
|
||||
Pair<Promise<Option<Integer>>, Future<Integer>> r6 = flow.runWith(source, sink, mat);
|
||||
Promise<Optional<Integer>> r5 = flow.to(sink).runWith(source, mat);
|
||||
Pair<Promise<Optional<Integer>>, Future<Integer>> r6 = flow.runWith(source, sink, mat);
|
||||
|
||||
// Using more complext combinations
|
||||
RunnableGraph<Pair<Promise<Option<Integer>>, Cancellable>> r7 =
|
||||
RunnableGraph<Pair<Promise<Optional<Integer>>, Cancellable>> r7 =
|
||||
source.viaMat(flow, Keep.both()).to(sink);
|
||||
|
||||
RunnableGraph<Pair<Promise<Option<Integer>>, Future<Integer>>> r8 =
|
||||
RunnableGraph<Pair<Promise<Optional<Integer>>, Future<Integer>>> r8 =
|
||||
source.via(flow).toMat(sink, Keep.both());
|
||||
|
||||
RunnableGraph<Pair<Pair<Promise<Option<Integer>>, Cancellable>, Future<Integer>>> r9 =
|
||||
RunnableGraph<Pair<Pair<Promise<Optional<Integer>>, Cancellable>, Future<Integer>>> r9 =
|
||||
source.viaMat(flow, Keep.both()).toMat(sink, Keep.both());
|
||||
|
||||
RunnableGraph<Pair<Cancellable, Future<Integer>>> r10 =
|
||||
|
|
@ -267,7 +264,7 @@ public class FlowDocTest {
|
|||
|
||||
RunnableGraph<Cancellable> r11 =
|
||||
r9.mapMaterializedValue( (nestedTuple) -> {
|
||||
Promise<Option<Integer>> p = nestedTuple.first().first();
|
||||
Promise<Optional<Integer>> p = nestedTuple.first().first();
|
||||
Cancellable c = nestedTuple.first().second();
|
||||
Future<Integer> f = nestedTuple.second();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
|
@ -148,7 +149,7 @@ public class MigrationsJava {
|
|||
}
|
||||
|
||||
//#source-creators
|
||||
Source<Integer, Promise<Option<Integer>>> src = Source.<Integer>maybe();
|
||||
Source<Integer, Promise<Optional<Integer>>> src = Source.<Integer>maybe();
|
||||
// Complete the promise with an empty option to emulate the old lazyEmpty
|
||||
promise.trySuccess(scala.Option.empty());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue