Merge pull request #2355 from eugenp/rxjava_ref

Rxjava refactor
This commit is contained in:
Doha2012 2017-08-02 12:39:21 +02:00 committed by GitHub
commit 5ba675be35
4 changed files with 23 additions and 37 deletions

View File

@ -3,9 +3,9 @@ package com.baelding.rxjava.operator;
import rx.Observable.Operator;
import rx.Subscriber;
public class cleanString implements Operator<String, String> {
public class CleanString implements Operator<String, String> {
public cleanString() {
public CleanString() {
super();
}

View File

@ -0,0 +1,16 @@
package com.baelding.rxjava.operator;
import rx.Observable;
import rx.Observable.Transformer;
import rx.functions.Func1;
public class ToLength implements Transformer<String, Integer> {
public ToLength() {
super();
}
@Override
public Observable<Integer> call(Observable<String> source) {
return source.map(String::length);
}
}

View File

@ -1,22 +0,0 @@
package com.baelding.rxjava.operator;
import rx.Observable;
import rx.Observable.Transformer;
import rx.functions.Func1;
public class toLength implements Transformer<String, Integer> {
public toLength() {
super();
}
@Override
public Observable<Integer> call(Observable<String> source) {
return source.map(new Func1<String, Integer>() {
@Override
public Integer call(String str) {
return str.length();
}
});
}
}

View File

@ -15,10 +15,9 @@ import rx.Observable;
import rx.Observable.Operator;
import rx.Observable.Transformer;
import rx.Subscriber;
import rx.functions.Func1;
import com.baelding.rxjava.operator.cleanString;
import com.baelding.rxjava.operator.toLength;
import com.baelding.rxjava.operator.CleanString;
import com.baelding.rxjava.operator.ToLength;
public class RxJavaCustomOperatorUnitTest {
@ -28,7 +27,7 @@ public class RxJavaCustomOperatorUnitTest {
final List<String> results = new ArrayList<String>();
final Observable<String> observable = Observable.from(list)
.lift(new cleanString());
.lift(new CleanString());
// when
observable.subscribe(results::add);
@ -45,7 +44,7 @@ public class RxJavaCustomOperatorUnitTest {
final List<Integer> results = new ArrayList<Integer>();
final Observable<Integer> observable = Observable.from(list)
.compose(new toLength());
.compose(new ToLength());
// when
observable.subscribe(results::add);
@ -96,14 +95,7 @@ public class RxJavaCustomOperatorUnitTest {
@Test
public void whenUseFunctionTransformer_thenSuccess() {
final Transformer<String, Integer> toLengthFn = source -> {
return source.map(new Func1<String, Integer>() {
@Override
public Integer call(String str) {
return str.length();
}
});
};
final Transformer<String, Integer> toLengthFn = source -> source.map(String::length);
final List<Integer> results = new ArrayList<Integer>();
Observable.from(Arrays.asList("apple", "orange"))