changeset 6351:e4101c3658cc

Remove remaining ISEs in pipeline operations
author briangoetz
date Thu, 25 Oct 2012 14:56:42 -0400
parents 52fe21edb93b
children 8cc8b86e8231
files src/share/classes/java/util/streams/AbstractPipeline.java src/share/classes/java/util/streams/Streams.java test-ng/tests/org/openjdk/tests/java/util/streams/ops/InfiniteStreamWithLimitOpTest.java
diffstat 3 files changed, 8 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/streams/AbstractPipeline.java	Wed Oct 24 12:27:58 2012 -0700
+++ b/src/share/classes/java/util/streams/AbstractPipeline.java	Thu Oct 25 14:56:42 2012 -0400
@@ -225,16 +225,6 @@
 
         <R> SequentialImplPipelineHelper(StreamAccessor<P_IN> source, TerminalOp<E_OUT, R> terminal) {
             super(source, pipes());
-
-            // @@@ Other potential IllegalStateException
-            // @@@ If an infinite stream is input to a stateful intermediate op that is required to operate on all
-            //     elements of the input before producing the output e.g. SortedOp
-            // @@@ There is currently no mechanism to differentiate between SortedOp and CumulateOp, they are both
-            //     stateful but the latter does not need to consume all the input
-
-            if (!terminal.isShortCircuit() && isOutputInfinitelySized()) {
-                throw new IllegalStateException("A stream of known infinite size is input to a non-short-circuiting terminal operation");
-            }
         }
 
         @Override
--- a/src/share/classes/java/util/streams/Streams.java	Wed Oct 24 12:27:58 2012 -0700
+++ b/src/share/classes/java/util/streams/Streams.java	Thu Oct 25 14:56:42 2012 -0400
@@ -234,7 +234,7 @@
 
         // Check if the source is empty
         if (!source.iterator().hasNext()) {
-            throw new IllegalArgumentException("Source Iterable to cycle elements from must not be empty");
+            return Collections.<T>emptyList().stream();
         }
 
         final InfiniteIterator<T> cycle = new InfiniteIterator<T>() {
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/InfiniteStreamWithLimitOpTest.java	Wed Oct 24 12:27:58 2012 -0700
+++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/InfiniteStreamWithLimitOpTest.java	Thu Oct 25 14:56:42 2012 -0400
@@ -28,6 +28,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.streams.Stream;
 import java.util.streams.Streams;
 
@@ -65,6 +66,12 @@
                 Arrays.asList(0, 1, 1, 2, 3, 5, 8, 13, 21, 34).iterator());
     }
 
+    public void testEmptyCycle() {
+        assertContents(
+                Streams.cycle(Collections.emptyList()).iterator(),
+                Collections.emptyList().iterator());
+    }
+
     public void testCycleLimit() {
         assertContents(
                 Streams.cycle(Arrays.asList(0, 1, 2, 3)).limit(16).iterator(),
@@ -83,21 +90,6 @@
         assertFalse(Streams.cycle(Arrays.asList(1, 2, 3, 4)).noneMatch(i -> i > 3));
     }
 
-    @Test(expectedExceptions = {IllegalStateException.class})
-    public void testInfiniteToNonShortCircuitTerminal() {
-        Streams.repeat(1).toArray();
-    }
-
-    @Test(expectedExceptions = {IllegalStateException.class})
-    public void testInfiniteToNonShortCircuitTerminal2() {
-        Streams.repeat(1).filter(i -> true).toArray();
-    }
-
-    @Test(expectedExceptions = {IllegalStateException.class})
-    public void testInfiniteToNonShortCircuitTerminal3() {
-        Streams.repeat(1).into(new ArrayList<>());
-    }
-
     public void testInfiniteWithLimitToShortCircuitTerminal() {
         Streams.repeat(1).limit(4).toArray();
         Streams.repeat(1).limit(4).filter(i -> true).toArray();