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


Java SingleTransformer类代码示例

本文整理汇总了Java中io.reactivex.SingleTransformer的典型用法代码示例。如果您正苦于以下问题:Java SingleTransformer类的具体用法?Java SingleTransformer怎么用?Java SingleTransformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: logSingle

import io.reactivex.SingleTransformer; //导入依赖的package包/类
/**
 * Creates transform operator, which logs defined events in observable's lifecycle
 * @param msg     message
 * @param bitMask bitmask of events which you want to log
 * @param <T>     type
 * @return transformer
 */
public static <T> SingleTransformer<T, T> logSingle(final String msg, final int bitMask) {
    return upstream -> {
        if ((bitMask & LOG_SUBSCRIBE) > 0) {
            upstream = upstream.compose(sLogSubscribe(msg));
        }
        if ((bitMask & LOG_ERROR) > 0) {
            upstream = upstream.compose(sLogError(msg));
        }
        if ((bitMask & LOG_NEXT_DATA) > 0) {
            upstream = upstream.compose(sLogSuccess(msg));
        } else if ((bitMask & LOG_NEXT_EVENT) > 0) {
            upstream = upstream.compose(sLogSuccessEvent(msg));
        }
        if ((bitMask & LOG_DISPOSE) > 0) {
            upstream = upstream.compose(sLogDispose(msg));
        }
        return upstream;
    };
}
 
开发者ID:Team-SOFTsk,项目名称:RxLog,代码行数:27,代码来源:RxLog.java

示例2: storeToCacheAndReturn

import io.reactivex.SingleTransformer; //导入依赖的package包/类
private SingleTransformer<TmpResult, TmpResult> storeToCacheAndReturn() {
    return single -> single
            // собственно, вставка
            .flatMap(result -> this.messagesInteractor
                    .insertMessages(result.getAccountId(), result.collectDtos())
                    .andThen(refreshChangedDialogs(result))
                    .andThen(Single.just(result)))
            .flatMap(result -> {
                // собственно, получение из локальной базы
                List<Integer> ids = collectIds(result.getData(), msg -> true);

                return this.messagesInteractor
                        .findCachedMessages(result.getAccountId(), ids)
                        .map(result::appendModel);
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:17,代码来源:RealtimeMessagesProcessor.java

示例3: dbos2models

import io.reactivex.SingleTransformer; //导入依赖的package包/类
private SingleTransformer<List<PostEntity>, List<Post>> dbos2models(int accountId) {
    return single -> single
            .flatMap(dbos -> {
                final VKOwnIds ids = new VKOwnIds();
                Entity2Model.fillOwnerIds(ids, dbos);

                return ownersInteractor
                        .findBaseOwnersDataAsBundle(accountId, ids.getAll(), IOwnersInteractor.MODE_ANY)
                        .map(owners -> {
                            List<Post> posts = new ArrayList<>(dbos.size());
                            for (PostEntity dbo : dbos) {
                                posts.add(Entity2Model.buildPostFromDbo(dbo, owners));
                            }
                            return posts;
                        });
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:18,代码来源:WallsImpl.java

示例4: toMessageModels

import io.reactivex.SingleTransformer; //导入依赖的package包/类
private SingleTransformer<List<MessageEntity>, List<Message>> toMessageModels(int accountId) {
    return single -> single
            .flatMap(dbos -> {
                VKOwnIds ownIds = new VKOwnIds();
                Entity2Model.fillOwnerIds(ownIds, dbos);

                return this.ownersInteractor
                        .findBaseOwnersDataAsBundle(accountId, ownIds.getAll(), IOwnersInteractor.MODE_ANY)
                        .map(owners -> {
                            final List<Message> messages = new ArrayList<>(dbos.size());

                            for (MessageEntity dbo : dbos) {
                                messages.add(Entity2Model.buildMessageFromDbo(accountId, dbo, owners));
                            }

                            return messages;
                        });
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:20,代码来源:MessagesInteractor.java

示例5: dbos2models

import io.reactivex.SingleTransformer; //导入依赖的package包/类
private SingleTransformer<List<CommentEntity>, List<Comment>> dbos2models(int accountId) {
    return single -> single.flatMap(dbos -> {
        VKOwnIds ownids = new VKOwnIds();
        for (CommentEntity c : dbos) {
            Entity2Model.fillCommentOwnerIds(ownids, c);
        }

        return ownersInteractor
                .findBaseOwnersDataAsBundle(accountId, ownids.getAll(), IOwnersInteractor.MODE_ANY)
                .map(owners -> {
                    List<Comment> comments = new ArrayList<>(dbos.size());
                    for (CommentEntity dbo : dbos) {
                        comments.add(Entity2Model.buildCommentFromDbo(dbo, owners));
                    }
                    return comments;
                });
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:19,代码来源:CommentsInteractor.java

示例6: composeSingle

import io.reactivex.SingleTransformer; //导入依赖的package包/类
public <R> SingleTransformer<? super R, ? extends R> composeSingle() {
    return new SingleTransformer<R, R>() {
        @Override
        public SingleSource<R> apply(@NonNull Single<R> upstream) {
            return upstream
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .retryWhen(new RetryWithDelay(maxRetry, todoBeforeRetry).forSingle)
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            AbstractPresenter.this.addDisposable(disposable);
                        }
                    });
        }
    };
}
 
开发者ID:florent37,项目名称:AndroidMVPresenter,代码行数:18,代码来源:AbstractPresenter.java

示例7: forSingle

import io.reactivex.SingleTransformer; //导入依赖的package包/类
public static <R extends Result> SingleTransformer<R, R> forSingle() {
    return upstream -> upstream.onErrorResumeNext(throwable -> {
        if(throwable instanceof StatusException) {
            StatusException statusException = (StatusException) throwable;

            if(statusException.getStatus().hasResolution()) {
                return Single.just((R) statusException.getResult());
            } else {
                return Single.error(throwable);
            }

        } else {
            return Single.error(throwable);
        }
    });
}
 
开发者ID:florent37,项目名称:RxGps,代码行数:17,代码来源:StatusExceptionResumeNextTransformer.java

示例8: filterByFilterText

import io.reactivex.SingleTransformer; //导入依赖的package包/类
/**
 * Filters the given list against whether their Title or Subtitle matches the filter text.
 *
 * @return Filtered list.
 */
public SingleTransformer<List<? extends RecyclerViewModel>, List<? extends RecyclerViewModel>> filterByFilterText()
{
    return untransformed ->
            (Single) untransformed.flattenAsObservable(items -> items)
                    .filter(item ->
                            item.getSubtitle().toLowerCase().contains(filterText) || item.getTitle().toLowerCase().contains(filterText))
                    .toList();
}
 
开发者ID:jbmlaird,项目名称:DiscogsBrowser,代码行数:14,代码来源:FilterHelper.java

示例9: filterForSale

import io.reactivex.SingleTransformer; //导入依赖的package包/类
/**
 * Filters the list to items that are listed as For Sale.
 *
 * @return Filtered list.
 */
public SingleTransformer<List<Listing>, List<Listing>> filterForSale()
{
    return listingsSingle ->
            listingsSingle.flattenAsObservable(listings -> listings)
                    .filter(listing ->
                            listing.getStatus().equals("For Sale"))
                    .toList();
}
 
开发者ID:jbmlaird,项目名称:DiscogsBrowser,代码行数:14,代码来源:FilterHelper.java

示例10: provideSchedulerSingleTransformer

import io.reactivex.SingleTransformer; //导入依赖的package包/类
@Provides
SchedulerSingleTransformer provideSchedulerSingleTransformer() {
  return new SchedulerSingleTransformer() {
    @SuppressWarnings("unchecked")
    @Override public <T> SingleTransformer<T, T> transformer() {
      return upstream -> upstream.subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread());
    }
  };
}
 
开发者ID:dbof10,项目名称:redux-observable,代码行数:11,代码来源:AppModule.java

示例11: transformer

import io.reactivex.SingleTransformer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override public <T> SingleTransformer<T, T> transformer() {
  return (SingleTransformer<T, T>) new SingleTransformer() {
    @Override public SingleSource apply(Single upstream) {
      return upstream.subscribeOn(Schedulers.trampoline())
          .observeOn(Schedulers.trampoline());
    }
  };
}
 
开发者ID:dbof10,项目名称:redux-observable,代码行数:10,代码来源:SchedulerSingleTransformer.java

示例12: getAndStore

import io.reactivex.SingleTransformer; //导入依赖的package包/类
private SingleTransformer<TmpResult, TmpResult> getAndStore() {
    return single -> single
            .flatMap(result -> {
                // если в исходных данных недостаточно инфы - получаем нужные данные с api
                List<Integer> needGetFromNet = collectIds(result.getData(), msg -> isNull(msg.getDto()));
                if (needGetFromNet.isEmpty()) {
                    return Single.just(result);
                }

                return networker.vkDefault(result.getAccountId())
                        .messages()
                        .getById(needGetFromNet)
                        .map(result::appendDtos);
            })
            .map(result -> {
                // отсеиваем сообщения, которые имеют отношение к обмену ключами
                removeIf(result.getData(), msg -> KeyExchangeService.intercept(app, result.getAccountId(), msg.getDto()));
                return result;
            })
            .flatMap(result -> {
                if (result.getData().isEmpty()) {
                    return Single.just(result);
                }

                // идентифицируем доолнительные необходимые данные, которых не хватает в локальной базе
                // например, информация о пользователях, группах или чатах
                // получаем и сохраняем, если необходимо
                return identifyMissingObjectsGetAndStore(result)
                        .andThen(Single.just(result))
                        // сохраняем сообщения в локальную базу и получаем оттуда "тяжелые" обьекты сообщений
                        .compose(storeToCacheAndReturn());
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:34,代码来源:RealtimeMessagesProcessor.java

示例13: dbo2model

import io.reactivex.SingleTransformer; //导入依赖的package包/类
private SingleTransformer<PostEntity, Post> dbo2model(int accountId) {
    return single -> single
            .flatMap(dbo -> {
                final VKOwnIds ids = new VKOwnIds();
                Entity2Model.fillPostOwnerIds(ids, dbo);

                return ownersInteractor
                        .findBaseOwnersDataAsBundle(accountId, ids.getAll(), IOwnersInteractor.MODE_ANY)
                        .map(owners -> {
                            return Entity2Model.buildPostFromDbo(dbo, owners);
                        });
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:14,代码来源:WallsImpl.java

示例14: applyCommonSchedulersSingle

import io.reactivex.SingleTransformer; //导入依赖的package包/类
public  static <T> SingleTransformer<T, T> applyCommonSchedulersSingle() {
    return new SingleTransformer<T, T>() {
        @Override
        public SingleSource<T> apply(@NonNull Single<T> upstream) {
            return upstream.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread());
        }
    };
}
 
开发者ID:anad7,项目名称:CleanArchitecture,代码行数:10,代码来源:RxUtils.java

示例15: retry

import io.reactivex.SingleTransformer; //导入依赖的package包/类
private <T> SingleTransformer<T, T> retry() {
    return new SingleTransformer<T, T>() {
        @Override
        public SingleSource<T> apply(Single<T> upstream) {
            return upstream.retryWhen(new Function<Flowable<Throwable>, Publisher<Object>>() {

                private final int MAX_COUNT = 3;
                private int count = 0;

                private final int DELAY_SECOND = 10;

                @Override
                public Publisher<Object> apply(Flowable<Throwable> throwableFlowable) throws Exception {
                    return throwableFlowable.flatMap(new Function<Throwable, Publisher<?>>() {
                        @Override
                        public Publisher<?> apply(Throwable throwable) throws Exception {
                            if (count++ < MAX_COUNT && throwable instanceof HttpException) {
                                final HttpException httpException = (HttpException) throwable;
                                if (httpException.code() == 403) {
                                    return Flowable.timer(DELAY_SECOND, TimeUnit.SECONDS);
                                }
                            }
                            return Flowable.error(throwable);
                        }
                    });
                }
            });
        }
    };
}
 
开发者ID:florent37,项目名称:Android-Allocine-Api,代码行数:31,代码来源:AllocineApi.java


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