当前位置: 首页>>代码示例>>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;未经允许,请勿转载。