< prev index next >

src/java.base/share/classes/java/util/stream/Streams.java

Print this page




  32 import java.util.function.IntConsumer;
  33 import java.util.function.LongConsumer;
  34 import jdk.internal.HotSpotIntrinsicCandidate;
  35 
  36 /**
  37  * Utility methods for operating on and creating streams.
  38  *
  39  * <p>Unless otherwise stated, streams are created as sequential streams.  A
  40  * sequential stream can be transformed into a parallel stream by calling the
  41  * {@code parallel()} method on the created stream.
  42  *
  43  * @since 1.8
  44  */
  45 final class Streams {
  46 
  47     private Streams() {
  48         throw new Error("no instances");
  49     }
  50 
  51     /**
  52      * An object instance representing no value, that cannot be an actual
  53      * data element of a stream.  Used when processing streams that can contain
  54      * {@code null} elements to distinguish between a {@code null} value and no
  55      * value.
  56      */
  57     static final Object NONE = new Object();
  58 
  59     /**
  60      * An {@code int} range spliterator.
  61      */
  62     static final class RangeIntSpliterator implements Spliterator.OfInt {
  63         // Can never be greater that upTo, this avoids overflow if upper bound
  64         // is Integer.MAX_VALUE
  65         // All elements are traversed if from == upTo & last == 0
  66         private int from;
  67         private final int upTo;
  68         // 1 if the range is closed and the last element has not been traversed
  69         // Otherwise, 0 if the range is open, or is a closed range and all
  70         // elements have been traversed
  71         private int last;
  72 
  73         RangeIntSpliterator(int from, int upTo, boolean closed) {
  74             this(from, upTo, closed ? 1 : 0);
  75         }
  76 
  77         private RangeIntSpliterator(int from, int upTo, int last) {
  78             this.from = from;
  79             this.upTo = upTo;




  32 import java.util.function.IntConsumer;
  33 import java.util.function.LongConsumer;
  34 import jdk.internal.HotSpotIntrinsicCandidate;
  35 
  36 /**
  37  * Utility methods for operating on and creating streams.
  38  *
  39  * <p>Unless otherwise stated, streams are created as sequential streams.  A
  40  * sequential stream can be transformed into a parallel stream by calling the
  41  * {@code parallel()} method on the created stream.
  42  *
  43  * @since 1.8
  44  */
  45 final class Streams {
  46 
  47     private Streams() {
  48         throw new Error("no instances");
  49     }
  50 
  51     /**








  52      * An {@code int} range spliterator.
  53      */
  54     static final class RangeIntSpliterator implements Spliterator.OfInt {
  55         // Can never be greater that upTo, this avoids overflow if upper bound
  56         // is Integer.MAX_VALUE
  57         // All elements are traversed if from == upTo & last == 0
  58         private int from;
  59         private final int upTo;
  60         // 1 if the range is closed and the last element has not been traversed
  61         // Otherwise, 0 if the range is open, or is a closed range and all
  62         // elements have been traversed
  63         private int last;
  64 
  65         RangeIntSpliterator(int from, int upTo, boolean closed) {
  66             this(from, upTo, closed ? 1 : 0);
  67         }
  68 
  69         private RangeIntSpliterator(int from, int upTo, int last) {
  70             this.from = from;
  71             this.upTo = upTo;


< prev index next >