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