@Override public IntStream build() { int c = count; if (c >= 0) { // Switch count to negative value signalling the builder is built count = -count - 1; // Use this spliterator if 0 or 1 elements, otherwise use // the spliterator of the spined buffer return (c < 2) ? StreamSupport.intStream(this, false) : StreamSupport.intStream(buffer.spliterator(), false); } throw new IllegalStateException(); }
@Override public IntStream build() { int c = count; if (c >= 0) { // Switch count to negative value signalling the builder is built count = -count - 1; // Use this spliterator if 0 or 1 elements, otherwise use // the spliterator of the spined buffer return (c < 2) ? StreamSupport.intStream(this, false) : StreamSupport.intStream(buffer.spliterator(), false); } throw new IllegalStateException(); }
/** * Returns an empty sequential {@code IntStream}. * * @return an empty sequential stream */ public static IntStream empty() { return StreamSupport.intStream(Spliterators.emptyIntSpliterator(), false); }
/** * Returns a sequential {@code IntStream} containing a single element. * * @param t the single element * @return a singleton sequential stream */ public static IntStream of(int t) { return StreamSupport.intStream(new Streams.IntStreamBuilderImpl(t), false); }
/** * Returns an empty sequential {@code IntStream}. * * @return an empty sequential stream */ public static IntStream empty() { return StreamSupport.intStream(Spliterators.emptyIntSpliterator(), false); }
/** * Returns a sequential {@code IntStream} containing a single element. * * @param t the single element * @return a singleton sequential stream */ public static IntStream of(int t) { return StreamSupport.intStream(new Streams.IntStreamBuilderImpl(t), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values from this generator and/or one split from it. * * <p><b>Implementation Note:</b><br> This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code int} values */ public IntStream ints() { return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values from this generator and/or one split from it. * * <p><b>Implementation Note:</b><br> This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code int} values */ public IntStream ints() { return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values. * * <p><b>Implementation Note:</b><br> * This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code int} values * @since 1.8 */ public IntStream ints() { return StreamSupport.intStream (new RandomIntsSpliterator (0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0), false); }
/** * Returns a stream producing the given {@code streamSize} number * of pseudorandom {@code int} values from this generator and/or * one split from it. * * @param streamSize the number of values to generate * @return a stream of pseudorandom {@code int} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero */ public IntStream ints(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BAD_SIZE); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, streamSize, Integer.MAX_VALUE, 0), false); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code int} values. * * @param streamSize the number of values to generate * @return a stream of pseudorandom {@code int} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero * @since 1.8 */ public IntStream ints(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BAD_SIZE); return StreamSupport.intStream (new RandomIntsSpliterator (0L, streamSize, Integer.MAX_VALUE, 0), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code int} * values. * * <p><b>Implementation Note:</b><br> * This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code int} values * @since 1.8 */ public IntStream ints() { return StreamSupport.intStream (new RandomIntsSpliterator (0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0), false); }
/** * Returns a sequential {@link IntStream} with the specified range of the * specified array as its source. * * @param array the array, assumed to be unmodified during use * @param startInclusive the first index to cover, inclusive * @param endExclusive index immediately past the last index to cover * @return an {@code IntStream} for the array range * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is * negative, {@code endExclusive} is less than * {@code startInclusive}, or {@code endExclusive} is greater than * the array size * @since 1.8 */ public static IntStream stream(int[] array, int startInclusive, int endExclusive) { return StreamSupport.intStream(spliterator(array, startInclusive, endExclusive), false); }
/** * Returns a sequential {@link IntStream} with the specified range of the * specified array as its source. * * @param array the array, assumed to be unmodified during use * @param startInclusive the first index to cover, inclusive * @param endExclusive index immediately past the last index to cover * @return an {@code IntStream} for the array range * @throws ArrayIndexOutOfBoundsException if {@code startInclusive} is * negative, {@code endExclusive} is less than * {@code startInclusive}, or {@code endExclusive} is greater than * the array size * @since 1.8 */ public static IntStream stream(int[] array, int startInclusive, int endExclusive) { return StreamSupport.intStream(spliterator(array, startInclusive, endExclusive), false); }
/** * Returns a stream producing the given {@code streamSize} number * of pseudorandom {@code int} values from this generator and/or * one split from it. * * @param streamSize the number of values to generate * @return a stream of pseudorandom {@code int} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero */ public IntStream ints(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BAD_SIZE); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, streamSize, Integer.MAX_VALUE, 0), false); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code int} values. * * @param streamSize the number of values to generate * @return a stream of pseudorandom {@code int} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero * @since 1.8 */ public IntStream ints(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BAD_SIZE); return StreamSupport.intStream (new RandomIntsSpliterator (0L, streamSize, Integer.MAX_VALUE, 0), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code * int} values from this generator and/or one split from it; each value * conforms to the given origin (inclusive) and bound (exclusive). * * <p><b>Implementation Note:</b><br> This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. * * @param randomNumberOrigin the origin (inclusive) of each random value * @param randomNumberBound the bound (exclusive) of each random value * @return a stream of pseudorandom {@code int} values, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} */ public IntStream ints(int randomNumberOrigin, int randomNumberBound) { if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BAD_RANGE); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code * int} values from this generator and/or one split from it; each value * conforms to the given origin (inclusive) and bound (exclusive). * * <p><b>Implementation Note:</b><br> This method is implemented to be equivalent to {@code * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. * * @param randomNumberOrigin the origin (inclusive) of each random value * @param randomNumberBound the bound (exclusive) of each random value * @return a stream of pseudorandom {@code int} values, * each with the given origin (inclusive) and bound (exclusive) * @throws IllegalArgumentException if {@code randomNumberOrigin} * is greater than or equal to {@code randomNumberBound} */ public IntStream ints(int randomNumberOrigin, int randomNumberBound) { if (randomNumberOrigin >= randomNumberBound) throw new IllegalArgumentException(BAD_RANGE); return StreamSupport.intStream (new RandomIntsSpliterator (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), false); }
/** * Returns an infinite sequential unordered stream where each element is * generated by the provided {@code IntSupplier}. This is suitable for * generating constant streams, streams of random elements, etc. * * @param s the {@code IntSupplier} for generated elements * @return a new infinite sequential unordered {@code IntStream} */ public static IntStream generate(IntSupplier s) { Objects.requireNonNull(s); return StreamSupport.intStream( new StreamSpliterators.InfiniteSupplyingSpliterator.OfInt(Long.MAX_VALUE, s), false); }
/** * Returns an infinite sequential unordered stream where each element is * generated by the provided {@code IntSupplier}. This is suitable for * generating constant streams, streams of random elements, etc. * * @param s the {@code IntSupplier} for generated elements * @return a new infinite sequential unordered {@code IntStream} */ public static IntStream generate(IntSupplier s) { Objects.requireNonNull(s); return StreamSupport.intStream( new StreamSpliterators.InfiniteSupplyingSpliterator.OfInt(Long.MAX_VALUE, s), false); }