當前位置: 首頁>>代碼示例>>Java>>正文


Java Observable.merge方法代碼示例

本文整理匯總了Java中io.reactivex.Observable.merge方法的典型用法代碼示例。如果您正苦於以下問題:Java Observable.merge方法的具體用法?Java Observable.merge怎麽用?Java Observable.merge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.Observable的用法示例。


在下文中一共展示了Observable.merge方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionsToResults

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected ObservableTransformer<Action, Result> actionsToResults() {
    return upstream -> Observable.merge(
            upstream.ofType(LandingUiActions.LogoutAction.class)
                .flatMap(action ->
                    logoutUseCase.performAction(action)
                        .onErrorReturn(throwable -> Result.error(action, throwable))
                        .startWith(Result.loading(action))),
            upstream.ofType(LandingUiActions.GetProfileAction.class)
                .flatMap(action ->
                    getUserUseCase.performAction(action)
                        .onErrorReturn(throwable -> Result.error(action, throwable))
                        .startWith(Result.loading(action))
                )
    );
}
 
開發者ID:sztomek,項目名稱:cleanarchitecture-unidirectional,代碼行數:17,代碼來源:LandingPresenter.java

示例2: eventsToActions

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected ObservableTransformer<UiEvent, Action> eventsToActions() {
    return upstream -> Observable.merge(
            upstream.ofType(TimezoneEditUiEvents.GetTimezoneEvent.class)
                .map(event -> TimezoneEditUiActions.get(event.getUserId(),event.getTimezoneId())),
            upstream.ofType(TimezoneEditUiEvents.SaveTimezoneEvent.class)
                .map(event -> {
                    final TimezoneEditUiActions.SaveTimezoneAction.Builder builder = new TimezoneEditUiActions.SaveTimezoneAction.Builder();
                    final TimezoneModel tz = event.getTimezone();
                    builder.setCity(tz.getCity());
                    builder.setDifference(tryParseDifference(tz.getDifference()));
                    builder.setId(tz.getId());
                    builder.setName(tz.getName());
                    builder.setUserId(tz.getOwnerId());
                    return TimezoneEditUiActions.save(builder);
                }),
            upstream.ofType(DeleteTimezoneEvent.class)
                .map(event -> TimezoneEditUiActions.delete(event.getUserId(), event.getTimezoneId()))
    );
}
 
開發者ID:sztomek,項目名稱:cleanarchitecture-unidirectional,代碼行數:21,代碼來源:TimezoneEditPresenter.java

示例3: squareClicks

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
public Observable<BoardCoordinate> squareClicks() {
  ArrayList<Observable<BoardCoordinate>> observables = new ArrayList<>();
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      final int finalI = i;
      final int finalJ = j;
      observables.add(
          RxView.clicks(imageButtons[i][j])
              .map(
                  new Function<Object, BoardCoordinate>() {
                    @Override
                    public BoardCoordinate apply(Object irrelevant) throws Exception {
                      return new BoardCoordinate(finalI, finalJ);
                    }
                  }));
    }
  }
  return Observable.merge(observables);
}
 
開發者ID:uber,項目名稱:RIBs,代碼行數:21,代碼來源:TicTacToeView.java

示例4: actionsToResults

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected ObservableTransformer<Action, Result> actionsToResults() {
    return upstream -> Observable.merge(
            upstream.ofType(TimezonesUiActions.RefreshAction.class)
                    .flatMap(refreshAction ->
                            listUseCase.performAction(refreshAction)
                                    .onErrorReturn(t -> Result.error(refreshAction, t))
                                    .startWith(Result.loading(refreshAction))),
            upstream.ofType(TimezonesUiActions.LoadMoreAction.class)
                    .flatMap(loadMoreAction ->
                            listUseCase.performAction(loadMoreAction)
                                    .onErrorReturn(t -> Result.error(loadMoreAction, t))
                                    .startWith(Result.loading(loadMoreAction))),
            upstream.ofType(DeleteTimezoneAction.class)
                    .flatMap(action ->
                            deleteUseCase.performAction(action)
                                    .onErrorReturn(t -> Result.error(action, t))
                                    .startWith(Result.loading(action)))
    );
}
 
開發者ID:sztomek,項目名稱:cleanarchitecture-unidirectional,代碼行數:21,代碼來源:TimezonePresenter.java

示例5: startGameRequest

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
public Observable<GameKey> startGameRequest(List<? extends GameKey> gameKeys) {
  List<Observable<GameKey>> observables = new ArrayList<>();
  for (final GameKey gameKey : gameKeys) {
    Button button = (Button) LayoutInflater.from(getContext()).inflate(R.layout.game_button, this, false);
    button.setText(gameKey.gameName());
    Observable<GameKey> observable = RxView
        .clicks(button)
        .map(new Function<Object, GameKey>() {
          @Override
          public GameKey apply(Object o) throws Exception {
            return gameKey;
          }
        });
    observables.add(observable);
    addView(button);
  }
  return Observable.merge(observables);
}
 
開發者ID:uber,項目名稱:RIBs,代碼行數:20,代碼來源:OffGameView.java

示例6: clock

import io.reactivex.Observable; //導入方法依賴的package包/類
private static Observable<Long> clock() {
    Observable<Long> fast = Observable.interval(1, TimeUnit.SECONDS);
    Observable<Long> slow = Observable.interval(3, TimeUnit.SECONDS);

    return Observable.merge(
            slow.filter(t -> isSlowTickTime()).doOnEach(w->System.out.println("<SLOW>")),
            fast.filter(t -> !isSlowTickTime()).doOnEach(w->System.out.println("<FAST>"))
    );
}
 
開發者ID:OlegDokuka,項目名稱:reactive-playing,代碼行數:10,代碼來源:TickTack.java

示例7: toObservableSticky

import io.reactivex.Observable; //導入方法依賴的package包/類
/**
 * 根據傳遞的 eventType 類型返回特定類型(eventType)的 被觀察者
 */
public <T> Observable<T> toObservableSticky(final Class<T> eventType) {
    synchronized (mStickyEventMap) {
        Observable<T> observable = mBus.ofType(eventType);
        final Object event = mStickyEventMap.get(eventType);

        if (event != null) {
            return Observable.merge(observable, Observable.create(subscriber -> subscriber.onNext(eventType.cast(event))));
        } else {
            return observable;
        }
    }
}
 
開發者ID:Loofer,項目名稱:Watermark,代碼行數:16,代碼來源:RxBus.java

示例8: eventsToActions

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected ObservableTransformer<UiEvent, Action> eventsToActions() {
    return upstream -> Observable.merge(
            upstream.ofType(LandingUiEvents.LogoutUiEvent.class)
                .map(event -> LandingUiActions.logout(event.getMenuId())),
            upstream.ofType(LandingUiEvents.MenuSelectedUiEvent.class)
                .startWith(LandingUiEvents.menuSelected(getLastState().getData().getSelectedMenuId()))
                .map(event -> LandingUiActions.getProfile(event.getMenuId(), userManager.getUserId()))
    );
}
 
開發者ID:sztomek,項目名稱:cleanarchitecture-unidirectional,代碼行數:11,代碼來源:LandingPresenter.java

示例9: actionsToResults

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected ObservableTransformer<Action, Result> actionsToResults() {
    return upstream -> Observable.merge(
            upstream.ofType(TimezoneEditUiActions.GetTimezoneAction.class)
                .flatMap(action -> getUseCase.performAction(action)
                    .onErrorReturn(t -> Result.error(action, t))
                    .startWith(Result.loading(action))
                ),
            upstream.ofType(TimezoneEditUiActions.SaveTimezoneAction.class)
                .flatMap(action -> {
                    if (action.getName() == null || action.getName().isEmpty()) {
                        return Observable.just(Result.error(action, new FormValidationException("Name cannot be empty!")));
                    } else if (action.getCity() == null || action.getCity().isEmpty()) {
                        return Observable.just(Result.error(action, new FormValidationException("City cannot be empty!")));
                    } else if (action.getDifference() < -12 || action.getDifference() > 12) {
                        return Observable.just(Result.error(action, new FormValidationException("Difference must be an integer between -12 and +12!")));
                    }
                    final Observable<Result> result;
                    if (action.getId() == null) {
                        result = saveUseCase.performAction(action);
                    } else {
                        result = updateUseCase.performAction(action);
                    }
                    return result
                            .onErrorReturn(t -> Result.error(action, t))
                            .startWith(Result.loading(action));
                }),
            upstream.ofType(DeleteTimezoneAction.class)
                .flatMap(action -> deleteUseCase.performAction(action)
                        .onErrorReturn(t -> Result.error(action, t))
                        .startWith(Result.loading(action))
                )
    );
}
 
開發者ID:sztomek,項目名稱:cleanarchitecture-unidirectional,代碼行數:35,代碼來源:TimezoneEditPresenter.java

示例10: actionsToResults

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected ObservableTransformer<Action, Result> actionsToResults() {
    return upstream -> Observable.merge(
            upstream.ofType(CheckUserActions.CheckUserExists.class)
                    .flatMap(checkUserExists -> checkUserUseCase.performAction(checkUserExists)
                            .onErrorReturn(throwable -> Result.error(checkUserExists, throwable))
                            .startWith(Result.<Boolean, CheckUserActions.CheckUserExists>loading(checkUserExists))),
            upstream.ofType(CheckUserActions.RegisterUserRecord.class)
                    .flatMap(action -> registerUserUseCase.performAction(action)
                            .onErrorReturn(throwable -> Result.error(action, throwable)))
    );
}
 
開發者ID:sztomek,項目名稱:cleanarchitecture-unidirectional,代碼行數:13,代碼來源:CheckUserPresenter.java

示例11: maybeInitCookbooks

import io.reactivex.Observable; //導入方法依賴的package包/類
public static Observable<Event> maybeInitCookbooks(final FileSystem fs, final BuckarooConfig config) {

        final Path configFolder = fs.getPath(
            System.getProperty("user.home"),
            ".buckaroo");

        return Observable.merge(config.cookbooks
            .stream()
            .filter(cookbook -> !Files.exists(configFolder.resolve(cookbook.name.toString())))
            .map(cookbook ->
                UpdateTasks.updateCookbook(configFolder, cookbook))
            .collect(toImmutableList())
        );
    }
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:15,代碼來源:CommonTasks.java

示例12: oneOf

import io.reactivex.Observable; //導入方法依賴的package包/類
private Observable<?> oneOf(Observable<?> trigger, Observable<?> pending) {
    if (trigger == null) {
        return Observable.just(TRIGGER);
    }
    return Observable.merge(trigger, pending);
}
 
開發者ID:paozhuanyinyu,項目名稱:XPermission,代碼行數:7,代碼來源:XPermission.java

示例13: oneOf

import io.reactivex.Observable; //導入方法依賴的package包/類
private Observable<?> oneOf(Observable<?> trigger, Observable<?> pending) {
    if (trigger == null) {
        return Observable.just(new Object());
    }
    return Observable.merge(trigger, pending);
}
 
開發者ID:ChangWeiBa,項目名稱:AesExoPlayer,代碼行數:7,代碼來源:RxPermissions.java

示例14: oneOf

import io.reactivex.Observable; //導入方法依賴的package包/類
private Observable<?> oneOf(Observable<?> trigger, Observable<?> pending) {
    if (trigger == null) {
        return Observable.just(1);
    }
    return Observable.merge(trigger, pending);
}
 
開發者ID:CodyyAndroid,項目名稱:RxPermissions,代碼行數:7,代碼來源:RxPermissions.java

示例15: observeEach

import io.reactivex.Observable; //導入方法依賴的package包/類
/**
 * Converts a {@link Promise} for an iterable into an {@link Observable}.
 * <p>
 * The promised iterable will be emitted to the observer one element at a time, like {@link Observable#fromIterable(Iterable)}.
 * <p>
 * <pre class="java">{@code
 * import ratpack.rx.RxRatpack;
 * import ratpack.exec.Promise;
 * import ratpack.test.exec.ExecHarness;
 * <p>
 * import java.util.Arrays;
 * import java.util.LinkedList;
 * import java.util.List;
 * <p>
 * import public static org.junit.Assert.assertEquals;
 * <p>
 * public class Example {
 * public static void main(String... args) throws Exception {
 * final List<String> items = new LinkedList<>();
 * ExecHarness.runSingle(e ->
 * Promise.value(Arrays.asList("foo", "bar"))
 * .to(RxRatpack::observeEach)
 * .subscribe(items::add)
 * );
 * <p>
 * assertEquals(Arrays.asList("foo", "bar"), items);
 * }
 * }
 * }</pre>
 *
 * @param promise the promise
 * @param <T>     the element type of the promised iterable
 * @param <I>     the type of iterable
 * @return an observable for each element of the promised iterable
 * @see #observe(ratpack.exec.Promise)
 */
public static <T, I extends Iterable<T>> Observable<T> observeEach(Promise<I> promise) {
  return Observable.merge(observe(promise).map(Observable::fromIterable));
}
 
開發者ID:drmaas,項目名稱:ratpack-rx2,代碼行數:40,代碼來源:RxRatpack.java


注:本文中的io.reactivex.Observable.merge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。