Skip to content

Commit 722ce7b

Browse files
committed
Add main converters and tests
1 parent cc8e74e commit 722ce7b

19 files changed

+2352
-1
lines changed

README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,161 @@ dependencies {
1919

2020

2121
# Features
22+
23+
## Convert between Flowables
24+
25+
### via static methods
26+
27+
```java
28+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
29+
30+
io.reactivex.Flowable f2 = RxJavaBridge.toV2Flowable(io.reactivex.rxjava3.core.Flowable)
31+
32+
io.reactivex.rxjava3.core.Flowable f3 = RxJavaBridge.toV3Flowable(io.reactivex.Flowable)
33+
```
34+
35+
### via FlowableConverter application
36+
37+
```java
38+
f3 = f2.as(RxJavaBridge.toV3Flowable())
39+
40+
f2 = f3.to(RxJavaBridge.toV2Flowable())
41+
```
42+
43+
## Convert between Observables
44+
45+
### via static methods
46+
47+
```java
48+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
49+
50+
io.reactivex.Observable o2 = RxJavaBridge.toV2Observable(io.reactivex.rxjava3.core.Observable)
51+
52+
io.reactivex.rxjava3.core.Observable o3 = RxJavaBridge.toV3Observable(io.reactivex.Observable)
53+
```
54+
55+
### via ObservableConverter application
56+
57+
```java
58+
o3 = o2.as(RxJavaBridge.toV3Observable())
59+
60+
o2 = o3.to(RxJavaBridge.toV2Observable())
61+
```
62+
63+
## Convert between Maybes
64+
65+
### via static methods
66+
67+
```java
68+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
69+
70+
io.reactivex.Maybe m2 = RxJavaBridge.toV2Maybe(io.reactivex.rxjava3.core.Maybe)
71+
72+
io.reactivex.rxjava3.core.Maybe m3 = RxJavaBridge.toV3Maybe(io.reactivex.Maybe)
73+
```
74+
75+
### via MaybeConverter application
76+
77+
```java
78+
m3 = m2.as(RxJavaBridge.toV3Maybe())
79+
80+
m2 = m3.to(RxJavaBridge.toV2Maybe())
81+
```
82+
83+
## Convert between Singles
84+
85+
### via static methods
86+
87+
```java
88+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
89+
90+
io.reactivex.Single s2 = RxJavaBridge.toV2Single(io.reactivex.rxjava3.core.Single)
91+
92+
io.reactivex.rxjava3.core.Single s3 = RxJavaBridge.toV3Single(io.reactivex.Single)
93+
```
94+
95+
### via SingleConverter application
96+
97+
```java
98+
s3 = s2.as(RxJavaBridge.toV3Single())
99+
100+
s2 = s3.to(RxJavaBridge.toV2Single())
101+
```
102+
103+
104+
## Convert between Completables
105+
106+
### via static methods
107+
108+
```java
109+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
110+
111+
io.reactivex.Completable c2 = RxJavaBridge.toV2Completable(io.reactivex.rxjava3.core.Completable)
112+
113+
io.reactivex.rxjava3.core.Completable c3 = RxJavaBridge.toV3Completable(io.reactivex.Completable)
114+
```
115+
116+
### via CompletableConverter application
117+
118+
```java
119+
c3 = c2.as(RxJavaBridge.toV3Completable())
120+
121+
c2 = c3.to(RxJavaBridge.toV2Completable())
122+
```
123+
124+
125+
## Convert between Disposables
126+
127+
### via static methods
128+
129+
```java
130+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
131+
132+
io.reactivex.disposables.Disposable d2 = RxJavaBridge.toV2Disposable(io.reactivex.rxjava3.disposables.Disposable)
133+
134+
io.reactivex.rxjava3.disosables.Observable d3 = RxJavaBridge.toV3Disposable(io.reactivex.disposables.Disposable)
135+
```
136+
137+
## Convert between Schedulers
138+
139+
### via static methods
140+
141+
```java
142+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
143+
144+
io.reactivex.Scheduler sch2 = RxJavaBridge.toV2Scheduler(io.reactivex.rxjava3.core.Scheduler)
145+
146+
io.reactivex.rxjava3.core.Scheduler sch3 = RxJavaBridge.toV3Scheduler(io.reactivex.Scheduler)
147+
```
148+
149+
### use 3.x standard schedulers in 2.x
150+
151+
```java
152+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
153+
154+
io.reactivex.schedulers.Schedulers.shutdown();
155+
156+
RxJavaBridge.startUsingV3Schedulers();
157+
158+
// when done
159+
160+
RxJavaBridge.stopUsingV3Schedulers();
161+
162+
io.reactivex.schedulers.Schedulers.start();
163+
```
164+
165+
### use 2.x standard schedulers in 3.x
166+
167+
```java
168+
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;
169+
170+
io.reactivex.rxjava3.schedulers.Schedulers.shutdown();
171+
172+
RxJavaBridge.startUsingV2Schedulers();
173+
174+
// when done
175+
176+
RxJavaBridge.stopUsingV2Schedulers();
177+
178+
io.reactivex.rxjava3.schedulers.Schedulers.start();
179+
```

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ build.dependsOn jacocoTestReport
2626

2727
check.dependsOn jacocoTestReport
2828

29+
javadoc {
30+
failOnError = false
31+
32+
options.links(
33+
"http://docs.oracle.com/javase/7/docs/api/",
34+
"http://reactivex.io/RxJava/2.x/javadoc",
35+
"http://reactivex.io/RxJava/3.x/javadoc"
36+
)
37+
}
2938

3039
group = "com.github.akarnokd"
3140

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2019 David Karnok
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package hu.akarnokd.rxjava3.bridge;
18+
19+
final class CompletableV2toV3 extends io.reactivex.rxjava3.core.Completable
20+
implements io.reactivex.CompletableConverter<io.reactivex.rxjava3.core.Completable> {
21+
22+
final io.reactivex.Completable source;
23+
24+
static final CompletableV2toV3 CONVERTER = new CompletableV2toV3(null);
25+
26+
CompletableV2toV3(io.reactivex.Completable source) {
27+
this.source = source;
28+
}
29+
30+
@Override
31+
protected void subscribeActual(io.reactivex.rxjava3.core.CompletableObserver s) {
32+
source.subscribe(new CompletableObserverV3toV2(s));
33+
}
34+
35+
@Override
36+
public io.reactivex.rxjava3.core.Completable apply(io.reactivex.Completable upstream) {
37+
return new CompletableV2toV3(upstream);
38+
}
39+
40+
static final class CompletableObserverV3toV2
41+
implements io.reactivex.CompletableObserver, io.reactivex.rxjava3.disposables.Disposable {
42+
43+
final io.reactivex.rxjava3.core.CompletableObserver downstream;
44+
45+
io.reactivex.disposables.Disposable upstream;
46+
47+
CompletableObserverV3toV2(io.reactivex.rxjava3.core.CompletableObserver downstream) {
48+
this.downstream = downstream;
49+
}
50+
51+
@Override
52+
public void onSubscribe(io.reactivex.disposables.Disposable d) {
53+
this.upstream = d;
54+
downstream.onSubscribe(this);
55+
}
56+
57+
@Override
58+
public void onError(Throwable e) {
59+
downstream.onError(e);
60+
}
61+
62+
@Override
63+
public void onComplete() {
64+
downstream.onComplete();
65+
}
66+
67+
@Override
68+
public boolean isDisposed() {
69+
return upstream.isDisposed();
70+
}
71+
72+
@Override
73+
public void dispose() {
74+
upstream.dispose();
75+
}
76+
}
77+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2019 David Karnok
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package hu.akarnokd.rxjava3.bridge;
18+
19+
final class CompletableV3toV2 extends io.reactivex.Completable
20+
implements io.reactivex.rxjava3.core.CompletableConverter<io.reactivex.Completable> {
21+
22+
final io.reactivex.rxjava3.core.Completable source;
23+
24+
static final CompletableV3toV2 CONVERTER = new CompletableV3toV2(null);
25+
26+
CompletableV3toV2(io.reactivex.rxjava3.core.Completable source) {
27+
this.source = source;
28+
}
29+
30+
@Override
31+
protected void subscribeActual(io.reactivex.CompletableObserver s) {
32+
source.subscribe(new CompletableObserverV2toV3(s));
33+
}
34+
35+
@Override
36+
public io.reactivex.Completable apply(io.reactivex.rxjava3.core.Completable upstream) {
37+
return new CompletableV3toV2(upstream);
38+
}
39+
40+
static final class CompletableObserverV2toV3
41+
implements io.reactivex.rxjava3.core.CompletableObserver, io.reactivex.disposables.Disposable {
42+
43+
final io.reactivex.CompletableObserver downstream;
44+
45+
io.reactivex.rxjava3.disposables.Disposable upstream;
46+
47+
CompletableObserverV2toV3(io.reactivex.CompletableObserver downstream) {
48+
this.downstream = downstream;
49+
}
50+
51+
@Override
52+
public void onSubscribe(io.reactivex.rxjava3.disposables.Disposable d) {
53+
this.upstream = d;
54+
downstream.onSubscribe(this);
55+
}
56+
57+
@Override
58+
public void onError(Throwable e) {
59+
downstream.onError(e);
60+
}
61+
62+
@Override
63+
public void onComplete() {
64+
downstream.onComplete();
65+
}
66+
67+
@Override
68+
public boolean isDisposed() {
69+
return upstream.isDisposed();
70+
}
71+
72+
@Override
73+
public void dispose() {
74+
upstream.dispose();
75+
}
76+
}
77+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2019 David Karnok
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package hu.akarnokd.rxjava3.bridge;
18+
19+
final class DisposableV2toV3 implements io.reactivex.rxjava3.disposables.Disposable {
20+
21+
final io.reactivex.disposables.Disposable disposable;
22+
23+
DisposableV2toV3(io.reactivex.disposables.Disposable disposable) {
24+
this.disposable = disposable;
25+
}
26+
27+
@Override
28+
public boolean isDisposed() {
29+
return disposable.isDisposed();
30+
}
31+
32+
@Override
33+
public void dispose() {
34+
disposable.dispose();
35+
}
36+
37+
static io.reactivex.rxjava3.disposables.Disposable wrap(io.reactivex.disposables.Disposable disposable) {
38+
if (disposable == io.reactivex.internal.disposables.DisposableHelper.DISPOSED) {
39+
return io.reactivex.rxjava3.internal.disposables.DisposableHelper.DISPOSED;
40+
}
41+
if (disposable == io.reactivex.internal.disposables.EmptyDisposable.INSTANCE) {
42+
return io.reactivex.rxjava3.internal.disposables.EmptyDisposable.INSTANCE;
43+
}
44+
return new DisposableV2toV3(disposable);
45+
}
46+
}

0 commit comments

Comments
 (0)