jdk/src/share/classes/java/util/stream/Stream.java
changeset 18820 a87cdd6a8834
parent 18572 53b8b8c30086
child 18822 4b6be7c19547
equal deleted inserted replaced
18819:c4335fc31aeb 18820:a87cdd6a8834
   881     public static<T> Stream<T> generate(Supplier<T> s) {
   881     public static<T> Stream<T> generate(Supplier<T> s) {
   882         Objects.requireNonNull(s);
   882         Objects.requireNonNull(s);
   883         return StreamSupport.stream(
   883         return StreamSupport.stream(
   884                 new StreamSpliterators.InfiniteSupplyingSpliterator.OfRef<>(Long.MAX_VALUE, s));
   884                 new StreamSpliterators.InfiniteSupplyingSpliterator.OfRef<>(Long.MAX_VALUE, s));
   885     }
   885     }
       
   886 
       
   887     /**
       
   888      * Creates a lazy concatenated {@code Stream} whose elements are all the
       
   889      * elements of a first {@code Stream} succeeded by all the elements of the
       
   890      * second {@code Stream}. The resulting stream is ordered if both
       
   891      * of the input streams are ordered, and parallel if either of the input
       
   892      * streams is parallel.
       
   893      *
       
   894      * @param <T> The type of stream elements
       
   895      * @param a the first stream
       
   896      * @param b the second stream to concatenate on to end of the first
       
   897      *        stream
       
   898      * @return the concatenation of the two input streams
       
   899      */
       
   900     public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b) {
       
   901         Objects.requireNonNull(a);
       
   902         Objects.requireNonNull(b);
       
   903 
       
   904         @SuppressWarnings("unchecked")
       
   905         Spliterator<T> split = new Streams.ConcatSpliterator.OfRef<>(
       
   906                 (Spliterator<T>) a.spliterator(), (Spliterator<T>) b.spliterator());
       
   907         return (a.isParallel() || b.isParallel())
       
   908                ? StreamSupport.parallelStream(split)
       
   909                : StreamSupport.stream(split);
       
   910     }
   886 }
   911 }