提交 2a659c5d 编写于 作者: P psandoz

8017329: 8b92-lambda regression: TreeSet("a",...

8017329: 8b92-lambda regression: TreeSet("a", "b").stream().substream(1).parallel().iterator() is empty
Reviewed-by: alanb
上级 d7e96a5a
......@@ -598,9 +598,9 @@ final class SliceOps {
final Node.Builder<P_OUT> nb = op.makeNodeBuilder(sizeIfKnown, generator);
Sink<P_OUT> opSink = op.opWrapSink(helper.getStreamAndOpFlags(), nb);
helper.copyIntoWithCancel(helper.wrapSink(opSink), spliterator);
// It is necessary to truncate here since the result at the root
// can only be set once
return doTruncate(nb.build());
// There is no need to truncate since the op performs the
// skipping and limiting of elements
return nb.build();
}
else {
Node<P_OUT> node = helper.wrapAndCopyInto(helper.makeNodeBuilder(-1, generator),
......
......@@ -26,13 +26,16 @@ import org.testng.annotations.Test;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LambdaTestHelpers;
import java.util.stream.LongStream;
import java.util.stream.OpTestCase;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.stream.StreamTestDataProvider;
import java.util.stream.TestData;
......@@ -192,6 +195,53 @@ public class SliceOpTest extends OpTestCase {
}
}
public void testSkipLimitOpsWithNonSplittingSpliterator() {
class NonSplittingNotSubsizedOrderedSpliterator<T> implements Spliterator<T> {
Spliterator<T> s;
NonSplittingNotSubsizedOrderedSpliterator(Spliterator<T> s) {
assert s.hasCharacteristics(Spliterator.ORDERED);
this.s = s;
}
@Override
public boolean tryAdvance(Consumer<? super T> action) {
return s.tryAdvance(action);
}
@Override
public void forEachRemaining(Consumer<? super T> action) {
s.forEachRemaining(action);
}
@Override
public Spliterator<T> trySplit() {
return null;
}
@Override
public long estimateSize() {
return s.estimateSize();
}
@Override
public int characteristics() {
return s.characteristics() & ~(Spliterator.SUBSIZED);
}
@Override
public Comparator<? super T> getComparator() {
return s.getComparator();
}
}
List<Integer> list = IntStream.range(0, 100).boxed().collect(Collectors.toList());
TestData.OfRef<Integer> data = TestData.Factory.ofSupplier(
"Non splitting, not SUBSIZED, ORDERED, stream",
() -> StreamSupport.stream(new NonSplittingNotSubsizedOrderedSpliterator<>(list.spliterator())));
testSkipLimitOps("testSkipLimitOpsWithNonSplittingSpliterator", data);
}
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
public void testLimitOps(String name, TestData.OfRef<Integer> data) {
List<Integer> limits = sizes(data.size());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册