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