rxjava custom operator (#2352)
* minor logging fix * spring security sso * use basic auth * use form login * cleanup * cleanup * final cleanup * second client app for sso * spring boot bootstrap * add logic * cleanup * add simple controller * add thymeleaf and security * minor fix * minor fix * add more boot properties * fix live test * fix live test * minor fix * semaphores * fix configuration * kotlin collection * add more collection examples * minor upgrade * cucumber java8 * minor fix * rxjava custom operator
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
a3ed5a57a3
commit
b0e05630ea
@@ -0,0 +1,39 @@
|
||||
package com.baelding.rxjava.operator;
|
||||
|
||||
import rx.Observable.Operator;
|
||||
import rx.Subscriber;
|
||||
|
||||
public class cleanString implements Operator<String, String> {
|
||||
|
||||
public cleanString() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subscriber<? super String> call(final Subscriber<? super String> subscriber) {
|
||||
return new Subscriber<String>(subscriber) {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
if (!subscriber.isUnsubscribed()) {
|
||||
subscriber.onCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
if (!subscriber.isUnsubscribed()) {
|
||||
subscriber.onError(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String item) {
|
||||
if (!subscriber.isUnsubscribed()) {
|
||||
final String result = item.replaceAll("[^A-Za-z0-9]", "");
|
||||
subscriber.onNext(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user