本文整理汇总了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))
)
);
}
示例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()))
);
}
示例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);
}
示例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)))
);
}
示例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);
}
示例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>"))
);
}
示例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;
}
}
}
示例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()))
);
}
示例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))
)
);
}
示例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)))
);
}
示例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())
);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}