@@ -29,17 +29,17 @@ private ReactiveStreamsFlowBridge() {
29
29
* @return the equivalent Reactive Streams Publisher
30
30
*/
31
31
@ SuppressWarnings ("unchecked" )
32
- public static <T > org .reactivestreams .Publisher <T > toReactiveStreams (
32
+ public static <T > org .reactivestreams .Publisher <T > toPublisher (
33
33
Flow .Publisher <? extends T > flowPublisher ) {
34
34
if (flowPublisher == null ) {
35
35
throw new NullPointerException ("flowPublisher" );
36
36
}
37
- if (flowPublisher instanceof org .reactivestreams .Publisher ) {
38
- return (org .reactivestreams .Publisher <T >)flowPublisher ;
39
- }
40
37
if (flowPublisher instanceof FlowPublisherFromReactive ) {
41
38
return (org .reactivestreams .Publisher <T >)(((FlowPublisherFromReactive <T >)flowPublisher ).reactiveStreams );
42
39
}
40
+ if (flowPublisher instanceof org .reactivestreams .Publisher ) {
41
+ return (org .reactivestreams .Publisher <T >)flowPublisher ;
42
+ }
43
43
return new ReactivePublisherFromFlow <T >(flowPublisher );
44
44
}
45
45
@@ -50,21 +50,21 @@ public static <T> org.reactivestreams.Publisher<T> toReactiveStreams(
50
50
* @return the equivalent Flow Publisher
51
51
*/
52
52
@ SuppressWarnings ("unchecked" )
53
- public static <T > Flow .Publisher <T > toFlow (
53
+ public static <T > Flow .Publisher <T > toFlowPublisher (
54
54
org .reactivestreams .Publisher <? extends T > reactiveStreamsPublisher
55
55
) {
56
56
if (reactiveStreamsPublisher == null ) {
57
57
throw new NullPointerException ("reactiveStreamsPublisher" );
58
58
}
59
- if (reactiveStreamsPublisher instanceof Flow .Publisher ) {
60
- return (Flow .Publisher <T >)reactiveStreamsPublisher ;
61
- }
62
59
if (reactiveStreamsPublisher instanceof ReactivePublisherFromFlow ) {
63
60
return (Flow .Publisher <T >)(((ReactivePublisherFromFlow <T >)reactiveStreamsPublisher ).flow );
64
61
}
62
+ if (reactiveStreamsPublisher instanceof Flow .Publisher ) {
63
+ return (Flow .Publisher <T >)reactiveStreamsPublisher ;
64
+ }
65
65
return new FlowPublisherFromReactive <T >(reactiveStreamsPublisher );
66
66
}
67
-
67
+
68
68
/**
69
69
* Converts a Flow Processor into a Reactive Streams Processor.
70
70
* @param <T> the input value type
@@ -73,18 +73,18 @@ public static <T> Flow.Publisher<T> toFlow(
73
73
* @return the equivalent Reactive Streams Processor
74
74
*/
75
75
@ SuppressWarnings ("unchecked" )
76
- public static <T , U > org .reactivestreams .Processor <T , U > toReactiveStreams (
76
+ public static <T , U > org .reactivestreams .Processor <T , U > toProcessor (
77
77
Flow .Processor <? super T , ? extends U > flowProcessor
78
78
) {
79
79
if (flowProcessor == null ) {
80
80
throw new NullPointerException ("flowProcessor" );
81
81
}
82
- if (flowProcessor instanceof org .reactivestreams .Processor ) {
83
- return (org .reactivestreams .Processor <T , U >)flowProcessor ;
84
- }
85
82
if (flowProcessor instanceof FlowToReactiveProcessor ) {
86
83
return (org .reactivestreams .Processor <T , U >)(((FlowToReactiveProcessor <T , U >)flowProcessor ).reactiveStreams );
87
84
}
85
+ if (flowProcessor instanceof org .reactivestreams .Processor ) {
86
+ return (org .reactivestreams .Processor <T , U >)flowProcessor ;
87
+ }
88
88
return new ReactiveToFlowProcessor <T , U >(flowProcessor );
89
89
}
90
90
@@ -96,18 +96,18 @@ public static <T, U> org.reactivestreams.Processor<T, U> toReactiveStreams(
96
96
* @return the equivalent Flow Processor
97
97
*/
98
98
@ SuppressWarnings ("unchecked" )
99
- public static <T , U > Flow .Processor <T , U > toFlow (
99
+ public static <T , U > Flow .Processor <T , U > toFlowProcessor (
100
100
org .reactivestreams .Processor <? super T , ? extends U > reactiveStreamsProcessor
101
101
) {
102
102
if (reactiveStreamsProcessor == null ) {
103
103
throw new NullPointerException ("reactiveStreamsProcessor" );
104
104
}
105
- if (reactiveStreamsProcessor instanceof Flow .Processor ) {
106
- return (Flow .Processor <T , U >)reactiveStreamsProcessor ;
107
- }
108
105
if (reactiveStreamsProcessor instanceof ReactiveToFlowProcessor ) {
109
106
return (Flow .Processor <T , U >)(((ReactiveToFlowProcessor <T , U >)reactiveStreamsProcessor ).flow );
110
107
}
108
+ if (reactiveStreamsProcessor instanceof Flow .Processor ) {
109
+ return (Flow .Processor <T , U >)reactiveStreamsProcessor ;
110
+ }
111
111
return new FlowToReactiveProcessor <T , U >(reactiveStreamsProcessor );
112
112
}
113
113
@@ -117,10 +117,17 @@ public static <T, U> Flow.Processor<T, U> toFlow(
117
117
* @param reactiveStreamsSubscriber the Reactive Streams Subscriber instance to convert
118
118
* @return the equivalent Flow Subscriber
119
119
*/
120
+ @ SuppressWarnings ("unchecked" )
120
121
public static <T > Flow .Subscriber <T > toFlowSubscriber (org .reactivestreams .Subscriber <T > reactiveStreamsSubscriber ) {
121
122
if (reactiveStreamsSubscriber == null ) {
122
123
throw new NullPointerException ("reactiveStreamsSubscriber" );
123
124
}
125
+ if (reactiveStreamsSubscriber instanceof ReactiveToFlowSubscriber ) {
126
+ return (Flow .Subscriber <T >)((ReactiveToFlowSubscriber <T >)reactiveStreamsSubscriber ).flow ;
127
+ }
128
+ if (reactiveStreamsSubscriber instanceof Flow .Subscriber ) {
129
+ return (Flow .Subscriber <T >)reactiveStreamsSubscriber ;
130
+ }
124
131
return new FlowToReactiveSubscriber <T >(reactiveStreamsSubscriber );
125
132
}
126
133
@@ -130,19 +137,26 @@ public static <T> Flow.Subscriber<T> toFlowSubscriber(org.reactivestreams.Subscr
130
137
* @param flowSubscriber the Flow Subscriber instance to convert
131
138
* @return the equivalent Reactive Streams Subscriber
132
139
*/
133
- public static <T > org .reactivestreams .Subscriber <T > toReactiveStreamsSubscriber (Flow .Subscriber <T > flowSubscriber ) {
140
+ @ SuppressWarnings ("unchecked" )
141
+ public static <T > org .reactivestreams .Subscriber <T > toSubscriber (Flow .Subscriber <T > flowSubscriber ) {
134
142
if (flowSubscriber == null ) {
135
143
throw new NullPointerException ("flowSubscriber" );
136
144
}
145
+ if (flowSubscriber instanceof FlowToReactiveSubscriber ) {
146
+ return (org .reactivestreams .Subscriber <T >)((FlowToReactiveSubscriber <T >)flowSubscriber ).reactiveStreams ;
147
+ }
148
+ if (flowSubscriber instanceof org .reactivestreams .Subscriber ) {
149
+ return (org .reactivestreams .Subscriber <T >)flowSubscriber ;
150
+ }
137
151
return new ReactiveToFlowSubscriber <T >(flowSubscriber );
138
152
}
139
153
140
154
/**
141
155
* Wraps a Reactive Streams Subscription and converts the calls to a Flow Subscription.
142
156
*/
143
157
static final class FlowToReactiveSubscription implements Flow .Subscription {
144
- private final org .reactivestreams .Subscription reactiveStreams ;
145
-
158
+ final org .reactivestreams .Subscription reactiveStreams ;
159
+
146
160
public FlowToReactiveSubscription (org .reactivestreams .Subscription reactive ) {
147
161
this .reactiveStreams = reactive ;
148
162
}
@@ -156,15 +170,15 @@ public void request(long n) {
156
170
public void cancel () {
157
171
reactiveStreams .cancel ();
158
172
}
159
-
173
+
160
174
}
161
-
175
+
162
176
/**
163
177
* Wraps a Flow Subscription and converts the calls to a Reactive Streams Subscription.
164
178
*/
165
179
static final class ReactiveToFlowSubscription implements org .reactivestreams .Subscription {
166
- private final Flow .Subscription flow ;
167
-
180
+ final Flow .Subscription flow ;
181
+
168
182
public ReactiveToFlowSubscription (Flow .Subscription flow ) {
169
183
this .flow = flow ;
170
184
}
@@ -178,25 +192,25 @@ public void request(long n) {
178
192
public void cancel () {
179
193
flow .cancel ();
180
194
}
181
-
182
-
195
+
196
+
183
197
}
184
-
198
+
185
199
/**
186
200
* Wraps a Reactive Streams Subscriber and forwards methods of the Flow Subscriber to it.
187
201
* @param <T> the element type
188
202
*/
189
- static final class FlowToReactiveSubscriber <T >
203
+ static final class FlowToReactiveSubscriber <T >
190
204
implements Flow .Subscriber <T > {
191
- private final org .reactivestreams .Subscriber <? super T > reactiveStreams ;
192
-
205
+ final org .reactivestreams .Subscriber <? super T > reactiveStreams ;
206
+
193
207
public FlowToReactiveSubscriber (org .reactivestreams .Subscriber <? super T > reactive ) {
194
208
this .reactiveStreams = reactive ;
195
209
}
196
210
197
211
@ Override
198
212
public void onSubscribe (Flow .Subscription subscription ) {
199
- reactiveStreams .onSubscribe (new ReactiveToFlowSubscription (subscription ));
213
+ reactiveStreams .onSubscribe (( subscription == null ) ? null : new ReactiveToFlowSubscription (subscription ));
200
214
}
201
215
202
216
@ Override
@@ -213,24 +227,24 @@ public void onError(Throwable throwable) {
213
227
public void onComplete () {
214
228
reactiveStreams .onComplete ();
215
229
}
216
-
230
+
217
231
}
218
232
219
233
/**
220
234
* Wraps a Reactive Streams Subscriber and forwards methods of the Flow Subscriber to it.
221
235
* @param <T> the element type
222
236
*/
223
- static final class ReactiveToFlowSubscriber <T >
237
+ static final class ReactiveToFlowSubscriber <T >
224
238
implements org .reactivestreams .Subscriber <T > {
225
- private final Flow .Subscriber <? super T > flow ;
226
-
239
+ final Flow .Subscriber <? super T > flow ;
240
+
227
241
public ReactiveToFlowSubscriber (Flow .Subscriber <? super T > flow ) {
228
242
this .flow = flow ;
229
243
}
230
244
231
245
@ Override
232
246
public void onSubscribe (org .reactivestreams .Subscription subscription ) {
233
- flow .onSubscribe (new FlowToReactiveSubscription (subscription ));
247
+ flow .onSubscribe (( subscription == null ) ? null : new FlowToReactiveSubscription (subscription ));
234
248
}
235
249
236
250
@ Override
@@ -247,9 +261,9 @@ public void onError(Throwable throwable) {
247
261
public void onComplete () {
248
262
flow .onComplete ();
249
263
}
250
-
264
+
251
265
}
252
-
266
+
253
267
/**
254
268
* Wraps a Flow Processor and forwards methods of the Reactive Streams Processor to it.
255
269
* @param <T> the input type
@@ -258,14 +272,14 @@ public void onComplete() {
258
272
static final class ReactiveToFlowProcessor <T , U >
259
273
implements org .reactivestreams .Processor <T , U > {
260
274
final Flow .Processor <? super T , ? extends U > flow ;
261
-
275
+
262
276
public ReactiveToFlowProcessor (Flow .Processor <? super T , ? extends U > flow ) {
263
277
this .flow = flow ;
264
278
}
265
279
266
280
@ Override
267
- public void onSubscribe (org .reactivestreams .Subscription s ) {
268
- flow .onSubscribe (new FlowToReactiveSubscription (s ));
281
+ public void onSubscribe (org .reactivestreams .Subscription subscription ) {
282
+ flow .onSubscribe (( subscription == null ) ? null : new FlowToReactiveSubscription (subscription ));
269
283
}
270
284
271
285
@ Override
@@ -285,14 +299,10 @@ public void onComplete() {
285
299
286
300
@ Override
287
301
public void subscribe (org .reactivestreams .Subscriber <? super U > s ) {
288
- if (s == null ) {
289
- flow .subscribe (null );
290
- return ;
291
- }
292
- flow .subscribe (new FlowToReactiveSubscriber <U >(s ));
302
+ flow .subscribe ((s == null ) ? null : new FlowToReactiveSubscriber <U >(s ));
293
303
}
294
304
}
295
-
305
+
296
306
/**
297
307
* Wraps a Reactive Streams Processor and forwards methods of the Flow Processor to it.
298
308
* @param <T> the input type
@@ -301,14 +311,14 @@ public void subscribe(org.reactivestreams.Subscriber<? super U> s) {
301
311
static final class FlowToReactiveProcessor <T , U >
302
312
implements Flow .Processor <T , U > {
303
313
final org .reactivestreams .Processor <? super T , ? extends U > reactiveStreams ;
304
-
314
+
305
315
public FlowToReactiveProcessor (org .reactivestreams .Processor <? super T , ? extends U > reactive ) {
306
316
this .reactiveStreams = reactive ;
307
317
}
308
318
309
319
@ Override
310
- public void onSubscribe (Flow .Subscription s ) {
311
- reactiveStreams .onSubscribe (new ReactiveToFlowSubscription (s ));
320
+ public void onSubscribe (Flow .Subscription subscription ) {
321
+ reactiveStreams .onSubscribe (( subscription == null ) ? null : new ReactiveToFlowSubscription (subscription ));
312
322
}
313
323
314
324
@ Override
@@ -328,11 +338,7 @@ public void onComplete() {
328
338
329
339
@ Override
330
340
public void subscribe (Flow .Subscriber <? super U > s ) {
331
- if (s == null ) {
332
- reactiveStreams .subscribe (null );
333
- return ;
334
- }
335
- reactiveStreams .subscribe (new ReactiveToFlowSubscriber <U >(s ));
341
+ reactiveStreams .subscribe ((s == null ) ? null : new ReactiveToFlowSubscriber <U >(s ));
336
342
}
337
343
}
338
344
@@ -350,11 +356,7 @@ public ReactivePublisherFromFlow(Flow.Publisher<? extends T> flowPublisher) {
350
356
351
357
@ Override
352
358
public void subscribe (org .reactivestreams .Subscriber <? super T > reactive ) {
353
- if (reactive == null ) {
354
- flow .subscribe (null );
355
- return ;
356
- }
357
- flow .subscribe (new FlowToReactiveSubscriber <T >(reactive ));
359
+ flow .subscribe ((reactive == null ) ? null : new FlowToReactiveSubscriber <T >(reactive ));
358
360
}
359
361
}
360
362
@@ -372,12 +374,8 @@ public FlowPublisherFromReactive(org.reactivestreams.Publisher<? extends T> reac
372
374
373
375
@ Override
374
376
public void subscribe (Flow .Subscriber <? super T > flow ) {
375
- if (flow == null ) {
376
- reactiveStreams .subscribe (null );
377
- return ;
378
- }
379
- reactiveStreams .subscribe (new ReactiveToFlowSubscriber <T >(flow ));
377
+ reactiveStreams .subscribe ((flow == null ) ? null : new ReactiveToFlowSubscriber <T >(flow ));
380
378
}
381
379
}
382
380
383
- }
381
+ }
0 commit comments