當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。