# HG changeset patch
# User psandoz
# Date 1370857952 -7200
# Node ID 644df1dfb3be7f2cdd1544c5f90c678b388a5506
# Parent 804f7c54faa6d2978ec56fb8eabcf53126091326
8015492: Remove DoubleStream.range methods
Reviewed-by: alanb
diff -r 804f7c54faa6 -r 644df1dfb3be jdk/src/share/classes/java/util/stream/DoubleStream.java
--- a/jdk/src/share/classes/java/util/stream/DoubleStream.java Sat Jun 08 09:05:49 2013 -0700
+++ b/jdk/src/share/classes/java/util/stream/DoubleStream.java Mon Jun 10 11:52:32 2013 +0200
@@ -753,75 +753,4 @@
},
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL));
}
-
- /**
- * Returns a sequential {@code DoubleStream} from {@code startInclusive} (inclusive)
- * to {@code endExclusive} (exclusive) by an incremental step of 1.0.
- *
- * @implSpec
- * The implementation behaves as if:
- *
{@code
- * doubleRange(startInclusive, endExclusive, 1.0);
- * }
- *
- * @param startInclusive the (inclusive) initial value
- * @param endExclusive the exclusive upper bound
- * @return a sequential {@code DoubleStream} for the range of {@code double}
- * elements
- */
- public static DoubleStream range(double startInclusive, double endExclusive) {
- return range(startInclusive, endExclusive, 1.0);
- }
-
- /**
- * Returns a sequential {@code DoubleStream} from {@code startInclusive}
- * (inclusive) to {@code endExclusive} (exclusive) by {@code step}. If
- * {@code startInclusive} is greater than or equal to {@code
- * endExclusive}, an empty stream is returned.
- *
- * An equivalent sequence of increasing values can be produced
- * sequentially using a {@code for} loop as follows:
- * {@code
- * long size = (long) Math.ceil((startInclusive - endExclusive) / step);
- * long i = 0
- * for (double v = startInclusive; i < size; i++, v = startInclusive + step * i) {
- * ...
- * }
- * }
- *
- * @param startInclusive the (inclusive) initial value
- * @param endExclusive the exclusive upper bound
- * @param step the difference between consecutive values
- * @return a sequential {@code DoubleStream} for tne range of {@code double}
- * elements
- * @throws IllegalArgumentException if {@code step} is less than or equal to
- * 0. is {@code NaN}, or the count of elements in the range would be
- * greater than {@code Long.MAX_VALUE}
- */
- public static DoubleStream range(double startInclusive, double endExclusive, double step) {
- // @@@ Need to check for ranges that may not produce distinct values
- // 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)) {
- throw new IllegalArgumentException(String.format("Illegal step: %f", step));
- } 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) {
- 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));
- }
- }
- }
}
diff -r 804f7c54faa6 -r 644df1dfb3be jdk/src/share/classes/java/util/stream/Streams.java
--- a/jdk/src/share/classes/java/util/stream/Streams.java Sat Jun 08 09:05:49 2013 -0700
+++ b/jdk/src/share/classes/java/util/stream/Streams.java Mon Jun 10 11:52:32 2013 +0200
@@ -192,87 +192,6 @@
}
}
- /**
- * A {@code double} range spliterator.
- *
- * The traversing and splitting logic is equivalent to that of
- * {@code RangeLongSpliterator} for increasing values with a {@code step} of
- * {@code 1}.
- *
- *
A {@code double} value is calculated from the function
- * {@code start + i * step} where {@code i} is the absolute position of the
- * value when traversing an instance of this class that has not been split.
- * This ensures the same values are produced at the same absolute positions
- * regardless of how an instance of this class is split or traversed.
- */
- static final class RangeDoubleSpliterator implements Spliterator.OfDouble {
- private final double from;
- private final double upTo;
- private final double step;
-
- private long lFrom;
- private final long lUpTo;
-
- RangeDoubleSpliterator(double from, double upTo, double step, long lFrom, long lUpTo) {
- this.from = from;
- this.upTo = upTo;
- this.step = step;
- this.lFrom = lFrom;
- this.lUpTo = lUpTo;
- }
-
- @Override
- public boolean tryAdvance(DoubleConsumer consumer) {
- boolean hasNext = lFrom < lUpTo;
- if (hasNext) {
- consumer.accept(from + lFrom * step);
- lFrom++;
- }
- return hasNext;
- }
-
- @Override
- public void forEachRemaining(DoubleConsumer consumer) {
- double hOrigin = from;
- double hStep = step;
- long hLUpTo = lUpTo;
- long i = lFrom;
- for (; i < hLUpTo; i++) {
- consumer.accept(hOrigin + i * hStep);
- }
- lFrom = i;
- }
-
- @Override
- public long estimateSize() {
- return lUpTo - lFrom;
- }
-
- @Override
- public int characteristics() {
- return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED |
- Spliterator.IMMUTABLE | Spliterator.NONNULL |
- Spliterator.DISTINCT | Spliterator.SORTED;
- }
-
- @Override
- public Comparator super Double> getComparator() {
- return null;
- }
-
- @Override
- public Spliterator.OfDouble trySplit() {
- return estimateSize() <= 1
- ? null
- : new RangeDoubleSpliterator(from, upTo, step, lFrom, lFrom = lFrom + midPoint());
- }
-
- private long midPoint() {
- // Size is known to be >= 2
- return (lUpTo - lFrom) / 2;
- }
- }
-
private static abstract class AbstractStreamBuilderImpl> implements Spliterator {
// >= 0 when building, < 0 when built
// -1 == no elements
diff -r 804f7c54faa6 -r 644df1dfb3be jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestDataProvider.java
--- a/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestDataProvider.java Sat Jun 08 09:05:49 2013 -0700
+++ b/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestDataProvider.java Mon Jun 10 11:52:32 2013 +0200
@@ -92,15 +92,6 @@
}
list.add(new Object[]{"SpinedList:" + name,
TestData.Factory.ofSpinedBuffer("SpinedList:" + name, isl)});
-
- list.add(streamDataDescr("Primitives.range(0,l): " + doubles.length,
- () -> DoubleStream.range(0, doubles.length)));
- list.add(streamDataDescr("Primitives.range(0,l,2): " + doubles.length,
- () -> DoubleStream.range(0, doubles.length, 2)));
- list.add(streamDataDescr("Primitives.range(0,l,3): " + doubles.length,
- () -> DoubleStream.range(0, doubles.length, 3)));
- list.add(streamDataDescr("Primitives.range(0,l,7): " + doubles.length,
- () -> DoubleStream.range(0, doubles.length, 7)));
}
testData = list.toArray(new Object[0][]);
}
@@ -128,15 +119,6 @@
() -> Spliterators.spliterator(isl.iterator(), doubles.length, 0)));
spliterators.add(splitDescr("Primitives.s(SpinedBuffer.iterator()):" + name,
() -> Spliterators.spliteratorUnknownSize(isl.iterator(), 0)));
-
- spliterators.add(splitDescr("Primitives.range(0,l):" + name,
- () -> DoubleStream.range(0, doubles.length).spliterator()));
- spliterators.add(splitDescr("Primitives.range(0,l,2):" + name,
- () -> DoubleStream.range(0, doubles.length, 2).spliterator()));
- spliterators.add(splitDescr("Primitives.range(0,l,3):" + name,
- () -> DoubleStream.range(0, doubles.length, 3).spliterator()));
- spliterators.add(splitDescr("Primitives.range(0,l,7):" + name,
- () -> DoubleStream.range(0, doubles.length, 7).spliterator()));
// Need more!
}
spliteratorTestData = spliterators.toArray(new Object[0][]);
@@ -144,10 +126,6 @@
}
- static Object[] streamDataDescr(String description, Supplier s) {
- return new Object[] { description, TestData.Factory.ofDoubleSupplier(description, s) };
- }
-
static Object[] splitDescr(String description, Supplier s) {
return new Object[] { description, s };
}
diff -r 804f7c54faa6 -r 644df1dfb3be jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java
--- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java Sat Jun 08 09:05:49 2013 -0700
+++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java Mon Jun 10 11:52:32 2013 +0200
@@ -110,7 +110,7 @@
result = exerciseOps(data, s -> DoubleStream.empty());
assertEquals(0, result.size());
- exerciseOps(data, s -> s.flatMap(e -> DoubleStream.range(0, e)));
- exerciseOps(data, s -> s.flatMap(e -> DoubleStream.range(0, e).limit(10)));
+ exerciseOps(data, s -> s.flatMap(e -> IntStream.range(0, (int) e).doubles()));
+ exerciseOps(data, s -> s.flatMap(e -> IntStream.range(0, (int) e).limit(10).doubles()));
}
}
diff -r 804f7c54faa6 -r 644df1dfb3be jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ForEachOpTest.java
--- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ForEachOpTest.java Sat Jun 08 09:05:49 2013 -0700
+++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ForEachOpTest.java Mon Jun 10 11:52:32 2013 +0200
@@ -205,7 +205,7 @@
public void testDoubleForEachOrdered() {
List input = countTo(10000);
TestData.OfDouble data = TestData.Factory.ofDoubleSupplier("[1, 10000]",
- () -> DoubleStream.range(1, 10001));
+ () -> IntStream.range(1, 10001).doubles());
Function> terminalFunc = s -> {
List l = new ArrayList<>();
diff -r 804f7c54faa6 -r 644df1dfb3be jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/RangeTest.java
--- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/RangeTest.java Sat Jun 08 09:05:49 2013 -0700
+++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/RangeTest.java Mon Jun 10 11:52:32 2013 +0200
@@ -221,124 +221,6 @@
//
- public void testDoubleRangeErrors() {
- for (double start : Arrays.asList(1, 10, -1, -10)) {
- for (double end : Arrays.asList(1, 10, -1, -10)) {
- for (double step : Arrays.asList(0.0, +0.0, -0.0, 1.0, -1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)) {
- try {
- if (step > 0)
- executeAndNoCatch(() -> DoubleStream.range(start, end, step));
- else
- executeAndCatch(() -> DoubleStream.range(start, end, step));
- }
- catch (AssertionError e) {
- System.out.printf("start=%f, end=%f, step=%f%n", start, end, step);
- throw e;
- }
- }
- }
- }
-
- for (double start : Arrays.asList(0.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) {
- for (double end : Arrays.asList(0.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) {
- for (double step : Arrays.asList(1.0, -1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) {
- try {
- if ((start == 0.0 && end == 0.0 && step > 0)
- || (start > end && step > 0)) {
- executeAndNoCatch(() -> DoubleStream.range(start, end, step));
- }
- else {
- executeAndCatch(() -> DoubleStream.range(start, end, step));
- }
- }
- catch (AssertionError e) {
- System.out.printf("start=%f, end=%f, step=%f%n", start, end, step);
- throw e;
- }
- }
- }
- }
- }
-
- public void testDoubleRange() {
- // Without step
- for (double start : Arrays.asList(1, 1000, -1, -1000)) {
- for (double end : Arrays.asList(1, 1000, -1, -1000)) {
- double step = 1;
- double size = start < end ? Math.ceil((end - start) / step) : 0;
- double[] exp = new double[(int) size];
- for (long i = 0; i < size; i++) {
- exp[(int) i] = start + i * step;
- }
-
- double[] inc = DoubleStream.range(start, end).toArray();
- assertEquals(inc.length, (int) size);
- assertTrue(Arrays.equals(exp, inc));
-
- withData(doubleRangeData(start, end, step)).stream(s -> s).
- expectedResult(exp).exercise();
- }
- }
-
- // With step
- for (double start : Arrays.asList(1, 1000, -1, -1000)) {
- for (double end : Arrays.asList(1, 1000, -1, -1000)) {
- for (double step : Arrays.asList(1, -1, -2, 2)) {
- if (step <= 0)
- continue;
- double size = start < end ? Math.ceil((end - start) / step) : 0;
- double[] exp = new double[(int) size];
- for (long i = 0; i < size; i++) {
- exp[(int) i] = start + i * step;
- }
-
- double[] inc = DoubleStream.range(start, end, step).toArray();
- assertEquals(inc.length, (int) size);
- assertTrue(Arrays.equals(exp, inc));
-
- withData(doubleRangeData(start, end, step)).stream(s -> s).
- expectedResult(exp).exercise();
- }
- }
- }
-
- // With non-integer values
- for (double step : Arrays.asList(Math.PI / 1000.0, Math.PI / 1000.0, Math.PI / 10000.0)) {
- double start = -Math.PI;
- double end = Math.PI;
- double size = start < end ? Math.ceil((end - start) / step) : 0;
- double[] exp = new double[(int) size];
- for (long i = 0; i < size; i++) {
- exp[(int) i] = start + i * step;
- }
-
- withData(doubleRangeData(start, end, step)).stream(s -> s).
- expectedResult(exp).exercise();
- }
- }
-
- TestData.OfDouble doubleRangeData(double start, double end, double step) {
- return TestData.Factory.ofDoubleSupplier("double range", () -> DoubleStream.range(start, end, step));
- }
-
- public void tesDoubleRangeReduce() {
- withData(doubleRangeData(0, 10000, 1)).
- terminal(s -> s.reduce(0, Double::sum)).exercise();
- }
-
- public void testDoubleInfiniteRangeLimit() {
- withData(TestData.Factory.ofDoubleSupplier(
- "double range", () -> DoubleStream.iterate(0, i -> i + 1).limit(10000))).
- terminal(s -> s.reduce(0, Double::sum)).exercise();
- }
-
- public void testDoubleInfiniteRangeFindFirst() {
- double first = DoubleStream.iterate(0, i -> i + 1).filter(i -> i > 10000).findFirst().getAsDouble();
- assertEquals(first, DoubleStream.iterate(0, i -> i + 1).parallel().filter(i -> i > 10000).findFirst().getAsDouble());
- }
-
- //
-
private static int[] reverse(int[] a) {
int[] b = new int[a.length];
for (int i = 0; i < a.length; i++) {
diff -r 804f7c54faa6 -r 644df1dfb3be jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java
--- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java Sat Jun 08 09:05:49 2013 -0700
+++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java Mon Jun 10 11:52:32 2013 +0200
@@ -275,7 +275,7 @@
@Test(dataProvider = "sizes")
public void testDoubleAfterBuilding(int size) {
StreamBuilder.OfDouble sb = DoubleStream.builder();
- DoubleStream.range(0, size).forEach(sb);
+ IntStream.range(0, size).doubles().forEach(sb);
sb.build();
checkISE(() -> sb.accept(1));
@@ -287,13 +287,13 @@
public void testDoubleStreamBuilder(int size) {
testDoubleStreamBuilder(size, (s) -> {
StreamBuilder.OfDouble sb = DoubleStream.builder();
- DoubleStream.range(0, s).forEach(sb);
+ IntStream.range(0, s).doubles().forEach(sb);
return sb.build();
});
testDoubleStreamBuilder(size, (s) -> {
StreamBuilder.OfDouble sb = DoubleStream.builder();
- DoubleStream.range(0, s).forEach(i -> {
+ IntStream.range(0, s).doubles().forEach(i -> {
StreamBuilder.OfDouble _sb = sb.add(i);
assertTrue(sb == _sb);
});
@@ -307,12 +307,12 @@
withData(data).
stream(s -> s).
- expectedResult(DoubleStream.range(0, size).toArray()).
+ expectedResult(IntStream.range(0, size).doubles().toArray()).
exercise();
withData(data).
stream(s -> s.map(i -> i)).
- expectedResult(DoubleStream.range(0, size).toArray()).
+ expectedResult(IntStream.range(0, size).doubles().toArray()).
exercise();
}
diff -r 804f7c54faa6 -r 644df1dfb3be jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java
--- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java Sat Jun 08 09:05:49 2013 -0700
+++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java Mon Jun 10 11:52:32 2013 +0200
@@ -526,7 +526,7 @@
for (boolean proxyEstimateSize : new boolean[]{false, true}) {
// Size is assumed to be larger than the target size for no splitting
// @@@ Need way to obtain the target size
- Spliterator.OfDouble sp = intermediateOp.apply(DoubleStream.range(0, 1000)).spliterator();
+ Spliterator.OfDouble sp = intermediateOp.apply(IntStream.range(0, 1000).doubles()).spliterator();
ProxyNoExactSizeSpliterator.OfDouble psp = new ProxyNoExactSizeSpliterator.OfDouble(sp, proxyEstimateSize);
DoubleStream s = StreamSupport.doubleParallelStream(psp);
terminalOp.accept(s);