public void startAnimation(final int rankWidth, final int rankHeight) { Observable.timer((long)this.innerDelay, TimeUnit.MILLISECONDS).repeat((long)((int)(Math.random() * (double)(this.maxHeartNum - this.minHeartNum)) + this.minHeartNum)).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() { public void call(Long aLong) { BubbleView.this.bubbleAnimation(rankWidth, rankHeight); } }); }
public static Observable<Double> solveWithNewtonsMethod(final Func1<Double, Double> f, final Func1<Double, Double> dfdx, double x0) { return Observable.just(1).repeat().scan(x0, new Func2<Double, Integer, Double>() { @Override public Double call(Double xn, Integer n) { return xn - f.call(xn) / dfdx.call(xn); } }); }
private void repeat() { Observable.range(0, 3) .repeat(2) .subscribe(new Action1<Integer>() { @Override public void call(Integer integer) { Log.d(TAG, "repeat:" +integer.intValue()); } }); }
public Builder delay(Long delay, final TimeUnit unit) { this.delays = Observable.just(delay).map(toMillis(unit)).repeat(); return this; }
public void startAnimation(final int rankWidth, final int rankHeight, int count) { Observable.timer((long)this.innerDelay, TimeUnit.MILLISECONDS).repeat((long)count).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() { public void call(Long aLong) { BubbleView.this.bubbleAnimation(rankWidth, rankHeight); } }); }
public void startAnimation(final int rankWidth, final int rankHeight, int delay, int count) { Observable.timer((long)delay, TimeUnit.MILLISECONDS).repeat((long)count).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() { public void call(Long aLong) { BubbleView.this.bubbleAnimation(rankWidth, rankHeight); } }); }
public Builder delay(Long delay, final TimeUnit unit) { this.delays = Observable.just(delay).map(toMillis(unit)).repeat(); return this; }
public static Observable<Double> solveWithNewtonsMethod(final Func1<Double, Double> f, final Func1<Double, Double> dfdx, double x0) { return Observable.just(1).repeat().scan(x0, new Func2<Double, Integer, Double>() { @Override public Double call(Double xn, Integer n) { return xn - f.call(xn) / dfdx.call(xn); } }); }
public Observable<Collection<Car>> getCarsObservable(){ return Observable.interval(UPDATE_FREQUENCY_SECONDS, TimeUnit.SECONDS) .flatMap(n -> ServiceGenerator.createService(MapClient.class).getCars().map(Map::values)) .repeat() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()); }
private void loadList(List<AppInfo> apps) { mRecyclerView.setVisibility(View.VISIBLE); Observable<AppInfo> fullOfDuplicates = Observable.from(apps).take(3).repeat(3); fullOfDuplicates.distinct().subscribe(new Observer<AppInfo>() { @Override public void onCompleted() { mSwipeRefreshLayout.setRefreshing(false); } @Override public void onError(Throwable e) { Toast.makeText(getActivity(), "Something went south!", Toast.LENGTH_SHORT).show(); mSwipeRefreshLayout.setRefreshing(false); } @Override public void onNext(AppInfo appInfo) { mAddedApps.add(appInfo); mAdapter.addApplication(mAddedApps.size() - 1, appInfo); } }); } }
protected void startPolling() { subscription = Observable .timer(getPollingInterval(), getPollingIntervalUnit(), scheduler) .repeat() .filter(interval -> tryAcquireLock()) .subscribe(interval -> { try { MDC.put(AGENT_MDC_KEY, this.getClass().getSimpleName()); tick(); } catch (Exception e) { log.error("Error running agent tick", e); } finally { MDC.remove(AGENT_MDC_KEY); } }); }
static <T> Observable<T> odd(Observable<T> upstream) { Observable<Boolean> trueFalse = just(true, false).repeat(); return upstream .zipWith(trueFalse, Pair::of) .filter(Pair::getRight) .map(Pair::getLeft); }
private <T> Observable.Transformer<T, T> odd() { Observable<Boolean> trueFalse = just(true, false).repeat(); return upstream -> upstream .zipWith(trueFalse, Pair::of) .filter(Pair::getRight) .map(Pair::getLeft); }
public Observable<String> infos() { Observable<String> texts = Observable.just("Hello World", "Hallo Welt", "Bonjour le monde", "Ciao mondo").repeat(); Observable<Long> trigger = Observable.interval(1, TimeUnit.SECONDS); return Observable.zip(texts, trigger, (text, aLong) -> text).doOnNext(text -> SysOutUtils.sysout("Sending: " + text)); }
@Test public void sample_120() throws Exception { Random random = new Random(); Observable .defer(() -> just(random.nextGaussian())) .repeat(1000) .buffer(100, 1) .map(this::averageOfList) .subscribe(System.out::println); }
@Test public void test() throws Exception { Observable<String> delay = Observable.just("") .switchMap(dummy -> Observable.timer(randomTime(), TimeUnit.SECONDS)) .map( a -> String.valueOf(a) ) .repeat(); Observable<String> messages = Observable.just("Test") //eventually lines from a file... .repeat(); messages.zipWith(delay, (d, msg) -> ""+d+" "+msg ).subscribe( System.out::println ); Thread.sleep(10000); } }
@Test public void sample_589() throws Exception { Observable<Boolean> trueFalse = Observable.just(true, false).repeat(); Observable<Integer> upstream = Observable.range(30, 8); Observable<Integer> downstream = upstream .zipWith(trueFalse, Pair::of) .filter(Pair::getRight) .map(Pair::getLeft); }
@Test public void decode() { byte[] bytes = new byte[16]; Arrays.fill(bytes, (byte)65); byte[] bytes2 = new byte[16]; Arrays.fill(bytes, (byte)65); bytes[15] = 10; Observable<byte[]> data = Observable.just(bytes, bytes, bytes2).repeat(500); StringObservable.decode(data, StandardCharsets.UTF_8) .observeOn(Schedulers.computation(), false, 1) .toBlocking() .subscribe(System.out::println); }
@Test public void sample_600() throws Exception { Observable<Boolean> trueFalse = Observable.just(true, false).repeat(); Observable<Integer> upstream = Observable.range(30, 8); upstream.zipWith(trueFalse, (t, bool) -> bool ? just(t) : empty()) .flatMap(obs -> obs); } }
@Test public void sample_112() throws Exception { Observable .range(1, 4) .repeat() .lift(toStringOfOdd()) .take(3) .subscribe( System.out::println, Throwable::printStackTrace, () -> System.out.println("Completed") ); } }