Skip to content

Commit

Permalink
Add main converters and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd committed Aug 22, 2019
1 parent cc8e74e commit 722ce7b
Show file tree
Hide file tree
Showing 19 changed files with 2,352 additions and 1 deletion.
158 changes: 158 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,161 @@ dependencies {


# Features

## Convert between Flowables

### via static methods

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.Flowable f2 = RxJavaBridge.toV2Flowable(io.reactivex.rxjava3.core.Flowable)

io.reactivex.rxjava3.core.Flowable f3 = RxJavaBridge.toV3Flowable(io.reactivex.Flowable)
```

### via FlowableConverter application

```java
f3 = f2.as(RxJavaBridge.toV3Flowable())

f2 = f3.to(RxJavaBridge.toV2Flowable())
```

## Convert between Observables

### via static methods

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.Observable o2 = RxJavaBridge.toV2Observable(io.reactivex.rxjava3.core.Observable)

io.reactivex.rxjava3.core.Observable o3 = RxJavaBridge.toV3Observable(io.reactivex.Observable)
```

### via ObservableConverter application

```java
o3 = o2.as(RxJavaBridge.toV3Observable())

o2 = o3.to(RxJavaBridge.toV2Observable())
```

## Convert between Maybes

### via static methods

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.Maybe m2 = RxJavaBridge.toV2Maybe(io.reactivex.rxjava3.core.Maybe)

io.reactivex.rxjava3.core.Maybe m3 = RxJavaBridge.toV3Maybe(io.reactivex.Maybe)
```

### via MaybeConverter application

```java
m3 = m2.as(RxJavaBridge.toV3Maybe())

m2 = m3.to(RxJavaBridge.toV2Maybe())
```

## Convert between Singles

### via static methods

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.Single s2 = RxJavaBridge.toV2Single(io.reactivex.rxjava3.core.Single)

io.reactivex.rxjava3.core.Single s3 = RxJavaBridge.toV3Single(io.reactivex.Single)
```

### via SingleConverter application

```java
s3 = s2.as(RxJavaBridge.toV3Single())

s2 = s3.to(RxJavaBridge.toV2Single())
```


## Convert between Completables

### via static methods

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.Completable c2 = RxJavaBridge.toV2Completable(io.reactivex.rxjava3.core.Completable)

io.reactivex.rxjava3.core.Completable c3 = RxJavaBridge.toV3Completable(io.reactivex.Completable)
```

### via CompletableConverter application

```java
c3 = c2.as(RxJavaBridge.toV3Completable())

c2 = c3.to(RxJavaBridge.toV2Completable())
```


## Convert between Disposables

### via static methods

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.disposables.Disposable d2 = RxJavaBridge.toV2Disposable(io.reactivex.rxjava3.disposables.Disposable)

io.reactivex.rxjava3.disosables.Observable d3 = RxJavaBridge.toV3Disposable(io.reactivex.disposables.Disposable)
```

## Convert between Schedulers

### via static methods

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.Scheduler sch2 = RxJavaBridge.toV2Scheduler(io.reactivex.rxjava3.core.Scheduler)

io.reactivex.rxjava3.core.Scheduler sch3 = RxJavaBridge.toV3Scheduler(io.reactivex.Scheduler)
```

### use 3.x standard schedulers in 2.x

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.schedulers.Schedulers.shutdown();

RxJavaBridge.startUsingV3Schedulers();

// when done

RxJavaBridge.stopUsingV3Schedulers();

io.reactivex.schedulers.Schedulers.start();
```

### use 2.x standard schedulers in 3.x

```java
import hu.akarnokd.rxjava3.bridge.RxJavaBridge;

io.reactivex.rxjava3.schedulers.Schedulers.shutdown();

RxJavaBridge.startUsingV2Schedulers();

// when done

RxJavaBridge.stopUsingV2Schedulers();

io.reactivex.rxjava3.schedulers.Schedulers.start();
```
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ build.dependsOn jacocoTestReport

check.dependsOn jacocoTestReport

javadoc {
failOnError = false

options.links(
"http://docs.oracle.com/javase/7/docs/api/",
"http://reactivex.io/RxJava/2.x/javadoc",
"http://reactivex.io/RxJava/3.x/javadoc"
)
}

group = "com.github.akarnokd"

Expand Down
77 changes: 77 additions & 0 deletions src/main/java/hu/akarnokd/rxjava3/bridge/CompletableV2toV3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2019 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.bridge;

final class CompletableV2toV3 extends io.reactivex.rxjava3.core.Completable
implements io.reactivex.CompletableConverter<io.reactivex.rxjava3.core.Completable> {

final io.reactivex.Completable source;

static final CompletableV2toV3 CONVERTER = new CompletableV2toV3(null);

CompletableV2toV3(io.reactivex.Completable source) {
this.source = source;
}

@Override
protected void subscribeActual(io.reactivex.rxjava3.core.CompletableObserver s) {
source.subscribe(new CompletableObserverV3toV2(s));
}

@Override
public io.reactivex.rxjava3.core.Completable apply(io.reactivex.Completable upstream) {
return new CompletableV2toV3(upstream);
}

static final class CompletableObserverV3toV2
implements io.reactivex.CompletableObserver, io.reactivex.rxjava3.disposables.Disposable {

final io.reactivex.rxjava3.core.CompletableObserver downstream;

io.reactivex.disposables.Disposable upstream;

CompletableObserverV3toV2(io.reactivex.rxjava3.core.CompletableObserver downstream) {
this.downstream = downstream;
}

@Override
public void onSubscribe(io.reactivex.disposables.Disposable d) {
this.upstream = d;
downstream.onSubscribe(this);
}

@Override
public void onError(Throwable e) {
downstream.onError(e);
}

@Override
public void onComplete() {
downstream.onComplete();
}

@Override
public boolean isDisposed() {
return upstream.isDisposed();
}

@Override
public void dispose() {
upstream.dispose();
}
}
}
77 changes: 77 additions & 0 deletions src/main/java/hu/akarnokd/rxjava3/bridge/CompletableV3toV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2019 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.bridge;

final class CompletableV3toV2 extends io.reactivex.Completable
implements io.reactivex.rxjava3.core.CompletableConverter<io.reactivex.Completable> {

final io.reactivex.rxjava3.core.Completable source;

static final CompletableV3toV2 CONVERTER = new CompletableV3toV2(null);

CompletableV3toV2(io.reactivex.rxjava3.core.Completable source) {
this.source = source;
}

@Override
protected void subscribeActual(io.reactivex.CompletableObserver s) {
source.subscribe(new CompletableObserverV2toV3(s));
}

@Override
public io.reactivex.Completable apply(io.reactivex.rxjava3.core.Completable upstream) {
return new CompletableV3toV2(upstream);
}

static final class CompletableObserverV2toV3
implements io.reactivex.rxjava3.core.CompletableObserver, io.reactivex.disposables.Disposable {

final io.reactivex.CompletableObserver downstream;

io.reactivex.rxjava3.disposables.Disposable upstream;

CompletableObserverV2toV3(io.reactivex.CompletableObserver downstream) {
this.downstream = downstream;
}

@Override
public void onSubscribe(io.reactivex.rxjava3.disposables.Disposable d) {
this.upstream = d;
downstream.onSubscribe(this);
}

@Override
public void onError(Throwable e) {
downstream.onError(e);
}

@Override
public void onComplete() {
downstream.onComplete();
}

@Override
public boolean isDisposed() {
return upstream.isDisposed();
}

@Override
public void dispose() {
upstream.dispose();
}
}
}
46 changes: 46 additions & 0 deletions src/main/java/hu/akarnokd/rxjava3/bridge/DisposableV2toV3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2019 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.bridge;

final class DisposableV2toV3 implements io.reactivex.rxjava3.disposables.Disposable {

final io.reactivex.disposables.Disposable disposable;

DisposableV2toV3(io.reactivex.disposables.Disposable disposable) {
this.disposable = disposable;
}

@Override
public boolean isDisposed() {
return disposable.isDisposed();
}

@Override
public void dispose() {
disposable.dispose();
}

static io.reactivex.rxjava3.disposables.Disposable wrap(io.reactivex.disposables.Disposable disposable) {
if (disposable == io.reactivex.internal.disposables.DisposableHelper.DISPOSED) {
return io.reactivex.rxjava3.internal.disposables.DisposableHelper.DISPOSED;
}
if (disposable == io.reactivex.internal.disposables.EmptyDisposable.INSTANCE) {
return io.reactivex.rxjava3.internal.disposables.EmptyDisposable.INSTANCE;
}
return new DisposableV2toV3(disposable);
}
}
Loading

0 comments on commit 722ce7b

Please sign in to comment.