@Override public DoubleStream 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.doubleStream(this, false) : StreamSupport.doubleStream(buffer.spliterator(), false); } throw new IllegalStateException(); }
@Override public DoubleStream 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.doubleStream(this, false) : StreamSupport.doubleStream(buffer.spliterator(), false); } throw new IllegalStateException(); }
/** * Returns a sequential {@code DoubleStream} containing a single element. * * @param t the single element * @return a singleton sequential stream */ public static DoubleStream of(double t) { return StreamSupport.doubleStream(new Streams.DoubleStreamBuilderImpl(t), false); }
/** * Returns an empty sequential {@code DoubleStream}. * * @return an empty sequential stream */ public static DoubleStream empty() { return StreamSupport.doubleStream(Spliterators.emptyDoubleSpliterator(), false); }
/** * Returns an empty sequential {@code DoubleStream}. * * @return an empty sequential stream */ public static DoubleStream empty() { return StreamSupport.doubleStream(Spliterators.emptyDoubleSpliterator(), false); }
/** * Returns a sequential {@code DoubleStream} containing a single element. * * @param t the single element * @return a singleton sequential stream */ public static DoubleStream of(double t) { return StreamSupport.doubleStream(new Streams.DoubleStreamBuilderImpl(t), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code * double} values from this generator and/or one split from it; each value * is between zero (inclusive) and one (exclusive). * * <p><b>Implementation Note:</b><br> This method is implemented to be equivalent to {@code * doubles(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code double} values */ public DoubleStream doubles() { return StreamSupport.doubleStream (new RandomDoublesSpliterator (this, 0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code * double} values from this generator and/or one split from it; each value * is between zero (inclusive) and one (exclusive). * * <p><b>Implementation Note:</b><br> This method is implemented to be equivalent to {@code * doubles(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code double} values */ public DoubleStream doubles() { return StreamSupport.doubleStream (new RandomDoublesSpliterator (this, 0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code * double} values, each between zero (inclusive) and one * (exclusive). * * <p><b>Implementation Note:</b><br> * This method is implemented to be equivalent to {@code * doubles(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code double} values * @since 1.8 */ public DoubleStream doubles() { return StreamSupport.doubleStream (new RandomDoublesSpliterator (0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0), false); }
/** * Returns a sequential {@link DoubleStream} 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 a {@code DoubleStream} 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 DoubleStream stream(double[] array, int startInclusive, int endExclusive) { return StreamSupport.doubleStream(spliterator(array, startInclusive, endExclusive), false); }
/** * Returns a sequential {@link DoubleStream} 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 a {@code DoubleStream} 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 DoubleStream stream(double[] array, int startInclusive, int endExclusive) { return StreamSupport.doubleStream(spliterator(array, startInclusive, endExclusive), false); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code double} values, each between zero * (inclusive) and one (exclusive). * * @param streamSize the number of values to generate * @return a stream of {@code double} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero * @since 1.8 */ public DoubleStream doubles(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BAD_SIZE); return StreamSupport.doubleStream (new RandomDoublesSpliterator (0L, streamSize, Double.MAX_VALUE, 0.0), false); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code double} values, each between zero * (inclusive) and one (exclusive). * * @param streamSize the number of values to generate * @return a stream of {@code double} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero * @since 1.8 */ public DoubleStream doubles(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BAD_SIZE); return StreamSupport.doubleStream (new RandomDoublesSpliterator (0L, streamSize, Double.MAX_VALUE, 0.0), false); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code double} values from this generator and/or one split * from it; each value is between zero (inclusive) and one (exclusive). * * @param streamSize the number of values to generate * @return a stream of {@code double} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero */ public DoubleStream doubles(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BAD_SIZE); return StreamSupport.doubleStream (new RandomDoublesSpliterator (this, 0L, streamSize, Double.MAX_VALUE, 0.0), false); }
/** * Returns a stream producing the given {@code streamSize} number of * pseudorandom {@code double} values from this generator and/or one split * from it; each value is between zero (inclusive) and one (exclusive). * * @param streamSize the number of values to generate * @return a stream of {@code double} values * @throws IllegalArgumentException if {@code streamSize} is * less than zero */ public DoubleStream doubles(long streamSize) { if (streamSize < 0L) throw new IllegalArgumentException(BAD_SIZE); return StreamSupport.doubleStream (new RandomDoublesSpliterator (this, 0L, streamSize, Double.MAX_VALUE, 0.0), false); }
/** * Returns an effectively unlimited stream of pseudorandom {@code * double} values, each between zero (inclusive) and one * (exclusive). * * <p><b>Implementation Note:</b><br> * This method is implemented to be equivalent to {@code * doubles(Long.MAX_VALUE)}. * * @return a stream of pseudorandom {@code double} values * @since 1.8 */ public DoubleStream doubles() { return StreamSupport.doubleStream (new RandomDoublesSpliterator (0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0), false); }
/** * Returns an infinite sequential unordered stream where each element is * generated by the provided {@code DoubleSupplier}. This is suitable for * generating constant streams, streams of random elements, etc. * * @param s the {@code DoubleSupplier} for generated elements * @return a new infinite sequential unordered {@code DoubleStream} */ public static DoubleStream generate(DoubleSupplier s) { Objects.requireNonNull(s); return StreamSupport.doubleStream( new StreamSpliterators.InfiniteSupplyingSpliterator.OfDouble(Long.MAX_VALUE, s), false); }
/** * Returns an infinite sequential unordered stream where each element is * generated by the provided {@code DoubleSupplier}. This is suitable for * generating constant streams, streams of random elements, etc. * * @param s the {@code DoubleSupplier} for generated elements * @return a new infinite sequential unordered {@code DoubleStream} */ public static DoubleStream generate(DoubleSupplier s) { Objects.requireNonNull(s); return StreamSupport.doubleStream( new StreamSpliterators.InfiniteSupplyingSpliterator.OfDouble(Long.MAX_VALUE, s), false); }
/** * Returns a stream consisting of elements of the passed stream that match * the given predicate up to, but discarding, the first element encountered * that does not match the predicate. All subsequently encountered elements * are discarded. * * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting * stateful intermediate operation</a>. * * @param stream the stream to wrap for the {@code takeWhile()} operation * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, * predicate to apply to each element to determine if it * should be included, or it and all subsequently * encountered elements be discarded. * @return the new stream * @since 9 */ public static DoubleStream takeWhile(DoubleStream stream, DoublePredicate predicate) { Objects.requireNonNull(stream); Objects.requireNonNull(predicate); // Reuses the unordered spliterator, which, when encounter is present, // is safe to use as long as it configured not to split return StreamSupport.doubleStream( new WhileOps.UnorderedWhileSpliterator.OfDouble.Taking(stream.spliterator(), true, predicate), stream.isParallel()).onClose(StreamSupport.closeHandler(stream)); }
/** * Returns a stream consisting of the remaining elements of the passed * stream after discarding elements that match the given predicate up to, * but not discarding, the first element encountered that does not match the * predicate. All subsequently encountered elements are not discarded. * * <p>This is a <a href="package-summary.html#StreamOps">stateful * intermediate operation</a>. * * @param stream the stream to wrap for the {@code dropWhile()} operation * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, * predicate to apply to each element to determine if it * should be discarded, or it and all subsequently * encountered elements be included. * @return the new stream * @since 9 */ public static DoubleStream dropWhile(DoubleStream stream, DoublePredicate predicate) { Objects.requireNonNull(stream); Objects.requireNonNull(predicate); // Reuses the unordered spliterator, which, when encounter is present, // is safe to use as long as it configured not to split return StreamSupport.doubleStream( new WhileOps.UnorderedWhileSpliterator.OfDouble.Dropping(stream.spliterator(), true, predicate), stream.isParallel()).onClose(StreamSupport.closeHandler(stream)); }