提交 206c4375 编写于 作者: P psandoz

8015798: Rename IntStream.longs/doubles and LongStream.doubles to asXxxStream

Reviewed-by: alanb
上级 4a117002
...@@ -183,7 +183,7 @@ abstract class IntPipeline<E_IN> ...@@ -183,7 +183,7 @@ abstract class IntPipeline<E_IN>
// Stateless intermediate ops from IntStream // Stateless intermediate ops from IntStream
@Override @Override
public final LongStream longs() { public final LongStream asLongStream() {
return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE, return new LongPipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) { StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override @Override
...@@ -199,7 +199,7 @@ abstract class IntPipeline<E_IN> ...@@ -199,7 +199,7 @@ abstract class IntPipeline<E_IN>
} }
@Override @Override
public final DoubleStream doubles() { public final DoubleStream asDoubleStream() {
return new DoublePipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE, return new DoublePipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) { StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override @Override
...@@ -424,7 +424,7 @@ abstract class IntPipeline<E_IN> ...@@ -424,7 +424,7 @@ abstract class IntPipeline<E_IN>
@Override @Override
public final long count() { public final long count() {
return longs().map(e -> 1L).sum(); return asLongStream().map(e -> 1L).sum();
} }
@Override @Override
......
...@@ -625,7 +625,7 @@ public interface IntStream extends BaseStream<Integer, IntStream> { ...@@ -625,7 +625,7 @@ public interface IntStream extends BaseStream<Integer, IntStream> {
* @return a {@code LongStream} consisting of the elements of this stream, * @return a {@code LongStream} consisting of the elements of this stream,
* converted to {@code long} * converted to {@code long}
*/ */
LongStream longs(); LongStream asLongStream();
/** /**
* Returns a {@code DoubleStream} consisting of the elements of this stream, * Returns a {@code DoubleStream} consisting of the elements of this stream,
...@@ -634,7 +634,7 @@ public interface IntStream extends BaseStream<Integer, IntStream> { ...@@ -634,7 +634,7 @@ public interface IntStream extends BaseStream<Integer, IntStream> {
* @return a {@code DoubleStream} consisting of the elements of this stream, * @return a {@code DoubleStream} consisting of the elements of this stream,
* converted to {@code double} * converted to {@code double}
*/ */
DoubleStream doubles(); DoubleStream asDoubleStream();
/** /**
* Returns a {@code Stream} consisting of the elements of this stream, * Returns a {@code Stream} consisting of the elements of this stream,
......
...@@ -180,7 +180,7 @@ abstract class LongPipeline<E_IN> ...@@ -180,7 +180,7 @@ abstract class LongPipeline<E_IN>
// Stateless intermediate ops from LongStream // Stateless intermediate ops from LongStream
@Override @Override
public final DoubleStream doubles() { public final DoubleStream asDoubleStream() {
return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE, return new DoublePipeline.StatelessOp<Long>(this, StreamShape.LONG_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) { StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override @Override
......
...@@ -625,7 +625,7 @@ public interface LongStream extends BaseStream<Long, LongStream> { ...@@ -625,7 +625,7 @@ public interface LongStream extends BaseStream<Long, LongStream> {
* @return a {@code DoubleStream} consisting of the elements of this stream, * @return a {@code DoubleStream} consisting of the elements of this stream,
* converted to {@code double} * converted to {@code double}
*/ */
DoubleStream doubles(); DoubleStream asDoubleStream();
/** /**
* Returns a {@code Stream} consisting of the elements of this stream, * Returns a {@code Stream} consisting of the elements of this stream,
......
...@@ -300,7 +300,7 @@ public class SpinedBufferTest { ...@@ -300,7 +300,7 @@ public class SpinedBufferTest {
for (int size : sizes) { for (int size : sizes) {
// @@@ replace with double range when implemented // @@@ replace with double range when implemented
double[] array = LongStream.range(0, size).doubles().toArray(); double[] array = LongStream.range(0, size).asDoubleStream().toArray();
SpinedBuffer.OfDouble sb = new SpinedBuffer.OfDouble(); SpinedBuffer.OfDouble sb = new SpinedBuffer.OfDouble();
Arrays.stream(array).forEach(sb); Arrays.stream(array).forEach(sb);
......
...@@ -44,12 +44,12 @@ public class DoublePrimitiveOpsTests { ...@@ -44,12 +44,12 @@ public class DoublePrimitiveOpsTests {
public void testToArray() { public void testToArray() {
{ {
double[] array = LongStream.range(1, 10).doubles().map(i -> i * 2).toArray(); double[] array = LongStream.range(1, 10).asDoubleStream().map(i -> i * 2).toArray();
assertEquals(array, new double[]{2, 4, 6, 8, 10, 12, 14, 16, 18}); assertEquals(array, new double[]{2, 4, 6, 8, 10, 12, 14, 16, 18});
} }
{ {
double[] array = LongStream.range(1, 10).parallel().doubles().map(i -> i * 2).toArray(); double[] array = LongStream.range(1, 10).parallel().asDoubleStream().map(i -> i * 2).toArray();
assertEquals(array, new double[]{2, 4, 6, 8, 10, 12, 14, 16, 18}); assertEquals(array, new double[]{2, 4, 6, 8, 10, 12, 14, 16, 18});
} }
} }
...@@ -99,7 +99,7 @@ public class DoublePrimitiveOpsTests { ...@@ -99,7 +99,7 @@ public class DoublePrimitiveOpsTests {
} }
{ {
double[] actual = LongStream.range(1, 100).parallel().doubles().limit(9).toArray(); double[] actual = LongStream.range(1, 100).parallel().asDoubleStream().limit(9).toArray();
Assert.assertTrue(Arrays.equals(expected, actual)); Assert.assertTrue(Arrays.equals(expected, actual));
} }
} }
......
...@@ -110,7 +110,7 @@ public class ExplodeOpTest extends OpTestCase { ...@@ -110,7 +110,7 @@ public class ExplodeOpTest extends OpTestCase {
result = exerciseOps(data, s -> DoubleStream.empty()); result = exerciseOps(data, s -> DoubleStream.empty());
assertEquals(0, result.size()); assertEquals(0, result.size());
exerciseOps(data, s -> s.flatMap(e -> IntStream.range(0, (int) e).doubles())); exerciseOps(data, s -> s.flatMap(e -> IntStream.range(0, (int) e).asDoubleStream()));
exerciseOps(data, s -> s.flatMap(e -> IntStream.range(0, (int) e).limit(10).doubles())); exerciseOps(data, s -> s.flatMap(e -> IntStream.range(0, (int) e).limit(10).asDoubleStream()));
} }
} }
...@@ -205,7 +205,7 @@ public class ForEachOpTest extends OpTestCase { ...@@ -205,7 +205,7 @@ public class ForEachOpTest extends OpTestCase {
public void testDoubleForEachOrdered() { public void testDoubleForEachOrdered() {
List<Integer> input = countTo(10000); List<Integer> input = countTo(10000);
TestData.OfDouble data = TestData.Factory.ofDoubleSupplier("[1, 10000]", TestData.OfDouble data = TestData.Factory.ofDoubleSupplier("[1, 10000]",
() -> IntStream.range(1, 10001).doubles()); () -> IntStream.range(1, 10001).asDoubleStream());
Function<DoubleStream, List<Integer>> terminalFunc = s -> { Function<DoubleStream, List<Integer>> terminalFunc = s -> {
List<Integer> l = new ArrayList<>(); List<Integer> l = new ArrayList<>();
......
...@@ -24,16 +24,6 @@ package org.openjdk.tests.java.util.stream; ...@@ -24,16 +24,6 @@ package org.openjdk.tests.java.util.stream;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.function.DoubleToIntFunction;
import java.util.function.DoubleToLongFunction;
import java.util.function.Function;
import java.util.function.IntToDoubleFunction;
import java.util.function.IntToLongFunction;
import java.util.function.LongToDoubleFunction;
import java.util.function.LongToIntFunction;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import java.util.stream.*; import java.util.stream.*;
import static java.util.stream.LambdaTestHelpers.*; import static java.util.stream.LambdaTestHelpers.*;
...@@ -98,8 +88,8 @@ public class MapOpTest extends OpTestCase { ...@@ -98,8 +88,8 @@ public class MapOpTest extends OpTestCase {
exerciseOps(data, s -> s.mapToObj(i -> i)); exerciseOps(data, s -> s.mapToObj(i -> i));
exerciseOps(data, s -> s.map(i -> 0)); exerciseOps(data, s -> s.map(i -> 0));
exerciseOps(data, s -> s.map(i -> i * 2)); exerciseOps(data, s -> s.map(i -> i * 2));
exerciseOps(data, s -> s.longs()); exerciseOps(data, s -> s.asLongStream());
exerciseOps(data, s -> s.doubles()); exerciseOps(data, s -> s.asDoubleStream());
exerciseOps(data, s -> s.boxed()); exerciseOps(data, s -> s.boxed());
exerciseOps(data, s -> s.mapToObj(Integer::toString)); exerciseOps(data, s -> s.mapToObj(Integer::toString));
exerciseOps(data, s -> s.mapToLong(i -> i)); exerciseOps(data, s -> s.mapToLong(i -> i));
...@@ -113,7 +103,7 @@ public class MapOpTest extends OpTestCase { ...@@ -113,7 +103,7 @@ public class MapOpTest extends OpTestCase {
exerciseOps(data, s -> s.mapToObj(i -> i)); exerciseOps(data, s -> s.mapToObj(i -> i));
exerciseOps(data, s -> s.map(i -> 0L)); exerciseOps(data, s -> s.map(i -> 0L));
exerciseOps(data, s -> s.map(i -> i * 2L)); exerciseOps(data, s -> s.map(i -> i * 2L));
exerciseOps(data, s -> s.doubles()); exerciseOps(data, s -> s.asDoubleStream());
exerciseOps(data, s -> s.boxed()); exerciseOps(data, s -> s.boxed());
exerciseOps(data, s -> s.mapToObj(e -> Long.toString(e))); exerciseOps(data, s -> s.mapToObj(e -> Long.toString(e)));
exerciseOps(data, s -> s.mapToInt(i -> (int) i)); exerciseOps(data, s -> s.mapToInt(i -> (int) i));
......
...@@ -318,17 +318,17 @@ public class MatchOpTest extends OpTestCase { ...@@ -318,17 +318,17 @@ public class MatchOpTest extends OpTestCase {
} }
public void testDoubleStreamMatches() { public void testDoubleStreamMatches() {
assertDoublePredicates(() -> LongStream.range(0, 0).doubles(), Kind.ANY, DOUBLE_PREDICATES, false, false, false, false); assertDoublePredicates(() -> LongStream.range(0, 0).asDoubleStream(), Kind.ANY, DOUBLE_PREDICATES, false, false, false, false);
assertDoublePredicates(() -> LongStream.range(0, 0).doubles(), Kind.ALL, DOUBLE_PREDICATES, true, true, true, true); assertDoublePredicates(() -> LongStream.range(0, 0).asDoubleStream(), Kind.ALL, DOUBLE_PREDICATES, true, true, true, true);
assertDoublePredicates(() -> LongStream.range(0, 0).doubles(), Kind.NONE, DOUBLE_PREDICATES, true, true, true, true); assertDoublePredicates(() -> LongStream.range(0, 0).asDoubleStream(), Kind.NONE, DOUBLE_PREDICATES, true, true, true, true);
assertDoublePredicates(() -> LongStream.range(1, 2).doubles(), Kind.ANY, DOUBLE_PREDICATES, true, false, false, true); assertDoublePredicates(() -> LongStream.range(1, 2).asDoubleStream(), Kind.ANY, DOUBLE_PREDICATES, true, false, false, true);
assertDoublePredicates(() -> LongStream.range(1, 2).doubles(), Kind.ALL, DOUBLE_PREDICATES, true, false, false, true); assertDoublePredicates(() -> LongStream.range(1, 2).asDoubleStream(), Kind.ALL, DOUBLE_PREDICATES, true, false, false, true);
assertDoublePredicates(() -> LongStream.range(1, 2).doubles(), Kind.NONE, DOUBLE_PREDICATES, false, true, true, false); assertDoublePredicates(() -> LongStream.range(1, 2).asDoubleStream(), Kind.NONE, DOUBLE_PREDICATES, false, true, true, false);
assertDoublePredicates(() -> LongStream.range(1, 6).doubles(), Kind.ANY, DOUBLE_PREDICATES, true, false, true, true); assertDoublePredicates(() -> LongStream.range(1, 6).asDoubleStream(), Kind.ANY, DOUBLE_PREDICATES, true, false, true, true);
assertDoublePredicates(() -> LongStream.range(1, 6).doubles(), Kind.ALL, DOUBLE_PREDICATES, true, false, false, false); assertDoublePredicates(() -> LongStream.range(1, 6).asDoubleStream(), Kind.ALL, DOUBLE_PREDICATES, true, false, false, false);
assertDoublePredicates(() -> LongStream.range(1, 6).doubles(), Kind.NONE, DOUBLE_PREDICATES, false, true, false, false); assertDoublePredicates(() -> LongStream.range(1, 6).asDoubleStream(), Kind.NONE, DOUBLE_PREDICATES, false, true, false, false);
} }
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
......
...@@ -80,8 +80,8 @@ public class MinMaxTest extends OpTestCase { ...@@ -80,8 +80,8 @@ public class MinMaxTest extends OpTestCase {
public void testDoubleMinMax() { public void testDoubleMinMax() {
assertEquals(DoubleStream.empty().min(), OptionalDouble.empty()); assertEquals(DoubleStream.empty().min(), OptionalDouble.empty());
assertEquals(DoubleStream.empty().max(), OptionalDouble.empty()); assertEquals(DoubleStream.empty().max(), OptionalDouble.empty());
assertEquals(1.0, LongStream.range(1, 1001).doubles().min().getAsDouble()); assertEquals(1.0, LongStream.range(1, 1001).asDoubleStream().min().getAsDouble());
assertEquals(1000.0, LongStream.range(1, 1001).doubles().max().getAsDouble()); assertEquals(1000.0, LongStream.range(1, 1001).asDoubleStream().max().getAsDouble());
} }
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
......
...@@ -34,7 +34,7 @@ public class PrimitiveSumTest extends OpTestCase { ...@@ -34,7 +34,7 @@ public class PrimitiveSumTest extends OpTestCase {
withData(data). withData(data).
terminal(s -> (long) s.sum()). terminal(s -> (long) s.sum()).
expectedResult(data.stream().longs().reduce(0, LambdaTestHelpers.lrPlus)). expectedResult(data.stream().asLongStream().reduce(0, LambdaTestHelpers.lrPlus)).
exercise(); exercise();
} }
......
...@@ -275,7 +275,7 @@ public class StreamBuilderTest extends OpTestCase { ...@@ -275,7 +275,7 @@ public class StreamBuilderTest extends OpTestCase {
@Test(dataProvider = "sizes") @Test(dataProvider = "sizes")
public void testDoubleAfterBuilding(int size) { public void testDoubleAfterBuilding(int size) {
StreamBuilder.OfDouble sb = DoubleStream.builder(); StreamBuilder.OfDouble sb = DoubleStream.builder();
IntStream.range(0, size).doubles().forEach(sb); IntStream.range(0, size).asDoubleStream().forEach(sb);
sb.build(); sb.build();
checkISE(() -> sb.accept(1)); checkISE(() -> sb.accept(1));
...@@ -287,13 +287,13 @@ public class StreamBuilderTest extends OpTestCase { ...@@ -287,13 +287,13 @@ public class StreamBuilderTest extends OpTestCase {
public void testDoubleStreamBuilder(int size) { public void testDoubleStreamBuilder(int size) {
testDoubleStreamBuilder(size, (s) -> { testDoubleStreamBuilder(size, (s) -> {
StreamBuilder.OfDouble sb = DoubleStream.builder(); StreamBuilder.OfDouble sb = DoubleStream.builder();
IntStream.range(0, s).doubles().forEach(sb); IntStream.range(0, s).asDoubleStream().forEach(sb);
return sb.build(); return sb.build();
}); });
testDoubleStreamBuilder(size, (s) -> { testDoubleStreamBuilder(size, (s) -> {
StreamBuilder.OfDouble sb = DoubleStream.builder(); StreamBuilder.OfDouble sb = DoubleStream.builder();
IntStream.range(0, s).doubles().forEach(i -> { IntStream.range(0, s).asDoubleStream().forEach(i -> {
StreamBuilder.OfDouble _sb = sb.add(i); StreamBuilder.OfDouble _sb = sb.add(i);
assertTrue(sb == _sb); assertTrue(sb == _sb);
}); });
...@@ -307,12 +307,12 @@ public class StreamBuilderTest extends OpTestCase { ...@@ -307,12 +307,12 @@ public class StreamBuilderTest extends OpTestCase {
withData(data). withData(data).
stream(s -> s). stream(s -> s).
expectedResult(IntStream.range(0, size).doubles().toArray()). expectedResult(IntStream.range(0, size).asDoubleStream().toArray()).
exercise(); exercise();
withData(data). withData(data).
stream(s -> s.map(i -> i)). stream(s -> s.map(i -> i)).
expectedResult(IntStream.range(0, size).doubles().toArray()). expectedResult(IntStream.range(0, size).asDoubleStream().toArray()).
exercise(); exercise();
} }
......
...@@ -526,7 +526,7 @@ public class StreamSpliteratorTest extends OpTestCase { ...@@ -526,7 +526,7 @@ public class StreamSpliteratorTest extends OpTestCase {
for (boolean proxyEstimateSize : new boolean[]{false, true}) { for (boolean proxyEstimateSize : new boolean[]{false, true}) {
// Size is assumed to be larger than the target size for no splitting // Size is assumed to be larger than the target size for no splitting
// @@@ Need way to obtain the target size // @@@ Need way to obtain the target size
Spliterator.OfDouble sp = intermediateOp.apply(IntStream.range(0, 1000).doubles()).spliterator(); Spliterator.OfDouble sp = intermediateOp.apply(IntStream.range(0, 1000).asDoubleStream()).spliterator();
ProxyNoExactSizeSpliterator.OfDouble psp = new ProxyNoExactSizeSpliterator.OfDouble(sp, proxyEstimateSize); ProxyNoExactSizeSpliterator.OfDouble psp = new ProxyNoExactSizeSpliterator.OfDouble(sp, proxyEstimateSize);
DoubleStream s = StreamSupport.doubleParallelStream(psp); DoubleStream s = StreamSupport.doubleParallelStream(psp);
terminalOp.accept(s); terminalOp.accept(s);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册