/** * If a value is present, returns a sequential {@link IntStream} containing * only that value, otherwise returns an empty {@code IntStream}. * * <p><b>API Note:</b><br> * 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 IntStreams.of(value); } else { return IntStreams.empty(); } }
/** * If a value is present, returns a sequential {@link IntStream} containing * only that value, otherwise returns an empty {@code IntStream}. * * <p><b>API Note:</b><br> * 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 IntStreams.of(value); } else { return IntStreams.empty(); } }
/** * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endExclusive} (exclusive) by an incremental step of * {@code 1}. * * <p><b>API Note:</b><br> * <p>An equivalent sequence of increasing values can be produced * sequentially using a {@code for} loop as follows: * <pre>{@code * for (int i = startInclusive; i < endExclusive ; i++) { ... } * }</pre> * * @param startInclusive the (inclusive) initial value * @param endExclusive the exclusive upper bound * @return a sequential {@code IntStream} for the range of {@code int} * elements */ public static IntStream range(int startInclusive, int endExclusive) { if (startInclusive >= endExclusive) { return empty(); } else { return StreamSupport.intStream( new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false); } }
/** * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endExclusive} (exclusive) by an incremental step of * {@code 1}. * * <p><b>API Note:</b><br> * <p>An equivalent sequence of increasing values can be produced * sequentially using a {@code for} loop as follows: * <pre>{@code * for (int i = startInclusive; i < endExclusive ; i++) { ... } * }</pre> * * @param startInclusive the (inclusive) initial value * @param endExclusive the exclusive upper bound * @return a sequential {@code IntStream} for the range of {@code int} * elements */ public static IntStream range(int startInclusive, int endExclusive) { if (startInclusive >= endExclusive) { return empty(); } else { return StreamSupport.intStream( new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false); } }
/** * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endInclusive} (inclusive) by an incremental step of * {@code 1}. * * <p><b>API Note:</b><br> * <p>An equivalent sequence of increasing values can be produced * sequentially using a {@code for} loop as follows: * <pre>{@code * for (int i = startInclusive; i <= endInclusive ; i++) { ... } * }</pre> * * @param startInclusive the (inclusive) initial value * @param endInclusive the inclusive upper bound * @return a sequential {@code IntStream} for the range of {@code int} * elements */ public static IntStream rangeClosed(int startInclusive, int endInclusive) { if (startInclusive > endInclusive) { return empty(); } else { return StreamSupport.intStream( new Streams.RangeIntSpliterator(startInclusive, endInclusive, true), false); } }
/** * Returns a sequential ordered {@code IntStream} from {@code startInclusive} * (inclusive) to {@code endInclusive} (inclusive) by an incremental step of * {@code 1}. * * <p><b>API Note:</b><br> * <p>An equivalent sequence of increasing values can be produced * sequentially using a {@code for} loop as follows: * <pre>{@code * for (int i = startInclusive; i <= endInclusive ; i++) { ... } * }</pre> * * @param startInclusive the (inclusive) initial value * @param endInclusive the inclusive upper bound * @return a sequential {@code IntStream} for the range of {@code int} * elements */ public static IntStream rangeClosed(int startInclusive, int endInclusive) { if (startInclusive > endInclusive) { return empty(); } else { return StreamSupport.intStream( new Streams.RangeIntSpliterator(startInclusive, endInclusive, true), false); } }