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
| Observable<Integer> integerObservable = Observable.just(1, 2, 3); | |
| Single<Boolean> booleanSingle = integerObservable.any(new Predicate<Integer>() { | |
| @Override | |
| public boolean test(Integer integer) throws Exception { | |
| return integer % 2 == 0; | |
| } | |
| }); | |
| booleanSingle.subscribe(l -> System.out.println("Subscriber #1 onNext: " + l), (Throwable e) -> System.out.println("onError")); |
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
| Observable<Integer> integerObservable = Observable.just(1,2,3); | |
| Single<Integer> integerSingle = integerObservable.single(1); | |
| integerSingle.subscribe(l -> System.out.println("Subscriber #1 onNext: " + l), (Throwable e) -> System.out.println("onError")); | |
| integerSingle = integerObservable.singleOrError(); | |
| integerSingle.subscribe(l -> System.out.println("Subscriber #1 onNext: " + l), (Throwable e) -> System.out.println("onError")); |
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
| Observable<Long> observableInterval = Observable.interval(2, TimeUnit.SECONDS); | |
| PublishSubject<Long> publishSubject = PublishSubject.create(); | |
| observableInterval.subscribe(publishSubject); | |
| publishSubject.subscribe(l -> System.out.println("Subscriber #1 onNext: " + l)); | |
| try { | |
| Thread.sleep(2000); | |
| } catch (InterruptedException e) { |
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
| Observer<Integer> observer = new Observer<Integer>() { | |
| @Override | |
| public void onSubscribe(Disposable d) { | |
| System.out.println("onSubscribe"); | |
| } | |
| @Override | |
| public void onNext(Integer o) { | |
| System.out.println("onNext " + o); | |
| } |
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
| Observable<Integer> observable = new ObservableCreate<Integer>(new Observable.OnSubscribe<Integer>() { | |
| @Override | |
| public void subscribe(ObservableEmitter<Integer> emitter) throws Exception { | |
| emitter.onNext(10); | |
| emitter.onNext(20); | |
| emitter.onComplete(); | |
| } | |
| }); |
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
| import org.junit.Test; | |
| import io.reactivex.Observable; | |
| import static junit.framework.Assert.assertTrue; | |
| public class RxJavaUnitTest { | |
| String result=""; |
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
| Path path = Files.writeString(Files.createTempFile("test", ".txt"), "This was posted on JD"); | |
| System.out.println(path); | |
| String s = Files.readString(path); | |
| System.out.println(s); //This was posted on JD |
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
| class MemoryPolluter { | |
| static final int MEGABYTE_IN_BYTES = 1024 * 1024; | |
| static final int ITERATION_COUNT = 1024 * 10; | |
| static void main(String[] args) { | |
| System.out.println("Starting pollution"); | |
| for (int i = 0; i < ITERATION_COUNT; i++) { | |
| byte[] array = new byte[MEGABYTE_IN_BYTES]; |
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
| public void method() { | |
| String localVariable = "Local"; | |
| Foo foo = parameter -> { | |
| String localVariable = parameter; | |
| return localVariable; | |
| }; | |
| } |
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
| Foo foo = parameter -> { String result = "Something " + parameter; | |
| //many lines of code | |
| return result; | |
| }; |