This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableSrc | |
* use doOnSubscribe, doOnLifecycle, doOnComplete, doOnDispose, doOnTerminate, | |
* doAfterTerminate, doFinally, doAfterNext, doOnNext | |
* to understand its behavior | |
* This case is the onComplete reached case * | |
* @return | |
*/ | |
public static Observable getObservableLifecycleTrackerDoOn() { | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableWithErrorSrc | |
* use doOnSubscribe, doOnLifecycle, doOnComplete, doOnDispose, doOnTerminate, | |
* doAfterTerminate, doFinally, doAfterNext, doOnNext | |
* to understand its behavior | |
* This case is the onDispose reached case * | |
* @return | |
*/ | |
public static Observable getObservableLifecycleTrackerWithError() { | |
return observableWithErrorSrc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final Observable observableWithErrorSrc =Observable.create( | |
emiter -> { | |
emiter.onNext("Monday"); | |
emiter.onNext(null); | |
} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final Observable observableSrc = Observable.just( | |
"Monday", | |
"Tuesday", | |
"Wednesday", | |
"Thursday", | |
"Friday", | |
"Saturday", | |
"Sunday" | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableSrc | |
* use doOnSubscribe, doOnLifecycle, doOnComplete, doOnDispose, doOnTerminate, | |
* doAfterTerminate, doFinally, doAfterNext, doOnNext | |
* to understand its behavior | |
* This case is the onComplete reached case * | |
* @return | |
*/ | |
public static Observable getObservableLifecycleTrackerDoOn() { | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableWithErrorSrc | |
* use doOnSubscribe, doOnLifecycle, doOnComplete, doOnDispose, doOnTerminate, | |
* doAfterTerminate, doFinally, doAfterNext, doOnNext | |
* to understand its behavior | |
* This case is the onDispose reached case * | |
* @return | |
*/ | |
public static Observable getObservableLifecycleTrackerWithError() { | |
return observableWithErrorSrc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableWithErrorSrc skip error items and return a bad day item instead of the error | |
* @return | |
*/ | |
public static Observable getObservableWithOnErrorReturnItem() { | |
//you can also return an empty Observable and then quit the Observable nicely | |
return observableWithErrorSrc | |
.onErrorReturnItem("Bad day"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableWithErrorSrc skip error items and retry twice | |
* @return | |
*/ | |
public static Observable getObservableWithOnErrorRetry() { | |
//you can also return an empty Observable and then quit the Observable nicely | |
return observableWithErrorSrc | |
.retry(2); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableSrc we use doOnEach to understand its behavior | |
*/ | |
public static Observable getObservableDoOnEach() { | |
return observableSrc.doOnEach(it -> | |
{ | |
System.out.print("onEach is " + it+" :"); | |
if(it.isOnNext()) { | |
System.out.println("isOnNext = " + it.isOnNext() +" and getValue = " + it.getValue()); | |
}else if(it.isOnError()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableIntervalSrc | |
* use doOnSubscribe, doOnLifecycle, doOnComplete, doOnDispose, doOnTerminate, | |
* doAfterTerminate, doFinally, doAfterNext, doOnNext | |
* to understand its behavior | |
* This case is the onDispose reached case * | |
* @return | |
*/ | |
public static Observable getObservableLifecycleTrackerDoOnWithInterval() { | |
/** |