本文整理汇总了Java中java.util.stream.IntStream.empty方法的典型用法代码示例。如果您正苦于以下问题:Java IntStream.empty方法的具体用法?Java IntStream.empty怎么用?Java IntStream.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.stream.IntStream
的用法示例。
在下文中一共展示了IntStream.empty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: produceCases
import java.util.stream.IntStream; //导入方法依赖的package包/类
@DataProvider(name = "cases")
public static Object[][] produceCases() {
return new Object[][] {
{ "none", IntStream.empty() },
{ "index 0", IntStream.of(0) },
{ "index 255", IntStream.of(255) },
{ "index 0 and 255", IntStream.of(0, 255) },
{ "index Integer.MAX_VALUE", IntStream.of(Integer.MAX_VALUE) },
{ "index Integer.MAX_VALUE - 1", IntStream.of(Integer.MAX_VALUE - 1) },
{ "index 0 and Integer.MAX_VALUE", IntStream.of(0, Integer.MAX_VALUE) },
{ "every bit", IntStream.range(0, 255) },
{ "step 2", IntStream.range(0, 255).map(f -> f * 2) },
{ "step 3", IntStream.range(0, 255).map(f -> f * 3) },
{ "step 5", IntStream.range(0, 255).map(f -> f * 5) },
{ "step 7", IntStream.range(0, 255).map(f -> f * 7) },
{ "1, 10, 100, 1000", IntStream.of(1, 10, 100, 1000) },
{ "25 fibs", IntStream.generate(new Fibs()).limit(25) }
};
}
示例2: stream
import java.util.stream.IntStream; //导入方法依赖的package包/类
/**
* If a value is present, returns a sequential {@link IntStream} containing
* only that value, otherwise returns an empty {@code IntStream}.
*
* @apiNote
* This method can be used to transform a {@code Stream} of optional
* integers to an {@code IntStream} of present integers:
* <pre>{@code
* Stream<OptionalInt> os = ..
* IntStream s = os.flatMapToInt(OptionalInt::stream)
* }</pre>
*
* @return the optional value as an {@code IntStream}
* @since 9
*/
public IntStream stream() {
if (isPresent) {
return IntStream.of(value);
} else {
return IntStream.empty();
}
}
示例3: stream
import java.util.stream.IntStream; //导入方法依赖的package包/类
/**
* If a value is present in {@code optional}, returns a stream containing only that element,
* otherwise returns an empty stream.
*
* <p><b>Java 9 users:</b> use {@code optional.stream()} instead.
*/
public static IntStream stream(OptionalInt optional) {
return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty();
}