From 8214c8dd97a38b06959aae00ca678b521c4abef5 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 2 Aug 2017 00:05:37 +0200 Subject: [PATCH 1/2] Refactor --- .../main/java/com/baelding/rxjava/operator/toLength.java | 8 +------- .../baeldung/rxjava/RxJavaCustomOperatorUnitTest.java | 9 +-------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java b/rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java index 47398ddcb8..fa997b563d 100644 --- a/rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java +++ b/rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java @@ -11,12 +11,6 @@ public class toLength implements Transformer { @Override public Observable call(Observable source) { - - return source.map(new Func1() { - @Override - public Integer call(String str) { - return str.length(); - } - }); + return source.map(String::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..99ac0351be 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java @@ -96,14 +96,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")) From 4ff0768feacf43f622d9e79720c17647a2b18361 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 2 Aug 2017 00:06:14 +0200 Subject: [PATCH 2/2] Refactor --- .../operator/{cleanString.java => CleanString.java} | 4 ++-- .../rxjava/operator/{toLength.java => ToLength.java} | 4 ++-- .../baeldung/rxjava/RxJavaCustomOperatorUnitTest.java | 9 ++++----- 3 files changed, 8 insertions(+), 9 deletions(-) rename rxjava/src/main/java/com/baelding/rxjava/operator/{cleanString.java => CleanString.java} (91%) rename rxjava/src/main/java/com/baelding/rxjava/operator/{toLength.java => ToLength.java} (75%) 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 similarity index 75% rename from rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java rename to rxjava/src/main/java/com/baelding/rxjava/operator/ToLength.java index fa997b563d..ea954aa71c 100644 --- a/rxjava/src/main/java/com/baelding/rxjava/operator/toLength.java +++ b/rxjava/src/main/java/com/baelding/rxjava/operator/ToLength.java @@ -4,8 +4,8 @@ import rx.Observable; import rx.Observable.Transformer; import rx.functions.Func1; -public class toLength implements Transformer { - public toLength() { +public class ToLength implements Transformer { + public ToLength() { super(); } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java b/rxjava/src/test/java/com/baeldung/rxjava/RxJavaCustomOperatorUnitTest.java index 99ac0351be..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);