-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathRxJavaInterop.java
679 lines (635 loc) · 32.3 KB
/
RxJavaInterop.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
/*
* Copyright 2016-2020 David Karnok
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hu.akarnokd.rxjava3.interop;
/**
* Conversion methods for converting between 1.x and 3.x reactive types, composing backpressure
* and cancellation through.
*/
public final class RxJavaInterop {
/** Utility class. */
private RxJavaInterop() {
throw new IllegalStateException("No instances!");
}
// -----------------------------------------------------------------------------------------
// Conversions to 3.x
// -----------------------------------------------------------------------------------------
/**
* Converts an 1.x Observable into a 3.x Flowable, composing the backpressure and
* cancellation (unsubscription) through.
* <p>
* Note that in 1.x Observable's backpressure somewhat optional; you may need to apply
* one of the onBackpressureXXX operators on the source Observable or the resulting Flowable.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the
* source 1.x {@code Observable}'s backpressure behavior.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the value type
* @param source the source 1.x Observable instance, not null
* @return the new 3.x Flowable instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> io.reactivex.rxjava3.core.Flowable<T> toV3Flowable(rx.Observable<T> source) {
java.util.Objects.requireNonNull(source, "source is null");
return new ObservableV1ToFlowableV3<>(source);
}
/**
* Converts an 1.x Observable into a 3.x Observable, cancellation (unsubscription) through.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator consumes the source 1.x {@code Observable} in an
* unbounded manner (without applying backpressure).</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the value type
* @param source the source 1.x Observable instance, not null
* @return the new 3.x Observable instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> io.reactivex.rxjava3.core.Observable<T> toV3Observable(rx.Observable<T> source) {
java.util.Objects.requireNonNull(source, "source is null");
return new ObservableV1ToObservableV3<>(source);
}
/**
* Converts an 1.x Completable into a 3.x Maybe, composing cancellation (unsubscription) through.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the value type
* @param source the source 1.x Completable instance, not null
* @return the new 3.x Maybe instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> io.reactivex.rxjava3.core.Maybe<T> toV3Maybe(rx.Completable source) {
java.util.Objects.requireNonNull(source, "source is null");
return new CompletableV1ToMaybeV3<>(source);
}
/**
* Converts an 1.x Single into a 3.x Maybe, composing cancellation (unsubscription) through.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the value type
* @param source the source 1.x Single instance, not null
* @return the new 3.x Maybe instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> io.reactivex.rxjava3.core.Maybe<T> toV3Maybe(rx.Single<T> source) {
java.util.Objects.requireNonNull(source, "source is null");
return new SingleV1ToMaybeV3<>(source);
}
/**
* Converts an 1.x Single into a 3.x Single, composing cancellation (unsubscription) through.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the value type
* @param source the source 1.x Single instance, not null
* @return the new 3.x Single instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> io.reactivex.rxjava3.core.Single<T> toV3Single(rx.Single<T> source) {
java.util.Objects.requireNonNull(source, "source is null");
return new SingleV1ToSingleV3<>(source);
}
/**
* Converts an 1.x Completable into a 3.x Completable, composing cancellation (unsubscription) through.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param source the source 1.x Completable instance, not null
* @return the new 3.x Completable instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static io.reactivex.rxjava3.core.Completable toV3Completable(rx.Completable source) {
java.util.Objects.requireNonNull(source, "source is null");
return new CompletableV1ToCompletableV3(source);
}
/**
* Wraps a 1.x Subject into a 3.x Subject.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input and output value type of the Subjects
* @param subject the subject to wrap with the same input and output type;
* 3.x Subject supports only the same input and output type
* @return the new 3.x Subject instance
* @throws NullPointerException if {@code source} is null
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> io.reactivex.rxjava3.subjects.Subject<T> toV3Subject(rx.subjects.Subject<T, T> subject) {
java.util.Objects.requireNonNull(subject, "subject is null");
return new SubjectV1ToSubjectV3<>(subject);
}
/**
* Wraps a 1.x Subject into a 3.x FlowableProcessor.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the
* source 1.x {@code Subject}'s backpressure behavior.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input and output value type of the Subjects
* @param subject the subject to wrap with the same input and output type;
* 3.x FlowableProcessor supports only the same input and output type
* @return the new 3.x FlowableProcessor instance
* @throws NullPointerException if {@code source} is null
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> io.reactivex.rxjava3.processors.FlowableProcessor<T> toV3Processor(rx.subjects.Subject<T, T> subject) {
java.util.Objects.requireNonNull(subject, "subject is null");
return new SubjectV1ToProcessorV3<>(subject);
}
/**
* Convert the 1.x Observable.Transformer into a 3.x FlowableTransformer.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the
* 1.x Observable returned by the 1.x Transformer.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input value type
* @param <R> the output value type
* @param transformer the 1.x Observable.Transformer to convert
* @return the new FlowableTransformer instance
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T, R> io.reactivex.rxjava3.core.FlowableTransformer<T, R> toV3Transformer(final rx.Observable.Transformer<T, R> transformer) {
java.util.Objects.requireNonNull(transformer, "transformer is null");
return new io.reactivex.rxjava3.core.FlowableTransformer<T, R>() {
@Override
public org.reactivestreams.Publisher<R> apply(io.reactivex.rxjava3.core.Flowable<T> f) {
return toV3Flowable(transformer.call(toV1Observable(f)));
}
};
}
/**
* Convert the 1.x Observable.Transformer into a 3.x ObservableTransformer.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input value type
* @param <R> the output value type
* @param strategy the backpressure strategy to apply: BUFFER, DROP or LATEST.
* @param transformer the 1.x Observable.Transformer to convert
* @return the new ObservableTransformer instance
* @since 0.12.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T, R> io.reactivex.rxjava3.core.ObservableTransformer<T, R> toV3Transformer(final rx.Observable.Transformer<T, R> transformer,
final io.reactivex.rxjava3.core.BackpressureStrategy strategy) {
java.util.Objects.requireNonNull(transformer, "transformer is null");
return new io.reactivex.rxjava3.core.ObservableTransformer<T, R>() {
@Override
public io.reactivex.rxjava3.core.ObservableSource<R> apply(io.reactivex.rxjava3.core.Observable<T> obs) {
return toV3Observable(transformer.call(toV1Observable(obs, strategy)));
}
};
}
/**
* Convert the 1.x Single.Transformer into a 3.x SingleTransformer.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input value type
* @param <R> the output value type
* @param transformer the 1.x Single.Transformer to convert
* @return the new SingleTransformer instance
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T, R> io.reactivex.rxjava3.core.SingleTransformer<T, R> toV3Transformer(final rx.Single.Transformer<T, R> transformer) {
java.util.Objects.requireNonNull(transformer, "transformer is null");
return new io.reactivex.rxjava3.core.SingleTransformer<T, R>() {
@Override
public io.reactivex.rxjava3.core.Single<R> apply(io.reactivex.rxjava3.core.Single<T> f) {
return toV3Single(transformer.call(toV1Single(f)));
}
};
}
/**
* Convert the 1.x Completable.Transformer into a 3.x CompletableTransformer.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param transformer the 1.x Completable.Transformer to convert
* @return the new CompletableTransformer instance
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static io.reactivex.rxjava3.core.CompletableTransformer toV3Transformer(final rx.Completable.Transformer transformer) {
java.util.Objects.requireNonNull(transformer, "transformer is null");
return new io.reactivex.rxjava3.core.CompletableTransformer() {
@Override
public io.reactivex.rxjava3.core.Completable apply(io.reactivex.rxjava3.core.Completable f) {
return toV3Completable(transformer.call(toV1Completable(f)));
}
};
}
/**
* Convert the 1.x Observable.Operator into a 3.x FlowableOperator.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the
* 1.x Subscriber returned by the 1.x Operator.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input value type
* @param <R> the output value type
* @param operator the 1.x Observable.Operator to convert
* @return the new FlowableOperator instance
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T, R> io.reactivex.rxjava3.core.FlowableOperator<R, T> toV3Operator(final rx.Observable.Operator<R, T> operator) {
java.util.Objects.requireNonNull(operator, "operator is null");
return new io.reactivex.rxjava3.core.FlowableOperator<R, T>() {
@Override
public org.reactivestreams.Subscriber<? super T> apply(org.reactivestreams.Subscriber<? super R> s) throws Exception {
hu.akarnokd.rxjava3.interop.ObservableV1ToFlowableV3.ObservableSubscriber<R> parent = new hu.akarnokd.rxjava3.interop.ObservableV1ToFlowableV3.ObservableSubscriber<>(s);
hu.akarnokd.rxjava3.interop.ObservableV1ToFlowableV3.ObservableSubscriberSubscription parentSubscription = new hu.akarnokd.rxjava3.interop.ObservableV1ToFlowableV3.ObservableSubscriberSubscription(parent);
s.onSubscribe(parentSubscription);
rx.Subscriber<? super T> t;
try {
t = java.util.Objects.requireNonNull(operator.call(parent), "The operator returned a null rx.Subscriber");
} catch (Throwable ex) {
io.reactivex.rxjava3.exceptions.Exceptions.throwIfFatal(ex);
rx.exceptions.Exceptions.throwIfFatal(ex);
s.onError(ex);
t = rx.observers.Subscribers.empty();
t.unsubscribe();
}
hu.akarnokd.rxjava3.interop.FlowableV3ToObservableV1.SourceSubscriber<T> z = new hu.akarnokd.rxjava3.interop.FlowableV3ToObservableV1.SourceSubscriber<>(t);
t.add(z);
t.setProducer(z);
return z;
}
};
}
/**
* Convert the 1.x {@link rx.Subscription} into a 3.x {@link io.reactivex.rxjava3.disposables.Disposable}.
* @param subscription the 1.x Subscription to convert
* @return the new Disposable instance
* @since 0.11.0
*/
public static io.reactivex.rxjava3.disposables.Disposable toV3Disposable(final rx.Subscription subscription) {
java.util.Objects.requireNonNull(subscription, "subscription is null");
return new SubscriptionV1ToDisposableV3(subscription);
}
// -----------------------------------------------------------------------------------------
// Conversions to 1.x
// -----------------------------------------------------------------------------------------
/**
* Converts a Reactive-Streams Publisher of any kind (the base type of 3.x Flowable)
* into an 1.x Observable, composing the backpressure and cancellation
* (unsubscription) through.
* <p>
* Note that this method can convert <strong>any</strong> Reactive-Streams compliant
* source into an 1.x Observable, not just the 3.x Flowable.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the
* source {@code Publisher}'s backpressure behavior.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the value type
* @param source the source Reactive-Streams Publisher instance, not null
* @return the new 1.x Observable instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> rx.Observable<T> toV1Observable(org.reactivestreams.Publisher<T> source) {
java.util.Objects.requireNonNull(source, "source is null");
return rx.Observable.unsafeCreate(new FlowableV3ToObservableV1<>(source));
}
/**
* Converts a 3.x ObservableSource (the base type of 3.x Observable) into an 1.x
* Observable instance, applying the specified backpressure strategy and composing
* the cancellation (unsubscription) through.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator applies the backpressure strategy you specify.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the value type
* @param source the source ObservableSource instance, not null
* @param strategy the backpressure strategy to apply: BUFFER, DROP or LATEST.
* @return the new 1.x Observable instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> rx.Observable<T> toV1Observable(io.reactivex.rxjava3.core.ObservableSource<T> source, io.reactivex.rxjava3.core.BackpressureStrategy strategy) {
java.util.Objects.requireNonNull(source, "source is null");
java.util.Objects.requireNonNull(strategy, "strategy is null");
return toV1Observable(io.reactivex.rxjava3.core.Observable.wrap(source).toFlowable(strategy));
}
/**
* Converts an 3.x SingleSource (the base type of 3.x Single) into a
* 1.x Single, composing cancellation (unsubscription) through.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the value type
* @param source the source 3.x SingleSource instance, not null
* @return the new 1.x Single instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> rx.Single<T> toV1Single(io.reactivex.rxjava3.core.SingleSource<T> source) {
java.util.Objects.requireNonNull(source, "source is null");
return rx.Single.create(new SingleV3ToSingleV1<>(source));
}
/**
* Converts an 3.x CompletableSource (the base type of 3.x Completable) into a
* 1.x Completable, composing cancellation (unsubscription) through.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param source the source 3.x CompletableSource instance, not null
* @return the new 1.x Completable instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static rx.Completable toV1Completable(io.reactivex.rxjava3.core.CompletableSource source) {
java.util.Objects.requireNonNull(source, "source is null");
return rx.Completable.create(new CompletableV3ToCompletableV1(source));
}
/**
* Converts an 3.x MaybeSource (the base type of 3.x Maybe) into a
* 1.x Single, composing cancellation (unsubscription) through and
* signalling NoSuchElementException if the MaybeSource is empty.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the source's value type
* @param source the source 3.x MaybeSource instance, not null
* @return the new 1.x Single instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> rx.Single<T> toV1Single(io.reactivex.rxjava3.core.MaybeSource<T> source) {
java.util.Objects.requireNonNull(source, "source is null");
return rx.Single.create(new MaybeV3ToSingleV1<>(source));
}
/**
* Converts an 3.x MaybeSource (the base type of 3.x Maybe) into a
* 1.x Completable, composing cancellation (unsubscription) through
* and ignoring the success value.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the source's value type
* @param source the source 3.x MaybeSource instance, not null
* @return the new 1.x Completable instance
* @throws NullPointerException if {@code source} is null
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> rx.Completable toV1Completable(io.reactivex.rxjava3.core.MaybeSource<T> source) {
java.util.Objects.requireNonNull(source, "source is null");
return rx.Completable.create(new MaybeV3ToCompletableV1<>(source));
}
/**
* Wraps a 3.x Subject into a 1.x Subject.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input and output value type of the Subjects
* @param subject the subject to wrap with the same input and output type;
* 3.x Subject supports only the same input and output type
* @return the new 1.x Subject instance
* @throws NullPointerException if {@code source} is null
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> rx.subjects.Subject<T, T> toV1Subject(io.reactivex.rxjava3.subjects.Subject<T> subject) {
java.util.Objects.requireNonNull(subject, "subject is null");
return SubjectV3ToSubjectV1.<T>createWith(subject);
}
/**
* Wraps a 3.x FlowableProcessor into a 1.x Subject.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the
* source {@code FlowableProcessor}'s backpressure behavior.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input and output value type of the Subjects
* @param processor the flowable-processor to wrap with the same input and output type;
* 3.x FlowableProcessor supports only the same input and output type
* @return the new 1.x Subject instance
* @throws NullPointerException if {@code source} is null
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T> rx.subjects.Subject<T, T> toV1Subject(io.reactivex.rxjava3.processors.FlowableProcessor<T> processor) {
java.util.Objects.requireNonNull(processor, "processor is null");
return ProcessorV3ToSubjectV1.<T>createWith(processor);
}
/**
* Convert the 3.x FlowableTransformer into a 1.x Observable.Transformer.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the
* 3.x Flowable returned by the 3.x FlowableTransformer.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input value type
* @param <R> the output value type
* @param transformer the 3.x FlowableTransformer to convert
* @return the new Observable.Transformer instance
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T, R> rx.Observable.Transformer<T, R> toV1Transformer(final io.reactivex.rxjava3.core.FlowableTransformer<T, R> transformer) {
java.util.Objects.requireNonNull(transformer, "transformer is null");
return new rx.Observable.Transformer<T, R>() {
@Override
public rx.Observable<R> call(rx.Observable<T> f) {
return toV1Observable(transformer.apply(toV3Flowable(f)));
}
};
}
/**
* Convert the 3.x ObservableTransformer into a 1.x Observable.Transformer.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input value type
* @param <R> the output value type
* @param transformer the 3.x ObservableTransformer to convert
* @param strategy the backpressure strategy to apply: BUFFER, DROP or LATEST.
* @return the new Observable.Transformer instance
* @since 0.12.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T, R> rx.Observable.Transformer<T, R> toV1Transformer(final io.reactivex.rxjava3.core.ObservableTransformer<T, R> transformer,
final io.reactivex.rxjava3.core.BackpressureStrategy strategy) {
java.util.Objects.requireNonNull(transformer, "transformer is null");
return new rx.Observable.Transformer<T, R>() {
@Override
public rx.Observable<R> call(rx.Observable<T> obs) {
return toV1Observable(transformer.apply(toV3Observable(obs)), strategy);
}
};
}
/**
* Convert the 3.x SingleTransformer into a 1.x Single.Transformer.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input value type
* @param <R> the output value type
* @param transformer the 3.x SingleTransformer to convert
* @return the new Single.Transformer instance
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T, R> rx.Single.Transformer<T, R> toV1Transformer(final io.reactivex.rxjava3.core.SingleTransformer<T, R> transformer) {
java.util.Objects.requireNonNull(transformer, "transformer is null");
return new rx.Single.Transformer<T, R>() {
@Override
public rx.Single<R> call(rx.Single<T> f) {
return toV1Single(transformer.apply(toV3Single(f)));
}
};
}
/**
* Convert the 3.x CompletableTransformer into a 1.x Completable.Transformer.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param transformer the 3.x CompletableTransformer to convert
* @return the new Completable.Transformer instance
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static rx.Completable.Transformer toV1Transformer(final io.reactivex.rxjava3.core.CompletableTransformer transformer) {
java.util.Objects.requireNonNull(transformer, "transformer is null");
return new rx.Completable.Transformer() {
@Override
public rx.Completable call(rx.Completable f) {
return toV1Completable(transformer.apply(toV3Completable(f)));
}
};
}
/**
* Convert the 3.x FlowableOperator into a 1.x Observable.Operator.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator doesn't interfere with backpressure which is determined by the
* 3.x Subscriber returned by the 3.x FlowableOperator.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>The method does not operate by default on a particular {@code Scheduler}.</dd>
* </dl>
* @param <T> the input value type
* @param <R> the output value type
* @param operator the 3.x FlowableOperator to convert
* @return the new Observable.Operator instance
* @since 0.9.0
*/
@io.reactivex.rxjava3.annotations.SchedulerSupport(io.reactivex.rxjava3.annotations.SchedulerSupport.NONE)
public static <T, R> rx.Observable.Operator<R, T> toV1Operator(final io.reactivex.rxjava3.core.FlowableOperator<R, T> operator) {
java.util.Objects.requireNonNull(operator, "operator is null");
return new rx.Observable.Operator<R, T>() {
@Override
public rx.Subscriber<? super T> call(rx.Subscriber<? super R> t) {
hu.akarnokd.rxjava3.interop.FlowableV3ToObservableV1.SourceSubscriber<R> z = new hu.akarnokd.rxjava3.interop.FlowableV3ToObservableV1.SourceSubscriber<>(t);
t.add(z);
t.setProducer(z);
org.reactivestreams.Subscriber<? super T> s;
try {
s = java.util.Objects.requireNonNull(operator.apply(z), "The operator returned a null Subscriber");
} catch (Throwable ex) {
io.reactivex.rxjava3.exceptions.Exceptions.throwIfFatal(ex);
rx.exceptions.Exceptions.throwIfFatal(ex);
t.onError(ex);
rx.Subscriber<? super T> r = rx.observers.Subscribers.empty();
r.unsubscribe();
return r;
}
hu.akarnokd.rxjava3.interop.ObservableV1ToFlowableV3.ObservableSubscriber<T> parent = new hu.akarnokd.rxjava3.interop.ObservableV1ToFlowableV3.ObservableSubscriber<>(s);
hu.akarnokd.rxjava3.interop.ObservableV1ToFlowableV3.ObservableSubscriberSubscription parentSubscription = new hu.akarnokd.rxjava3.interop.ObservableV1ToFlowableV3.ObservableSubscriberSubscription(parent);
s.onSubscribe(parentSubscription);
return parent;
}
};
}
/**
* Convert the 3.x {@link io.reactivex.rxjava3.disposables.Disposable} into a 1.x {@link rx.Subscription}.
* @param disposable the 3.x Disposable to convert
* @return the new Subscription instance
* @since 0.11.0
*/
public static rx.Subscription toV1Subscription(final io.reactivex.rxjava3.disposables.Disposable disposable) {
java.util.Objects.requireNonNull(disposable, "disposable is null");
return new DisposableV3ToSubscriptionV1(disposable);
}
/**
* Convert the 3.x {@link io.reactivex.rxjava3.core.Scheduler} into a 1.x {@link rx.Scheduler}.
* @param scheduler the 3.x Scheduler to convert
* @return the new 1.x Scheduler instance
* @since 0.12.0
*/
public static rx.Scheduler toV1Scheduler(io.reactivex.rxjava3.core.Scheduler scheduler) {
java.util.Objects.requireNonNull(scheduler, "scheduler is null");
return new SchedulerV3ToSchedulerV1(scheduler);
}
/**
* Convert the 3.x {@link io.reactivex.rxjava3.core.Scheduler} into a 1.x {@link rx.Scheduler}.
* @param scheduler the 1.x Scheduler to convert
* @return the new 3.x Scheduler instance
* @since 0.12.0
*/
public static io.reactivex.rxjava3.core.Scheduler toV3Scheduler(rx.Scheduler scheduler) {
java.util.Objects.requireNonNull(scheduler, "scheduler is null");
return new SchedulerV1ToSchedulerV3(scheduler);
}
}