src/share/classes/java/util/stream/DoubleStream.java

Print this page
rev 7627 : 8015315: Stream.concat methods
Reviewed-by: psandoz
Contributed-by: brian.goetz@oracle.com, henry.jen@oracle.com
rev 7630 : 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
Reviewed-by: henryjen
rev 7631 : 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
Reviewed-by: psandoz
Contributed-by: brian goetz <brian.goetz@oracle.com>
rev 7632 : 8015318: Extend Collector with 'finish' operation
Reviewed-by:
Contributed-by: brian.goetz@oracle.com
rev 7633 : 8017513: Support for closeable streams
Reviewed-by:
Contributed-by: brian.goetz@oracle.com


 735 
 736     /**
 737      * Returns a sequential {@code DoubleStream} where each element is
 738      * generated by an {@code DoubleSupplier}.  This is suitable for generating
 739      * constant streams, streams of random elements, etc.
 740      *
 741      * @param s the {@code DoubleSupplier} for generated elements
 742      * @return a new sequential {@code DoubleStream}
 743      */
 744     public static DoubleStream generate(DoubleSupplier s) {
 745         Objects.requireNonNull(s);
 746         return StreamSupport.doubleStream(
 747                 new StreamSpliterators.InfiniteSupplyingSpliterator.OfDouble(Long.MAX_VALUE, s), false);
 748     }
 749 
 750     /**
 751      * Creates a lazy concatenated {@code DoubleStream} whose elements are all the
 752      * elements of a first {@code DoubleStream} succeeded by all the elements of the
 753      * second {@code DoubleStream}. The resulting stream is ordered if both
 754      * of the input streams are ordered, and parallel if either of the input
 755      * streams is parallel.

 756      *
 757      * @param a the first stream
 758      * @param b the second stream to concatenate on to end of the first stream
 759      * @return the concatenation of the two streams
 760      */
 761     public static DoubleStream concat(DoubleStream a, DoubleStream b) {
 762         Objects.requireNonNull(a);
 763         Objects.requireNonNull(b);
 764 
 765         Spliterator.OfDouble split = new Streams.ConcatSpliterator.OfDouble(
 766                 a.spliterator(), b.spliterator());
 767         return StreamSupport.doubleStream(split, a.isParallel() || b.isParallel());

 768     }
 769 
 770     /**
 771      * A mutable builder for a {@code DoubleStream}.
 772      *
 773      * <p>A stream builder has a lifecycle, where it starts in a building
 774      * phase, during which elements can be added, and then transitions to a
 775      * built phase, after which elements may not be added.  The built phase
 776      * begins when the {@link #build()} method is called, which creates an
 777      * ordered stream whose elements are the elements that were added to the
 778      * stream builder, in the order they were added.
 779      *
 780      * @see DoubleStream#builder()
 781      * @since 1.8
 782      */
 783     public interface Builder extends DoubleConsumer {
 784 
 785         /**
 786          * Adds an element to the stream being built.
 787          *




 735 
 736     /**
 737      * Returns a sequential {@code DoubleStream} where each element is
 738      * generated by an {@code DoubleSupplier}.  This is suitable for generating
 739      * constant streams, streams of random elements, etc.
 740      *
 741      * @param s the {@code DoubleSupplier} for generated elements
 742      * @return a new sequential {@code DoubleStream}
 743      */
 744     public static DoubleStream generate(DoubleSupplier s) {
 745         Objects.requireNonNull(s);
 746         return StreamSupport.doubleStream(
 747                 new StreamSpliterators.InfiniteSupplyingSpliterator.OfDouble(Long.MAX_VALUE, s), false);
 748     }
 749 
 750     /**
 751      * Creates a lazy concatenated {@code DoubleStream} whose elements are all the
 752      * elements of a first {@code DoubleStream} succeeded by all the elements of the
 753      * second {@code DoubleStream}. The resulting stream is ordered if both
 754      * of the input streams are ordered, and parallel if either of the input
 755      * streams is parallel.  When the resulting stream is closed, the close
 756      * handlers for both input streams is invoked.
 757      *
 758      * @param a the first stream
 759      * @param b the second stream to concatenate on to end of the first stream
 760      * @return the concatenation of the two streams
 761      */
 762     public static DoubleStream concat(DoubleStream a, DoubleStream b) {
 763         Objects.requireNonNull(a);
 764         Objects.requireNonNull(b);
 765 
 766         Spliterator.OfDouble split = new Streams.ConcatSpliterator.OfDouble(
 767                 a.spliterator(), b.spliterator());
 768         DoubleStream stream = StreamSupport.doubleStream(split, a.isParallel() || b.isParallel());
 769         return stream.onClose(Streams.composedClose(a, b));
 770     }
 771 
 772     /**
 773      * A mutable builder for a {@code DoubleStream}.
 774      *
 775      * <p>A stream builder has a lifecycle, where it starts in a building
 776      * phase, during which elements can be added, and then transitions to a
 777      * built phase, after which elements may not be added.  The built phase
 778      * begins when the {@link #build()} method is called, which creates an
 779      * ordered stream whose elements are the elements that were added to the
 780      * stream builder, in the order they were added.
 781      *
 782      * @see DoubleStream#builder()
 783      * @since 1.8
 784      */
 785     public interface Builder extends DoubleConsumer {
 786 
 787         /**
 788          * Adds an element to the stream being built.
 789          *