本文整理汇总了Java中java.util.stream.IntStream.of方法的典型用法代码示例。如果您正苦于以下问题:Java IntStream.of方法的具体用法?Java IntStream.of怎么用?Java IntStream.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.stream.IntStream
的用法示例。
在下文中一共展示了IntStream.of方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: arrayToStream
import java.util.stream.IntStream; //导入方法依赖的package包/类
public static Object arrayToStream(final Object array) {
if (array instanceof int[]) {
return IntStream.of((int[])array);
} else if (array instanceof long[]) {
return LongStream.of((long[])array);
} else if (array instanceof double[]) {
return DoubleStream.of((double[])array);
} else if (array instanceof Object[]) {
return Stream.of((Object[])array);
} else {
throw new IllegalArgumentException();
}
}
示例3: intProvider
import java.util.stream.IntStream; //导入方法依赖的package包/类
static IntStream intProvider() {
return IntStream.of(0, 1);
}
示例4: stream
import java.util.stream.IntStream; //导入方法依赖的package包/类
@NonNull
@Override
default IntStream stream() {
return IntStream.of(this.x(), this.y(), this.z());
}
示例5: stream
import java.util.stream.IntStream; //导入方法依赖的package包/类
@NonNull
@Override
default IntStream stream() {
return IntStream.of(this.x(), this.y());
}
示例6: stream
import java.util.stream.IntStream; //导入方法依赖的package包/类
@NonNull
@Override
default IntStream stream() {
return IntStream.of(this.x(), this.y(), this.z(), this.w());
}
示例7: 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();
}
}
示例8: 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();
}