jdk/src/share/classes/java/util/stream/IntStream.java
changeset 18822 4b6be7c19547
parent 18820 a87cdd6a8834
child 18825 06636235cd12
equal deleted inserted replaced
18821:50a3b8a90563 18822:4b6be7c19547
   672      * Returns an empty sequential {@code IntStream}.
   672      * Returns an empty sequential {@code IntStream}.
   673      *
   673      *
   674      * @return an empty sequential stream
   674      * @return an empty sequential stream
   675      */
   675      */
   676     public static IntStream empty() {
   676     public static IntStream empty() {
   677         return StreamSupport.intStream(Spliterators.emptyIntSpliterator());
   677         return StreamSupport.intStream(Spliterators.emptyIntSpliterator(), false);
   678     }
   678     }
   679 
   679 
   680     /**
   680     /**
   681      * Returns a sequential {@code IntStream} containing a single element.
   681      * Returns a sequential {@code IntStream} containing a single element.
   682      *
   682      *
   683      * @param t the single element
   683      * @param t the single element
   684      * @return a singleton sequential stream
   684      * @return a singleton sequential stream
   685      */
   685      */
   686     public static IntStream of(int t) {
   686     public static IntStream of(int t) {
   687         return StreamSupport.intStream(new Streams.IntStreamBuilderImpl(t));
   687         return StreamSupport.intStream(new Streams.IntStreamBuilderImpl(t), false);
   688     }
   688     }
   689 
   689 
   690     /**
   690     /**
   691      * Returns a sequential stream whose elements are the specified values.
   691      * Returns a sequential stream whose elements are the specified values.
   692      *
   692      *
   730                 return v;
   730                 return v;
   731             }
   731             }
   732         };
   732         };
   733         return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(
   733         return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(
   734                 iterator,
   734                 iterator,
   735                 Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL));
   735                 Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
   736     }
   736     }
   737 
   737 
   738     /**
   738     /**
   739      * Returns a sequential {@code IntStream} where each element is
   739      * Returns a sequential {@code IntStream} where each element is
   740      * generated by an {@code IntSupplier}.  This is suitable for generating
   740      * generated by an {@code IntSupplier}.  This is suitable for generating
   744      * @return a new sequential {@code IntStream}
   744      * @return a new sequential {@code IntStream}
   745      */
   745      */
   746     public static IntStream generate(IntSupplier s) {
   746     public static IntStream generate(IntSupplier s) {
   747         Objects.requireNonNull(s);
   747         Objects.requireNonNull(s);
   748         return StreamSupport.intStream(
   748         return StreamSupport.intStream(
   749                 new StreamSpliterators.InfiniteSupplyingSpliterator.OfInt(Long.MAX_VALUE, s));
   749                 new StreamSpliterators.InfiniteSupplyingSpliterator.OfInt(Long.MAX_VALUE, s), false);
   750     }
   750     }
   751 
   751 
   752     /**
   752     /**
   753      * Returns a sequential {@code IntStream} from {@code startInclusive}
   753      * Returns a sequential {@code IntStream} from {@code startInclusive}
   754      * (inclusive) to {@code endExclusive} (exclusive) by an incremental step of
   754      * (inclusive) to {@code endExclusive} (exclusive) by an incremental step of
   769     public static IntStream range(int startInclusive, int endExclusive) {
   769     public static IntStream range(int startInclusive, int endExclusive) {
   770         if (startInclusive >= endExclusive) {
   770         if (startInclusive >= endExclusive) {
   771             return empty();
   771             return empty();
   772         } else {
   772         } else {
   773             return StreamSupport.intStream(
   773             return StreamSupport.intStream(
   774                     new Streams.RangeIntSpliterator(startInclusive, endExclusive, false));
   774                     new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false);
   775         }
   775         }
   776     }
   776     }
   777 
   777 
   778     /**
   778     /**
   779      * Returns a sequential {@code IntStream} from {@code startInclusive}
   779      * Returns a sequential {@code IntStream} from {@code startInclusive}
   795     public static IntStream rangeClosed(int startInclusive, int endInclusive) {
   795     public static IntStream rangeClosed(int startInclusive, int endInclusive) {
   796         if (startInclusive > endInclusive) {
   796         if (startInclusive > endInclusive) {
   797             return empty();
   797             return empty();
   798         } else {
   798         } else {
   799             return StreamSupport.intStream(
   799             return StreamSupport.intStream(
   800                     new Streams.RangeIntSpliterator(startInclusive, endInclusive, true));
   800                     new Streams.RangeIntSpliterator(startInclusive, endInclusive, true), false);
   801         }
   801         }
   802     }
   802     }
   803 
   803 
   804     /**
   804     /**
   805      * Creates a lazy concatenated {@code IntStream} whose elements are all the
   805      * Creates a lazy concatenated {@code IntStream} whose elements are all the
   816         Objects.requireNonNull(a);
   816         Objects.requireNonNull(a);
   817         Objects.requireNonNull(b);
   817         Objects.requireNonNull(b);
   818 
   818 
   819         Spliterator.OfInt split = new Streams.ConcatSpliterator.OfInt(
   819         Spliterator.OfInt split = new Streams.ConcatSpliterator.OfInt(
   820                 a.spliterator(), b.spliterator());
   820                 a.spliterator(), b.spliterator());
   821         return (a.isParallel() || b.isParallel())
   821         return StreamSupport.intStream(split, a.isParallel() || b.isParallel());
   822                ? StreamSupport.intParallelStream(split)
       
   823                : StreamSupport.intStream(split);
       
   824     }
   822     }
   825 }
   823 }