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


Java Single.flatMap方法代码示例

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


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

示例1: like

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Integer> like(int accountId, int ownerId, int photoId, boolean add, String accessKey) {
    Single<Integer> single;

    if(add){
        single = networker.vkDefault(accountId)
                .likes()
                .add("photo", ownerId, photoId, accessKey);
    } else {
        single = networker.vkDefault(accountId)
                .likes()
                .delete("photo", ownerId, photoId);
    }

    return single.flatMap(count -> {
        final PhotoPatch patch = new PhotoPatch().setLike(new PhotoPatch.Like(count, add));
        return cache.photos()
                .applyPatch(accountId, ownerId, photoId, patch)
                .andThen(Single.just(count));
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:22,代码来源:PhotosInteractor.java

示例2: like

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Integer> like(int accountId, int ownerId, int postId, boolean add) {
    Single<Integer> single;
    if (add) {
        single = networker.vkDefault(accountId)
                .likes()
                .add("post", ownerId, postId, null);
    } else {
        single = networker.vkDefault(accountId)
                .likes()
                .delete("post", ownerId, postId);
    }

    return single.flatMap(count -> {
        // TODO: 05.09.2017 Сохранение лайков в таблице новостей надо ?
        final PostUpdate update = new PostUpdate(accountId, postId, ownerId).withLikes(count, add);
        return applyPatch(update).andThen(Single.just(count));
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:20,代码来源:WallsImpl.java

示例3: storeInDatabase

import io.reactivex.Single; //导入方法依赖的package包/类
private void storeInDatabase(JsonObject operation) {
    // 1. need to retrieve a connection
    // 2. execute the insertion statement
    // 3. close the connection


    // Step 1 get the connection
    Single<SQLConnection> connectionRetrieved = jdbc.rxGetConnection();

    // Step 2, when the connection is retrieved (this may have failed), do the insertion (upon success)
    Single<UpdateResult> update = connectionRetrieved
        .flatMap(connection ->
            connection.rxUpdateWithParams(INSERT_STATEMENT, new JsonArray().add(operation.encode()))

                // Step 3, when the insertion is done, close the connection.
                .doAfterTerminate(connection::close));

    update.subscribe(result -> {
        // Ok
    }, err -> {
        System.err.println("Failed to insert operation in database: " + err);
    });
}
 
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:24,代码来源:AuditVerticle.java

示例4: apply

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Wallet> apply(Single<Wallet> upstream) {
    return upstream.flatMap(wallet ->
            passwordStore
            .setPassword(wallet, password)
            .onErrorResumeNext(err -> walletRepository
                    .deleteWallet(wallet.address, password)
                    .lift(completableErrorProxy(err)))
            .toSingle(() -> wallet));
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:11,代码来源:SavePasswordOperator.java

示例5: send

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Comment> send(int accountId, Commented commented, final CommentIntent intent) {
    final Single<List<IAttachmentToken>> cachedAttachments;

    if (nonNull(intent.getDraftMessageId())) {
        cachedAttachments = getCachedAttachmentsToken(accountId, intent.getDraftMessageId());
    } else {
        cachedAttachments = Single.just(emptyList());
    }

    return cachedAttachments
            .flatMap(cachedTokens -> {
                final List<IAttachmentToken> tokens = new ArrayList<>();

                if (nonNull(cachedTokens)) {
                    tokens.addAll(cachedTokens);
                }

                if (nonEmpty(intent.getModels())) {
                    tokens.addAll(Model2Dto.createTokens(intent.getModels()));
                }

                return sendComment(accountId, commented, intent, tokens)
                        .flatMap(id -> getCommentByIdAndStore(accountId, commented, id, true))
                        .flatMap(comment -> {
                            if (isNull(intent.getDraftMessageId())) {
                                return Single.just(comment);
                            }

                            return cache.comments()
                                    .deleteByDbid(accountId, intent.getDraftMessageId())
                                    .andThen(Single.just(comment));
                        });
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:36,代码来源:CommentsInteractor.java

示例6: edit

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Comment> edit(int accountId, Commented commented, int commentId, String body, List<AbsModel> attachments) {
    List<IAttachmentToken> tokens = new ArrayList<>();

    try {
        if (nonNull(attachments)) {
            tokens.addAll(Model2Dto.createTokens(attachments));
        }
    } catch (Exception e) {
        return Single.error(e);
    }

    Single<Boolean> editSingle;

    switch (commented.getSourceType()) {
        case CommentedType.POST:
            editSingle = networker
                    .vkDefault(accountId)
                    .wall()
                    .editComment(commented.getSourceOwnerId(), commentId, body, tokens);
            break;

        case CommentedType.PHOTO:
            editSingle = networker
                    .vkDefault(accountId)
                    .photos()
                    .editComment(commented.getSourceOwnerId(), commentId, body, tokens);
            break;

        case CommentedType.TOPIC:
            int groupId = Math.abs(commented.getSourceOwnerId());
            int topicId = commented.getSourceId();

            editSingle = networker
                    .vkDefault(accountId)
                    .board()
                    .editComment(groupId, topicId, commentId, body, tokens);
            break;

        case CommentedType.VIDEO:
            editSingle = networker
                    .vkDefault(accountId)
                    .video()
                    .editComment(commented.getSourceOwnerId(), commentId, body, tokens);
            break;

        default:
            return Single.error(new IllegalArgumentException("Unknown commented source type"));
    }

    return editSingle.flatMap(ignored -> getCommentByIdAndStore(accountId, commented, commentId, true));
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:53,代码来源:CommentsInteractor.java


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