changeset 8408:63eaf13a7b9c

Clean up
author henryjen
date Fri, 26 Apr 2013 10:20:28 -0700
parents f91091fa0cc3
children 568d5f4bdd21 396ead07a8f7
files src/share/classes/java/util/stream/DoubleStream.java src/share/classes/java/util/stream/IntStream.java src/share/classes/java/util/stream/LongStream.java
diffstat 3 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/stream/DoubleStream.java	Fri Apr 26 17:00:36 2013 +0200
+++ b/src/share/classes/java/util/stream/DoubleStream.java	Fri Apr 26 10:20:28 2013 -0700
@@ -804,24 +804,25 @@
         //     such as when the step is very small
         //     Also clarify the size of the range which may produce more or less
         //     than expected
-        if (step <= 0 || Double.isNaN(step))
+        if (step <= 0 || Double.isNaN(step)) {
             throw new IllegalArgumentException(String.format("Illegal step: %f", step));
-        // @@@ Leave out equal case for case like range(INFINITE, INFINITE) or (NaN, Nan)
-        //     We can probably clarify on what values are invalid for start/end
-        else if (startInclusive > endExclusive)
-            return empty();
-        else {
+        } else {
+            double range = endExclusive - startInclusive;
+            if (range <= 0) {
+                return empty();
+            }
             double size = Math.ceil((endExclusive - startInclusive) / step);
             if (Double.isNaN(size)) {
                 throw new IllegalArgumentException(
                         String.format("Illegal range: %f size is NaN", size));
-            }
-            else if (size > Long.MAX_VALUE) {
+            } else if (size > Long.MAX_VALUE) {
                 throw new IllegalArgumentException(
                         String.format("Illegal range: size %f > Long.MAX_VALUE", size));
+            } else {
+                return StreamSupport.doubleStream(
+                        new Streams.RangeDoubleSpliterator(
+                                startInclusive, endExclusive, step, 0, (long) size));
             }
-            else
-                return StreamSupport.doubleStream(new Streams.RangeDoubleSpliterator(startInclusive, endExclusive, step, 0, (long) size));
         }
     }
 }
--- a/src/share/classes/java/util/stream/IntStream.java	Fri Apr 26 17:00:36 2013 +0200
+++ b/src/share/classes/java/util/stream/IntStream.java	Fri Apr 26 10:20:28 2013 -0700
@@ -796,11 +796,12 @@
      *         if {@code step} is less than or equal to 0
      */
     public static IntStream range(int startInclusive, int endExclusive, int step) {
-        if (step <= 0)
+        if (step <= 0) {
             throw new IllegalArgumentException(String.format("Illegal step: %d", step));
-        else if (startInclusive >= endExclusive)
+        } else if (startInclusive >= endExclusive) {
             return empty();
-        else
+        } else {
             return StreamSupport.intStream(new Streams.RangeIntSpliterator(startInclusive, endExclusive, step));
+        }
     }
 }
--- a/src/share/classes/java/util/stream/LongStream.java	Fri Apr 26 17:00:36 2013 +0200
+++ b/src/share/classes/java/util/stream/LongStream.java	Fri Apr 26 10:20:28 2013 -0700
@@ -787,11 +787,12 @@
      *         if {@code step} is less than or equal to 0
      */
     public static LongStream range(long startInclusive, final long endExclusive, final long step) {
-        if (step <= 0)
+        if (step <= 0) {
             throw new IllegalArgumentException(String.format("Illegal step: %d", step));
-        else if (startInclusive >= endExclusive)
+        } else if (startInclusive >= endExclusive) {
             return empty();
-        else
+        } else {
             return StreamSupport.longStream(new Streams.RangeLongSpliterator(startInclusive, endExclusive, step));
+        }
     }
 }