当前位置: 首页>>代码示例>>Java>>正文


Java Observable.flatMap方法代码示例

本文整理汇总了Java中io.reactivex.Observable.flatMap方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.flatMap方法的具体用法?Java Observable.flatMap怎么用?Java Observable.flatMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Observable的用法示例。


在下文中一共展示了Observable.flatMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<?> apply(Observable<? extends Throwable> observable) throws Exception {
    return observable
            .flatMap(new Function<Throwable, ObservableSource<?>>() {
                @Override
                public ObservableSource<?> apply(Throwable throwable) throws Exception {
                    if (++retryCount <= maxRetries && (throwable instanceof SocketTimeoutException
                            || throwable instanceof ConnectException)) {
                        ViseLog.d("get response data error, it will try after " + retryDelayMillis
                                + " millisecond, retry count " + retryCount);
                        return Observable.timer(retryDelayMillis, TimeUnit.MILLISECONDS);
                    }
                    return Observable.error(ApiException.handleException(throwable));
                }
            });
}
 
开发者ID:xiaoyaoyou1212,项目名称:XSnow,代码行数:17,代码来源:ApiRetryFunc.java

示例2: apply

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public ObservableSource<?> apply(@NonNull Observable<Throwable> throwableObservable) throws Exception {

    return throwableObservable
            .flatMap(new Function<Throwable, ObservableSource<?>>() {
                @Override
                public ObservableSource<?> apply(@NonNull Throwable throwable) throws Exception {
                    if (++retryCount <= maxRetries) {
                        // When this Observable calls onNext, the original Observable will be retried (i.e. re-subscribed).
                        Log.d("get error, it will try after " + retryDelaySecond
                                + " second, retry count " + retryCount);
                        return Observable.timer(retryDelaySecond,
                                TimeUnit.SECONDS);
                    }
                    // Max retries hit. Just pass the error along.
                    return Observable.error(throwable);
                }
            });
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:20,代码来源:RetryWithDelay.java

示例3: apply

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<?> apply(@NonNull Observable<? extends Throwable> attempts) throws Exception {
    return attempts.flatMap(new Function<Throwable, Observable<?>>() {
        @Override
        public Observable<?> apply(@NonNull Throwable throwable) throws Exception {
            if (++retryCount <= maxRetries) {
                // When this Observable calls onNext, the original Observable will be retried (i.e. re-subscribed).
                LogUtils.e("get error, it will try after " + retryDelayMillis +
                        " millisecond, retry count " + retryCount);
                return Observable.timer(retryDelayMillis, TimeUnit.MILLISECONDS);
            }
            // Max retries hit. Just pass the error along.
            return Observable.error(throwable);
        }
    });
}
 
开发者ID:imliujun,项目名称:LJFramework,代码行数:17,代码来源:RetryWithDelay.java

示例4: apply

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public ObservableSource<?> apply(@NonNull Observable<Throwable> throwableObservable) throws Exception {
    return throwableObservable
            .flatMap(new Function<Throwable, ObservableSource<?>>() {
                @Override
                public ObservableSource<?> apply(@NonNull Throwable throwable) throws Exception {
                    if (++retryCount <= maxRetries) {
                        // When this Observable calls onNext, the original Observable will be retried (i.e. re-subscribed).
                        Log.d(TAG, "Observable get error, it will try after " + retryDelaySecond
                                + " second, retry count " + retryCount);
                        return Observable.timer(retryDelaySecond,
                                TimeUnit.SECONDS);
                    }
                    // Max retries hit. Just pass the error along.
                    return Observable.error(throwable);
                }
            });
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:19,代码来源:RetryWithDelay.java

示例5: put

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<StorageResult> put(Observable<Entry> entries) {
  return entries.flatMap((Function<Entry, ObservableSource<StorageResult>>) entry -> {
    final String insert =
        "INSERT OR REPLACE INTO TILES(zoom_level, tile_column, tile_row, tile_data)"
            + " values (?, ?, ?, ?);";

    byte[] compressedMvt;
    try {
      compressedMvt = CompressUtil.getCompressedAsGzip(entry.getVector());
    } catch (final IOException ex) {
      throw Exceptions.propagate(ex);
    }

    Observable<Object> params = Observable.<Object>just(entry.getZoomLevel(), entry.getColumn(),
        flipY(entry.getRow(), entry.getZoomLevel()), compressedMvt);

    return dataSource.update(insert)
        .parameterStream(params.toFlowable(BackpressureStrategy.BUFFER)).counts()
        .map(integer -> new StorageResult(entry))
        .onErrorReturn(throwable -> new StorageResult(entry, new Exception(throwable)))
        .toObservable();
  });
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:25,代码来源:StorageImpl.java

示例6: loadAutocompleteCities

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override public void loadAutocompleteCities(Observable<String> cityQueryObservable) {
  Observable<SearchApiResponseModel> a =
      cityQueryObservable.flatMap(new Function<String, Observable<SearchApiResponseModel>>() {
        @Override public Observable<SearchApiResponseModel> apply(String s) throws Exception {
          return getDataManager().locationsApiRequest(s)
              .compose(getCompositeDisposableHelper().<SearchApiResponseModel>applySchedulers());
        }
      });

  getCompositeDisposableHelper().addDisposable(
      a.compose(getCompositeDisposableHelper().<SearchApiResponseModel>applySchedulers())
          .subscribeWith(
              new CityObserver(getMvpView(), getDataManager().getErrorHandlerHelper())));
}
 
开发者ID:nikacotAndroid,项目名称:Weather-Guru-MVP,代码行数:15,代码来源:ManageCityPresenter.java

示例7: apply

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<?> apply(Observable<? extends Throwable> observable) throws Exception {
    return observable.flatMap(new Function<Throwable, ObservableSource<?>>() {
        @Override
        public ObservableSource<?> apply(Throwable throwable) throws Exception {
            if(++retryCount <= maxRetries){
                return todoBeforeRetry.apply(throwable);
            }
            return Observable.error(throwable);
        }
    });
}
 
开发者ID:florent37,项目名称:AndroidMVPresenter,代码行数:13,代码来源:AbstractPresenter.java

示例8: request

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<ActivityResult> request(Observable<?> trigger, final Intent intent) {
    if (intent != null) {
        return trigger.flatMap(new Function<Object, Observable<ActivityResult>>() {
            @Override
            public Observable<ActivityResult> apply(@NonNull Object o) throws Exception {
                return requestImplementation(intent);
            }
        });
    } else {
        throw new IllegalArgumentException("RxActivityResults.request a non null input intent");
    }
}
 
开发者ID:mohamad-amin,项目名称:RxActivityResults,代码行数:13,代码来源:RxActivityResults.java

示例9: skipErrors

import io.reactivex.Observable; //导入方法依赖的package包/类
@Deprecated
public static <T> Observable<T> skipErrors(final Observable<Single<T>> xs) {
    Preconditions.checkNotNull(xs);
    return xs.flatMap(single -> single.map(Optional::of)
        .onErrorReturn(error -> Optional.empty())
        .flatMapObservable(optional ->
            optional.map(Observable::just).orElseGet(Observable::empty)));
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:9,代码来源:MoreObservables.java

示例10: getPopularMovies

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<List<Movie>> getPopularMovies(int page) {
    Observable<DiscoverMoviesResponse> discoverMoviesResponseObservable =
            apiService.discover("popularity.desc", page, ApiUtils.getApiKey());
    return discoverMoviesResponseObservable
            .flatMap(new Function<DiscoverMoviesResponse, ObservableSource<? extends List<Movie>>>() {
                @Override
                public ObservableSource<? extends List<Movie>> apply(DiscoverMoviesResponse discoverMoviesResponse)
                        throws Exception {
                    return Observable.just(discoverMoviesResponse.getResults());
                }
            });
}
 
开发者ID:segunfamisa,项目名称:android-mvvm-sample,代码行数:14,代码来源:MoviesRemoteRepository.java

示例11: testStockPriceFinderFindTheLatestCloseBug

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void testStockPriceFinderFindTheLatestCloseBug() throws IOException {
    Observable<String> stockNames = Observable.just("M", "MSFT", "BTC", "T", "ORCL");
    Observable<String> urls = stockNames.map(s -> "https://finance.google.com/finance/historical?output=csv&q=" + s);
    Observable<String> contentObservable = urls.flatMap(u -> Observable.fromFuture(createFuture(u)).onErrorResumeNext((Throwable e) -> Observable.empty()));
    Observable<String> lineObservable = contentObservable.doOnNext(s -> System.out.println(">>>>" + s)).flatMap(doc ->
            Observable.fromArray(doc.split("\n")).skip(1).take(1));
    Observable<Tuple2<String, Double>> tupleObservable = stockNames.zipWith(lineObservable.map(s -> s.split(",")[4]).map(Double::parseDouble), Tuple2::new);
    tupleObservable.subscribe(System.out::println);
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:11,代码来源:StockFinderTest.java

示例12: apply

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public ObservableSource<T> apply(@NonNull Observable<T> upstream) {
    return upstream.flatMap(new Function<T, ObservableSource<T>>() {
        @Override
        public ObservableSource<T> apply(@NonNull final T t) throws Exception {
            return Observable.create(new ObservableOnSubscribe<T>() {
                @Override
                public void subscribe(@NonNull final ObservableEmitter<T> e) throws Exception {
                    SimpleRuntimePermissionHelper.with(mActivity)
                            .permission(permissions)
                            .showPermissionRationaleListener(showRequestPermissionRationaleListener)
                            .execute(new PermissionListener() {
                                @Override
                                public void onAllPermissionGranted() {
                                    e.onNext(t);
                                    e.onComplete();
                                }

                                @Override
                                public void onPermissionRefuse(PermissionRefuseResultHelper resultHelper) {
                                    e.onError(
                                            new PermissionException(resultHelper)
                                    );
                                }
                            });
                }
            });
        }
    });
}
 
开发者ID:imfms,项目名称:simple-runtime-permission,代码行数:31,代码来源:RxSimpleRuntimePermissionTransform.java

示例13: loadArtist

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<Result> loadArtist(Observable<LoadArtistEvent> events) {
    return events.flatMap(event -> {
        if (!artistId.isPresent()) {
            throw new RuntimeException("An artist id shouldn't be empty");
        }

        return getRepository().getArtist(artistId.getValue())
                .map(LoadArtistResult::success)
                .onErrorReturn(LoadArtistResult::error)
                .toObservable()
                .startWith(LoadArtistResult.IN_PROGRESS);
    });
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:14,代码来源:EditArtistPresenter.java

示例14: saveArtist

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<Result> saveArtist(Observable<SaveArtistEvent> events) {
    return events.flatMap(event -> {
        String newName = event.getName();

        if (newName.isEmpty()) {
            SaveArtistResult result = SaveArtistResult.Builder.createFillError()
                    .nameIsEmpty(true)
                    .build();

            return Observable.just(result);
        }

        EditArtistUiModel uiModel = event.getUiModel();
        Completable completable;

        if (uiModel.isArtistNew()) {
            Artist newArtist = new Artist(newName);
            completable = getRepository().saveArtist(newArtist);
        } else {
            Artist initialArtist = uiModel.getInitialArtist().getValue();
            Artist updatedArtist = new Artist(initialArtist.getId(), newName);
            completable = getRepository().updateArtist(updatedArtist);
        }

        return completable
                .toSingleDefault(SaveArtistResult.SUCCESS)
                .onErrorReturn(t -> {
                    if (t instanceof NotUniqueArtistException) {
                        return SaveArtistResult.Builder.createFillError()
                                .nameIsNotUnique(true)
                                .build();
                    }

                    return SaveArtistResult.SAVING_ERROR;
                })
                .toObservable()
                .startWith(SaveArtistResult.IN_PROGRESS);
    });
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:40,代码来源:EditArtistPresenter.java

示例15: apply

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<?> apply(Observable<? extends Throwable> observable) throws Exception {
    return observable
            .flatMap(new Function<Throwable, ObservableSource<?>>() {
                @Override
                public ObservableSource<?> apply(Throwable throwable) throws Exception {
                    if (++retryCount <= maxRetries && (throwable instanceof SocketTimeoutException
                            || throwable instanceof ConnectException)) {
                        return Observable.timer(retryDelayMillis, TimeUnit.MILLISECONDS);
                    }
                    return Observable.error(ApiException.handleException(throwable));
                }
            });
}
 
开发者ID:qiaodashaoye,项目名称:SuperHttp,代码行数:15,代码来源:ApiRetryFunc.java


注:本文中的io.reactivex.Observable.flatMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。