@@ -34,11 +34,11 @@ public static <T> org.reactivestreams.Publisher<T> toReactiveStreams(
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 );
39
+ if (flowPublisher instanceof org .reactivestreams .Publisher ) {
40
+ }
41
+ return (org .reactivestreams .Publisher <T >)flowPublisher ;
42
42
}
43
43
return new ReactivePublisherFromFlow <T >(flowPublisher );
44
44
}
@@ -56,12 +56,12 @@ public static <T> Flow.Publisher<T> toFlow(
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
@@ -79,12 +79,12 @@ public static <T, U> org.reactivestreams.Processor<T, U> toReactiveStreams(
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
@@ -102,12 +102,12 @@ public static <T, U> Flow.Processor<T, U> toFlow(
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 > toFlow (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,18 +137,25 @@ public static <T> Flow.Subscriber<T> toFlow(org.reactivestreams.Subscriber<T> re
130
137
* @param flowSubscriber the Flow Subscriber instance to convert
131
138
* @return the equivalent Reactive Streams Subscriber
132
139
*/
140
+ @ SuppressWarnings ("unchecked" )
133
141
public static <T > org .reactivestreams .Subscriber <T > toReactiveStreams (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 ;
158
+ final org .reactivestreams .Subscription reactiveStreams ;
145
159
146
160
public FlowToReactiveSubscription (org .reactivestreams .Subscription reactive ) {
147
161
this .reactiveStreams = reactive ;
@@ -163,7 +177,7 @@ public void cancel() {
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 ;
180
+ final Flow .Subscription flow ;
167
181
168
182
public ReactiveToFlowSubscription (Flow .Subscription flow ) {
169
183
this .flow = flow ;
@@ -188,16 +202,15 @@ public void cancel() {
188
202
*/
189
203
static final class FlowToReactiveSubscriber <T >
190
204
implements Flow .Subscriber <T > {
191
- private final org .reactivestreams .Subscriber <? super T > reactiveStreams ;
205
+ final org .reactivestreams .Subscriber <? super T > reactiveStreams ;
192
206
193
207
public FlowToReactiveSubscriber (org .reactivestreams .Subscriber <? super T > reactive ) {
194
- if (reactive == null ) throw null ;
195
208
this .reactiveStreams = reactive ;
196
209
}
197
210
198
211
@ Override
199
212
public void onSubscribe (Flow .Subscription subscription ) {
200
- reactiveStreams .onSubscribe (new ReactiveToFlowSubscription (subscription ));
213
+ reactiveStreams .onSubscribe (( subscription == null ) ? null : new ReactiveToFlowSubscription (subscription ));
201
214
}
202
215
203
216
@ Override
@@ -223,15 +236,15 @@ public void onComplete() {
223
236
*/
224
237
static final class ReactiveToFlowSubscriber <T >
225
238
implements org .reactivestreams .Subscriber <T > {
226
- private final Flow .Subscriber <? super T > flow ;
239
+ final Flow .Subscriber <? super T > flow ;
227
240
228
241
public ReactiveToFlowSubscriber (Flow .Subscriber <? super T > flow ) {
229
242
this .flow = flow ;
230
243
}
231
244
232
245
@ Override
233
246
public void onSubscribe (org .reactivestreams .Subscription subscription ) {
234
- flow .onSubscribe (new FlowToReactiveSubscription (subscription ));
247
+ flow .onSubscribe (( subscription == null ) ? null : new FlowToReactiveSubscription (subscription ));
235
248
}
236
249
237
250
@ Override
@@ -261,13 +274,12 @@ static final class ReactiveToFlowProcessor<T, U>
261
274
final Flow .Processor <? super T , ? extends U > flow ;
262
275
263
276
public ReactiveToFlowProcessor (Flow .Processor <? super T , ? extends U > flow ) {
264
- if (flow == null ) throw null ;
265
277
this .flow = flow ;
266
278
}
267
279
268
280
@ Override
269
- public void onSubscribe (org .reactivestreams .Subscription s ) {
270
- flow .onSubscribe (new FlowToReactiveSubscription (s ));
281
+ public void onSubscribe (org .reactivestreams .Subscription subscription ) {
282
+ flow .onSubscribe (( subscription == null ) ? null : new FlowToReactiveSubscription (subscription ));
271
283
}
272
284
273
285
@ Override
@@ -287,11 +299,7 @@ public void onComplete() {
287
299
288
300
@ Override
289
301
public void subscribe (org .reactivestreams .Subscriber <? super U > s ) {
290
- if (s == null ) {
291
- flow .subscribe (null );
292
- return ;
293
- }
294
- flow .subscribe (new FlowToReactiveSubscriber <U >(s ));
302
+ flow .subscribe ((s == null ) ? null : new FlowToReactiveSubscriber <U >(s ));
295
303
}
296
304
}
297
305
@@ -309,8 +317,8 @@ public FlowToReactiveProcessor(org.reactivestreams.Processor<? super T, ? extend
309
317
}
310
318
311
319
@ Override
312
- public void onSubscribe (Flow .Subscription s ) {
313
- reactiveStreams .onSubscribe (new ReactiveToFlowSubscription (s ));
320
+ public void onSubscribe (Flow .Subscription subscription ) {
321
+ reactiveStreams .onSubscribe (( subscription == null ) ? null : new ReactiveToFlowSubscription (subscription ));
314
322
}
315
323
316
324
@ Override
@@ -330,11 +338,7 @@ public void onComplete() {
330
338
331
339
@ Override
332
340
public void subscribe (Flow .Subscriber <? super U > s ) {
333
- if (s == null ) {
334
- reactiveStreams .subscribe (null );
335
- return ;
336
- }
337
- reactiveStreams .subscribe (new ReactiveToFlowSubscriber <U >(s ));
341
+ reactiveStreams .subscribe ((s == null ) ? null : new ReactiveToFlowSubscriber <U >(s ));
338
342
}
339
343
}
340
344
@@ -352,11 +356,7 @@ public ReactivePublisherFromFlow(Flow.Publisher<? extends T> flowPublisher) {
352
356
353
357
@ Override
354
358
public void subscribe (org .reactivestreams .Subscriber <? super T > reactive ) {
355
- if (reactive == null ) {
356
- flow .subscribe (null );
357
- return ;
358
- }
359
- flow .subscribe (new FlowToReactiveSubscriber <T >(reactive ));
359
+ flow .subscribe ((reactive == null ) ? null : new FlowToReactiveSubscriber <T >(reactive ));
360
360
}
361
361
}
362
362
@@ -374,11 +374,7 @@ public FlowPublisherFromReactive(org.reactivestreams.Publisher<? extends T> reac
374
374
375
375
@ Override
376
376
public void subscribe (Flow .Subscriber <? super T > flow ) {
377
- if (flow == null ) {
378
- reactiveStreams .subscribe (null );
379
- return ;
380
- }
381
- reactiveStreams .subscribe (new ReactiveToFlowSubscriber <T >(flow ));
377
+ reactiveStreams .subscribe ((flow == null ) ? null : new ReactiveToFlowSubscriber <T >(flow ));
382
378
}
383
379
}
384
380
0 commit comments