本文整理了Java中io.vavr.control.Try.onSuccess()
方法的一些代码示例,展示了Try.onSuccess()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Try.onSuccess()
方法的具体详情如下:
包路径:io.vavr.control.Try
类名称:Try
方法名:onSuccess
[英]Consumes the value if this is a Try.Success.
// prints "1"
[中]如果这是一次尝试,则消耗该值。成功
// prints "1"
代码示例来源:origin: vavr-io/vavr
/**
* Performs the action once the Future is complete and the result is a {@link Try.Success}.
*
* @param action An action to be performed when this future succeeded.
* @return this Future
* @throws NullPointerException if {@code action} is null.
*/
default Future<T> onSuccess(Consumer<? super T> action) {
Objects.requireNonNull(action, "action is null");
return onComplete(result -> result.onSuccess(action));
}
代码示例来源:origin: vavr-io/vavr
/**
* Converts this to a {@link CompletableFuture}
*
* @return A new {@link CompletableFuture} containing the value
*/
@GwtIncompatible
default CompletableFuture<T> toCompletableFuture() {
final CompletableFuture<T> completableFuture = new CompletableFuture<>();
Try.of(this::get)
.onSuccess(completableFuture::complete)
.onFailure(completableFuture::completeExceptionally);
return completableFuture;
}
代码示例来源:origin: vavr-io/vavr
default <U> Future<U> flatMapTry(CheckedFunction1<? super T, ? extends Future<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
return run(executor(), complete ->
onComplete(result -> result.mapTry(mapper)
.onSuccess(future -> future.onComplete(complete::with))
.onFailure(x -> complete.with(Try.failure(x)))
)
);
}
代码示例来源:origin: vavr-io/vavr
.onSuccess(value -> completed.set(complete.with(Try.success(Option.some(value)))))
.onFailure(ignored -> {
if (wasLast) {
代码示例来源:origin: io.vavr/vavr
/**
* Performs the action once the Future is complete and the result is a {@link Try.Success}.
*
* @param action An action to be performed when this future succeeded.
* @return this Future
* @throws NullPointerException if {@code action} is null.
*/
default Future<T> onSuccess(Consumer<? super T> action) {
Objects.requireNonNull(action, "action is null");
return onComplete(result -> result.onSuccess(action));
}
代码示例来源:origin: io.vavr/vavr
/**
* Converts this to a {@link CompletableFuture}
*
* @return A new {@link CompletableFuture} containing the value
*/
@GwtIncompatible
default CompletableFuture<T> toCompletableFuture() {
final CompletableFuture<T> completableFuture = new CompletableFuture<>();
Try.of(this::get)
.onSuccess(completableFuture::complete)
.onFailure(completableFuture::completeExceptionally);
return completableFuture;
}
代码示例来源:origin: Tristan971/Lyrebird
@Override
public void refresh() {
if (!sessionManager.isLoggedInProperty().getValue()) {
LOG.debug("Logged out, not refreshing direct messages.");
return;
}
CompletableFuture.runAsync(() -> {
LOG.debug("Requesting last direct messages.");
sessionManager.getCurrentTwitter()
.mapTry(twitter -> twitter.getDirectMessages(20))
.onSuccess(this::addDirectMessages)
.onFailure(err -> LOG.error("Could not load direct messages successfully!", err));
});
}
代码示例来源:origin: Tristan971/Lyrebird
public void openUserDetails(final long targetUserId) {
findUser(targetUserId)
.onSuccess(this::openUserDetails)
.onFailure(err -> ExceptionHandler.displayExceptionPane(
"Unknown user!",
"Can't map this user's userId to an actual Twitter user!",
err
));
}
代码示例来源:origin: Tristan971/Lyrebird
public void openUserDetails(final String screenName) {
findUser(screenName)
.onSuccess(this::openUserDetails)
.onFailure(err -> ExceptionHandler.displayExceptionPane(
"Unknown user!",
"Can't map this user's screen name (@...) to an actual Twitter user!",
err
));
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Called when the user requests the displaying of the current user's detailed view.
*
* @see Screen#USER_VIEW
*/
private void loadDetailsForCurrentUser() {
sessionManager.currentSessionProperty()
.getValue()
.getTwitterUser()
.onSuccess(userDetailsService::openUserDetails);
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Fetches, shows and moves the main application stage to the front.
*/
private void showMainStage() {
CompletableFuture.runAsync(
() -> stageManager.getSingle(Screen.ROOT_VIEW)
.toTry(IllegalStateException::new)
.onSuccess(stage -> {
stage.show();
stage.setIconified(false);
}).onFailure(err -> LOG.error("Could not show main stage!", err)),
Platform::runLater
);
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Asynchronously loads the last tweets available
*/
public void refresh() {
CompletableFuture.runAsync(() -> {
if (sessionManager.getCurrentTwitter().getOrElse((Twitter) null) == null) {
return;
}
getLocalLogger().debug("Requesting last tweets in timeline.");
sessionManager.getCurrentTwitter()
.mapTry(this::initialLoad)
.onSuccess(this::addTweets)
.onFailure(err -> getLocalLogger().error("Could not refresh!", err))
.andThen(() -> isFirstCall.set(false));
});
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Asynchronous load and set of the user profile picture.
*
* @param user The user with which to work, mostly because we do not keep a reference to it inside this class.
*/
private void loadAndSetUserAvatar(final Try<User> user) {
user.map(User::getOriginalProfileImageURLHttps)
.map(imageUrl -> asyncIO.loadImageMiniature(imageUrl, 128.0, 128.0))
.onSuccess(loadRequest -> loadRequest.thenAcceptAsync(userProfilePicture::setImage, Platform::runLater));
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Loads the current user's account view on the top of the bar.
*/
private void loadCurrentAccountPanel() {
easyFxml.loadNode(CURRENT_ACCOUNT)
.getNode()
.onSuccess(container::setTop)
.onFailure(err -> displayExceptionPane(
"Could not load current user!",
"There was an error mapping the current session to a twitter account.",
err
));
}
代码示例来源:origin: Tristan971/Lyrebird
private void createTabForPal(final User user) {
if (loadedPals.contains(user)) return;
LOG.debug("Creating a conversation tab for conversation with {}", user.getScreenName());
easyFxml.loadNode(DIRECT_MESSAGE_CONVERSATION, Pane.class, DMConversationController.class)
.afterControllerLoaded(dmc -> dmc.setPal(user))
.getNode()
.recover(ExceptionHandler::fromThrowable)
.map(conversation -> new Tab(user.getName(), conversation))
.onSuccess(tab -> Platform.runLater(() -> {
LOG.debug("Adding [{}] as tab for user {}", tab.getText(), user.getScreenName());
this.conversationsManaged.add(tab);
}));
loadedPals.add(user);
}
代码示例来源:origin: io.vavr/vavr
default <U> Future<U> flatMapTry(CheckedFunction1<? super T, ? extends Future<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
return run(executor(), complete ->
onComplete(result -> result.mapTry(mapper)
.onSuccess(future -> future.onComplete(complete::with))
.onFailure(x -> complete.with(Try.failure(x)))
)
);
}
代码示例来源:origin: Tristan971/Lyrebird
private void displayApplicationAuthor() {
applicationAuthorProfileLink.setOnAction(e -> userDetailsService.openUserDetails("_tristan971_"));
userDetailsService.findUser("_tristan971_")
.map(User::getProfileImageURLHttps)
.map(cachedMedia::loadImage)
.onSuccess(applicationAuthorProfilePicture::setImage)
.andThen(() -> applicationAuthorProfilePicture.setClip(Clipping.getCircleClip(16.0)));
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Loads the target user's timeline into the view.
*/
private void loadTargetUserTimeline() {
final User user = targetUserProp.getValue();
easyFxml.loadNode(FxComponent.USER_TIMELINE, Pane.class, UserTimelineController.class)
.afterControllerLoaded(utc -> utc.setTargetUser(user))
.afterNodeLoaded(userDetailsTimeline -> VBox.setVgrow(userDetailsTimeline, Priority.ALWAYS))
.getNode()
.recover(ExceptionHandler::fromThrowable)
.onSuccess(container.getChildren()::add);
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Opens the detailed view of a given user.
*
* @param targetUser the user whose detailed view is requested to be shown
*/
public void openUserDetails(final User targetUser) {
LOG.info("Opening detailed view of user : {} (@{})", targetUser.getName(), targetUser.getScreenName());
easyFxml.loadNode(Screen.USER_VIEW, Pane.class, UserViewController.class)
.afterControllerLoaded(uvc -> uvc.targetUserProperty().setValue(targetUser))
.getNode()
.recover(ExceptionHandler::fromThrowable)
.onSuccess(userDetailsPane -> {
final String stageTitle = targetUser.getName() + " (@" + targetUser.getScreenName() + ")";
Stages.stageOf(stageTitle, userDetailsPane).thenAcceptAsync(Stages::scheduleDisplaying);
});
}
代码示例来源:origin: Tristan971/Lyrebird
private void setUpInteractionButtons() {
interactionBox.visibleProperty().bind(embeddedProperty.not());
interactionBox.managedProperty().bind(embeddedProperty.not());
easyFxml.loadNode(TWEET_INTERACTION_BOX, Pane.class, TweetInteractionPaneController.class)
.afterControllerLoaded(tipc -> tipc.targetStatusProperty().bind(currentStatus))
.getNode()
.recover(ExceptionHandler::fromThrowable)
.onSuccess(interactionBox::setCenter);
}
内容来源于网络,如有侵权,请联系作者删除!