This file contains 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
package com.example.hanlufeng.retrofitdemo; | |
import okhttp3.ResponseBody; | |
import retrofit2.Call; | |
import retrofit2.http.GET; | |
import retrofit2.http.Url; | |
interface ApiEndpoints { | |
@GET | |
Call<ResponseBody> rxGetImageCall(@Url String imageUrl); |
This file contains 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
//## from https://github.com/kamilwlf/Kamil-thoughts/blob/master/ToStringConverterFactory.java | |
package com.example.hanlufeng.retrofitdemo; | |
import java.io.IOException; | |
import java.lang.annotation.Annotation; | |
import java.lang.reflect.Type; | |
import okhttp3.ResponseBody; | |
import retrofit2.Converter; |
This file contains 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
ConnectableObservable<Boolean> booleanObservable = Observable | |
.fromCallable(() -> { | |
Thread.sleep(1_000); | |
return true; | |
}).startWith(false) | |
.subscribeOn(Schedulers.io()) | |
.replay(2); | |
Disposable sub1 = booleanObservable | |
.doOnSubscribe(disposable -> { |
This file contains 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
@org.junit.Test | |
public void name() throws Exception { | |
Observable<String> obs = Observable.create(customLogic()); | |
} | |
private Observable.OnSubscribe<String> customLogic() { | |
return subscriber -> { | |
try { | |
if (!subscriber.isUnsubscribed()) { | |
Scanner scanner = new Scanner("wurst.file.c"); |
This file contains 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
@Test | |
public void name() throws Exception { | |
Subscription subscribe = Observable.merge(getObservable(), getTimedObservable()) | |
.observeOn(Schedulers.io()) | |
.subscribe(s -> { | |
System.out.println("subscription " + s + "-Thread- " + Thread.currentThread()); | |
//Log.i("test", s); | |
}); |
This file contains 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
package com.example.sergej.rxjavatestapp; | |
import com.google.gson.JsonSyntaxException; | |
import com.google.gson.TypeAdapter; | |
import com.google.gson.stream.JsonReader; | |
import com.google.gson.stream.JsonToken; | |
import com.google.gson.stream.JsonWriter; | |
import java.io.IOException; |
This file contains 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
@Test | |
public void rollingBufferSearchForSequenceTest() throws Exception { | |
TestObserver<List<Integer>> listTestObserver = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6)) | |
.compose(searchForSequence(Arrays.asList(1, 2))) | |
.test() | |
.assertComplete() | |
.assertValueCount(2); | |
List<Integer> collect = listTestObserver.values() | |
.stream() |
This file contains 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
@Test | |
public void onComplete() throws Exception { | |
TestScheduler testScheduler = new TestScheduler(); | |
Observable<String> build = ObservableTestBuilder.<String>create(testScheduler).onNext("hans", 500, TimeUnit.MILLISECONDS) | |
.onNext("wurst", 500, TimeUnit.MILLISECONDS) | |
.onNext("isst", 200, TimeUnit.MILLISECONDS) | |
.onNext("gerne", 300, TimeUnit.MILLISECONDS) | |
.onNext("fleisch", 1, TimeUnit.SECONDS) | |
.onComplete(0, TimeUnit.MILLISECONDS) |
This file contains 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
public class Stackoverflow45784477 { | |
@Test | |
public void name() throws Exception { | |
Observable.just(1000, 500, 1300) | |
.observeOn(Schedulers.single()) | |
.flatMap(integer -> create(integer)) | |
.doOnNext(s -> { | |
System.out.println(Thread.currentThread().getName()); | |
}) | |
.test() |
This file contains 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
@Test | |
public void observableLimit2() throws Exception { | |
long lowerBound = 0; | |
long higherBound = 1000; | |
long actualSum = (higherBound * (higherBound + 1)) / 2; | |
Single<Long> longSingle = Flowable.rangeLong(lowerBound, higherBound + 1) | |
.doOnNext(aLong -> System.out.println(Thread.currentThread().toString())) | |
.reduce(0L, (integer, aLong) -> { |
OlderNewer