本文整理了Java中com.annimon.stream.Optional.executeIfPresent()
方法的一些代码示例,展示了Optional.executeIfPresent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.executeIfPresent()
方法的具体详情如下:
包路径:com.annimon.stream.Optional
类名称:Optional
方法名:executeIfPresent
[英]Invokes consumer function with the value if present. This method same as ifPresent, but does not breaks chaining
[中]调用具有值(如果存在)的使用者函数。此方法与ifPresent相同,但不会打断链接
代码示例来源:origin: aNNiMON/Lightweight-Stream-API
@Test
public void testExecuteIfPresentOnAbsentValue() {
Optional.<Integer>empty()
.executeIfPresent(new Consumer<Integer>() {
@Override
public void accept(Integer value) {
fail();
}
});
}
代码示例来源:origin: aNNiMON/Lightweight-Stream-API
@Test
public void testExecuteIfPresent() {
int value = Optional.of(10)
.executeIfPresent(new Consumer<Integer>() {
@Override
public void accept(Integer value) {
assertEquals(10, (int) value);
}
})
.get();
assertEquals(10, value);
}
代码示例来源:origin: Applandeo/Material-Calendar-View
private void loadIcon(ImageView dayIcon, Calendar day) {
if (mCalendarProperties.getEventDays() == null || !mCalendarProperties.getEventsEnabled()) {
dayIcon.setVisibility(View.GONE);
return;
}
Stream.of(mCalendarProperties.getEventDays()).filter(eventDate ->
eventDate.getCalendar().equals(day)).findFirst().executeIfPresent(eventDay -> {
ImageUtils.loadImage(dayIcon, eventDay.getImageDrawable());
// If a day doesn't belong to current month then image is transparent
if (!isCurrentMonthDay(day) || !isActiveDay(day)) {
dayIcon.setAlpha(0.12f);
}
});
}
}
内容来源于网络,如有侵权,请联系作者删除!