changeset 7556:9dc2126deb55

Characteristics for range and infinite stream.
author psandoz
date Mon, 04 Mar 2013 16:35:05 +0100
parents a65fb326969d
children 18ea6bfc143c
files src/share/classes/java/util/stream/Streams.java
diffstat 1 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/stream/Streams.java	Mon Mar 04 15:35:55 2013 +0100
+++ b/src/share/classes/java/util/stream/Streams.java	Mon Mar 04 16:35:05 2013 +0100
@@ -459,7 +459,10 @@
                 return t = (t == null) ? seed : f.apply(t);
             }
         };
-        return stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return stream(Spliterators.spliteratorUnknownSize(
+                iterator,
+                Spliterator.INFINITE | Spliterator.ORDERED |
+                Spliterator.IMMUTABLE));
     }
 
     /**
@@ -479,7 +482,10 @@
      */
     public static<T> Stream<T> generate(Supplier<T> s) {
         InfiniteIterator<T> iterator = s::get;
-        return stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return stream(Spliterators.spliteratorUnknownSize(
+                iterator,
+                Spliterator.INFINITE | Spliterator.ORDERED |
+                Spliterator.IMMUTABLE));
     }
 
     // Infinite IntStream generators and ranges
@@ -509,7 +515,10 @@
                 return v;
             }
         };
-        return intStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return intStream(Spliterators.spliteratorUnknownSize(
+                iterator,
+                Spliterator.INFINITE | Spliterator.ORDERED |
+                Spliterator.IMMUTABLE | Spliterator.NONNULL));
     }
 
     /**
@@ -529,7 +538,10 @@
      */
     public static IntStream generateInt(IntSupplier s) {
         InfiniteIterator.OfInt iterator = s::getAsInt;
-        return intStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return intStream(Spliterators.spliteratorUnknownSize(
+                iterator,
+                Spliterator.INFINITE | Spliterator.ORDERED |
+                Spliterator.IMMUTABLE | Spliterator.NONNULL));
     }
 
     /**
@@ -622,7 +634,10 @@
                 return v;
             }
         };
-        return longStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return longStream(Spliterators.spliteratorUnknownSize(
+                iterator,
+                Spliterator.INFINITE | Spliterator.ORDERED |
+                Spliterator.IMMUTABLE | Spliterator.NONNULL));
     }
 
     /**
@@ -642,7 +657,10 @@
      */
     public static LongStream generateLong(LongSupplier s) {
         InfiniteIterator.OfLong iterator = s::getAsLong;
-        return longStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return longStream(Spliterators.spliteratorUnknownSize(
+                iterator,
+                Spliterator.INFINITE | Spliterator.ORDERED |
+                Spliterator.IMMUTABLE | Spliterator.NONNULL));
     }
 
     /**
@@ -735,7 +753,10 @@
                 return v;
             }
         };
-        return doubleStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return doubleStream(Spliterators.spliteratorUnknownSize(
+                iterator,
+                Spliterator.INFINITE | Spliterator.ORDERED |
+                Spliterator.IMMUTABLE | Spliterator.NONNULL));
     }
 
     /**
@@ -755,7 +776,10 @@
      */
     public static DoubleStream generateDouble(DoubleSupplier s) {
         InfiniteIterator.OfDouble iterator = s::getAsDouble;
-        return doubleStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return doubleStream(Spliterators.spliteratorUnknownSize(
+                iterator,
+                Spliterator.INFINITE | Spliterator.ORDERED |
+                Spliterator.IMMUTABLE | Spliterator.NONNULL));
     }
 
     // Stream combining functions
@@ -980,7 +1004,9 @@
 
         @Override
         public int characteristics() {
-            return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;
+            return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED |
+                   Spliterator.IMMUTABLE | Spliterator.NONNULL |
+                   Spliterator.DISTINCT | (step > 0 ? Spliterator.SORTED : 0);
         }
 
         @Override
@@ -1045,7 +1071,9 @@
 
         @Override
         public int characteristics() {
-            return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;
+            return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED |
+                   Spliterator.IMMUTABLE | Spliterator.NONNULL |
+                   Spliterator.DISTINCT | (step > 0 ? Spliterator.SORTED : 0);
         }
 
         @Override