本文整理匯總了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();
}