/** * Returns a sequential {@code IntStreamEx} containing an * {@link OptionalInt} value, if present, otherwise returns an empty * {@code IntStreamEx}. * * @param optional the optional to create a stream of * @return a stream with an {@code OptionalInt} value if present, otherwise * an empty stream * @since 0.1.1 */ public static IntStreamEx of(OptionalInt optional) { return optional.isPresent() ? of(optional.getAsInt()) : empty(); }
/** * Returns a sequential ordered {@code IntStreamEx} from * {@code startInclusive} (inclusive) to {@code endExclusive} (exclusive) by * the specified incremental step. The negative step values are also * supported. In this case the {@code startInclusive} should be greater than * {@code endExclusive}. * * @param startInclusive the (inclusive) initial value * @param endExclusive the exclusive upper bound * @param step the non-zero value which designates the difference between * the consecutive values of the resulting stream. * @return a sequential {@code IntStreamEx} for the range of {@code int} * elements * @throws IllegalArgumentException if step is zero * @see IntStreamEx#range(int, int) * @since 0.4.0 */ public static IntStreamEx range(int startInclusive, int endExclusive, int step) { int endInclusive = endExclusive - Integer.signum(step); if (endInclusive > endExclusive && step > 0 || endInclusive < endExclusive && step < 0) return empty(); return rangeClosed(startInclusive, endInclusive, step); }
return empty(); int limit = (endInclusive - startInclusive) * Integer.signum(step); limit = Integer.divideUnsigned(limit, Math.abs(step));