Skip to content

Instantly share code, notes, and snippets.

View SergejIsbrecht's full-sized avatar
💭
UTC+1

SergejIsbrecht

💭
UTC+1
View GitHub Profile
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);
//## 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;
ConnectableObservable<Boolean> booleanObservable = Observable
.fromCallable(() -> {
Thread.sleep(1_000);
return true;
}).startWith(false)
.subscribeOn(Schedulers.io())
.replay(2);
Disposable sub1 = booleanObservable
.doOnSubscribe(disposable -> {
@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");
@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);
});
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;
@SergejIsbrecht
SergejIsbrecht / rxjava_rollingBuffer.java
Created April 3, 2017 20:21
Find Sequence in Observable.
@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()
@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)
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()
@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) -> {