本文整理了Java中com.annimon.stream.Optional.filter()
方法的一些代码示例,展示了Optional.filter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.filter()
方法的具体详情如下:
包路径:com.annimon.stream.Optional
类名称:Optional
方法名:filter
[英]Performs filtering on inner value if it is present.
[中]对内部值(如果存在)执行过滤。
代码示例来源:origin: aNNiMON/Lightweight-Stream-API
/**
* Performs negated filtering on inner value if it is present.
*
* @param predicate a predicate function
* @return this {@code Optional} if the value is present and doesn't matches predicate,
* otherwise an empty {@code Optional}
* @since 1.1.9
*/
public Optional<T> filterNot(Predicate<? super T> predicate) {
return filter(Predicate.Util.negate(predicate));
}
代码示例来源:origin: aNNiMON/Lightweight-Stream-API
@Override
public Optional<Integer> apply(Optional<Integer> optional) {
return optional.filter(Functions.remainder(2));
}
});
代码示例来源:origin: aNNiMON/Lightweight-Stream-API
@Test
public void testFilter() {
Optional<Integer> result = Optional.of(10)
.filter(Predicate.Util.negate(Functions.remainder(2)));
assertThat(result, isEmpty());
}
内容来源于网络,如有侵权,请联系作者删除!