diff --git a/rxjava/src/main/java/com/baelding/rxjava/operator/cleanString.java b/rxjava/src/main/java/com/baelding/rxjava/operator/CleanString.java similarity index 91% rename from rxjava/src/main/java/com/baelding/rxjava/operator/cleanString.java rename to rxjava/src/main/java/com/baelding/rxjava/operator/CleanString.java index 8ae8d25cd7..9abdd7e07d 100644 --- a/rxjava/src/main/java/com/baelding/rxjava/operator/cleanString.java +++ b/rxjava/src/main/java/com/baelding/rxjava/operator/CleanString.java @@ -3,9 +3,9 @@ package com.baelding.rxjava.operator; import rx.Observable.Operator; import rx.Subscriber; -public class cleanString implements Operator { +public class CleanString implements Operator { - public cleanString() { + public CleanString() { super(); } diff --git a/rxjava/src/main/java/com/baelding/rxjava/operator/ToLength.java b/rxjava/src/main/java/com/baelding/rxjava/operator/ToLength.java new file mode 100644 index 0000000000..ea954aa71c --- /dev/null +++ b/rxjava/src/main/java/com/baelding/rxjava/operator/ToLength.java @@ -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 { + public ToLength() { + super(); + } + + @Override + public Observable call(Observable source) { + return source.map(String::length); + } +} \ No newline at end of file diff --git a/rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java b/rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java deleted file mode 100644 index 47398ddcb8..0000000000 --- a/rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java +++ /dev/null @@ -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 { - public toLength() { - super(); - } - - @Override - public Observable call(Observable source) { - - return source.map(new Func1() { - @Override - public Integer call(String str) { - return str.length(); - } - }); - } -} \ No newline at end of file diff --git a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java index 0cc458c414..ca1169486e 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java @@ -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 results = new ArrayList(); final Observable observable = Observable.from(list) - .lift(new cleanString()); + .lift(new CleanString()); // when observable.subscribe(results::add); @@ -45,7 +44,7 @@ public class RxJavaCustomOperatorUnitTest { final List results = new ArrayList(); final Observable 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 toLengthFn = source -> { - return source.map(new Func1() { - @Override - public Integer call(String str) { - return str.length(); - } - }); - }; + final Transformer toLengthFn = source -> source.map(String::length); final List results = new ArrayList(); Observable.from(Arrays.asList("apple", "orange"))