--- old/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java 2015-11-13 15:38:20.214768755 -0800 +++ /dev/null 2015-05-15 15:37:46.536788447 -0700 @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package java.util.stream; - -import java.util.Collections; -import java.util.EnumSet; -import java.util.PrimitiveIterator; -import java.util.Set; -import java.util.Spliterator; -import java.util.function.Consumer; -import java.util.function.DoubleConsumer; -import java.util.function.Function; - -/** - * Test scenarios for double streams. - * - * Each scenario is provided with a data source, a function that maps a fresh - * stream (as provided by the data source) to a new stream, and a sink to - * receive results. Each scenario describes a different way of computing the - * stream contents. The test driver will ensure that all scenarios produce - * the same output (modulo allowable differences in ordering). - */ -@SuppressWarnings({"rawtypes", "unchecked"}) -public enum DoubleStreamTestScenario implements OpTestCase.BaseStreamTestScenario { - - STREAM_FOR_EACH(false) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - DoubleStream s = m.apply(source); - if (s.isParallel()) { - s = s.sequential(); - } - s.forEach(b); - } - }, - - STREAM_TO_ARRAY(false) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - for (double t : m.apply(source).toArray()) { - b.accept(t); - } - } - }, - - STREAM_ITERATOR(false) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - for (PrimitiveIterator.OfDouble seqIter = m.apply(source).iterator(); seqIter.hasNext(); ) - b.accept(seqIter.nextDouble()); - } - }, - - // Wrap as stream, and spliterate then iterate in pull mode - STREAM_SPLITERATOR(false) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - for (Spliterator.OfDouble spl = m.apply(source).spliterator(); spl.tryAdvance(b); ) { - } - } - }, - - // Wrap as stream, spliterate, then split a few times mixing advances with forEach - STREAM_SPLITERATOR_WITH_MIXED_TRAVERSE_AND_SPLIT(false) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - SpliteratorTestHelper.mixedTraverseAndSplit(b, m.apply(source).spliterator()); - } - }, - - // Wrap as stream, and spliterate then iterate in pull mode - STREAM_SPLITERATOR_FOREACH(false) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - m.apply(source).spliterator().forEachRemaining(b); - } - }, - - PAR_STREAM_SEQUENTIAL_FOR_EACH(true) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - m.apply(source).sequential().forEach(b); - } - }, - - // Wrap as parallel stream + forEachOrdered - PAR_STREAM_FOR_EACH_ORDERED(true) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - // @@@ Want to explicitly select ordered equalator - m.apply(source).forEachOrdered(b); - } - }, - - // Wrap as stream, and spliterate then iterate sequentially - PAR_STREAM_SPLITERATOR(true) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - for (Spliterator.OfDouble spl = m.apply(source).spliterator(); spl.tryAdvance(b); ) { - } - } - }, - - // Wrap as stream, and spliterate then iterate sequentially - PAR_STREAM_SPLITERATOR_FOREACH(true) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - m.apply(source).spliterator().forEachRemaining(b); - } - }, - - PAR_STREAM_TO_ARRAY(true) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - for (double t : m.apply(source).toArray()) - b.accept(t); - } - }, - - // Wrap as parallel stream, get the spliterator, wrap as a stream + toArray - PAR_STREAM_SPLITERATOR_STREAM_TO_ARRAY(true) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - DoubleStream s = m.apply(source); - Spliterator.OfDouble sp = s.spliterator(); - DoubleStream ss = StreamSupport.doubleStream(() -> sp, - StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) - | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED), true); - for (double t : ss.toArray()) - b.accept(t); - } - }, - - PAR_STREAM_TO_ARRAY_CLEAR_SIZED(true) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - S_IN pipe1 = (S_IN) OpTestCase.chain(source, - new FlagDeclaringOp(StreamOpFlag.NOT_SIZED, data.getShape())); - DoubleStream pipe2 = m.apply(pipe1); - - for (double t : pipe2.toArray()) - b.accept(t); - } - }, - - // Wrap as parallel stream + forEach synchronizing - PAR_STREAM_FOR_EACH(true, false) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - m.apply(source).forEach(e -> { - synchronized (data) { - b.accept(e); - } - }); - } - }, - - // Wrap as parallel stream + forEach synchronizing and clear SIZED flag - PAR_STREAM_FOR_EACH_CLEAR_SIZED(true, false) { - > - void run(TestData data, S_IN source, DoubleConsumer b, Function m) { - S_IN pipe1 = (S_IN) OpTestCase.chain(source, - new FlagDeclaringOp(StreamOpFlag.NOT_SIZED, data.getShape())); - m.apply(pipe1).forEach(e -> { - synchronized (data) { - b.accept(e); - } - }); - } - }, - ; - - // The set of scenarios that clean the SIZED flag - public static final Set CLEAR_SIZED_SCENARIOS = Collections.unmodifiableSet( - EnumSet.of(PAR_STREAM_TO_ARRAY_CLEAR_SIZED, PAR_STREAM_FOR_EACH_CLEAR_SIZED)); - - private boolean isParallel; - - private final boolean isOrdered; - - DoubleStreamTestScenario(boolean isParallel) { - this(isParallel, true); - } - - DoubleStreamTestScenario(boolean isParallel, boolean isOrdered) { - this.isParallel = isParallel; - this.isOrdered = isOrdered; - } - - public StreamShape getShape() { - return StreamShape.DOUBLE_VALUE; - } - - public boolean isParallel() { - return isParallel; - } - - public boolean isOrdered() { - return isOrdered; - } - - public , S_OUT extends BaseStream> - void run(TestData data, Consumer b, Function m) { - try (S_IN source = getStream(data)) { - run(data, source, (DoubleConsumer) b, (Function) m); - } - } - - abstract > - void run(TestData data, S_IN source, DoubleConsumer b, Function m); - -} --- /dev/null 2015-05-15 15:37:46.536788447 -0700 +++ new/test/java/util/stream/bootlib/java.base/java/util/stream/DoubleStreamTestScenario.java 2015-11-13 15:38:20.010760080 -0800 @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.stream; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.PrimitiveIterator; +import java.util.Set; +import java.util.Spliterator; +import java.util.function.Consumer; +import java.util.function.DoubleConsumer; +import java.util.function.Function; + +/** + * Test scenarios for double streams. + * + * Each scenario is provided with a data source, a function that maps a fresh + * stream (as provided by the data source) to a new stream, and a sink to + * receive results. Each scenario describes a different way of computing the + * stream contents. The test driver will ensure that all scenarios produce + * the same output (modulo allowable differences in ordering). + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public enum DoubleStreamTestScenario implements OpTestCase.BaseStreamTestScenario { + + STREAM_FOR_EACH(false) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + DoubleStream s = m.apply(source); + if (s.isParallel()) { + s = s.sequential(); + } + s.forEach(b); + } + }, + + STREAM_TO_ARRAY(false) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + for (double t : m.apply(source).toArray()) { + b.accept(t); + } + } + }, + + STREAM_ITERATOR(false) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + for (PrimitiveIterator.OfDouble seqIter = m.apply(source).iterator(); seqIter.hasNext(); ) + b.accept(seqIter.nextDouble()); + } + }, + + // Wrap as stream, and spliterate then iterate in pull mode + STREAM_SPLITERATOR(false) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + for (Spliterator.OfDouble spl = m.apply(source).spliterator(); spl.tryAdvance(b); ) { + } + } + }, + + // Wrap as stream, spliterate, then split a few times mixing advances with forEach + STREAM_SPLITERATOR_WITH_MIXED_TRAVERSE_AND_SPLIT(false) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + SpliteratorTestHelper.mixedTraverseAndSplit(b, m.apply(source).spliterator()); + } + }, + + // Wrap as stream, and spliterate then iterate in pull mode + STREAM_SPLITERATOR_FOREACH(false) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + m.apply(source).spliterator().forEachRemaining(b); + } + }, + + PAR_STREAM_SEQUENTIAL_FOR_EACH(true) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + m.apply(source).sequential().forEach(b); + } + }, + + // Wrap as parallel stream + forEachOrdered + PAR_STREAM_FOR_EACH_ORDERED(true) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + // @@@ Want to explicitly select ordered equalator + m.apply(source).forEachOrdered(b); + } + }, + + // Wrap as stream, and spliterate then iterate sequentially + PAR_STREAM_SPLITERATOR(true) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + for (Spliterator.OfDouble spl = m.apply(source).spliterator(); spl.tryAdvance(b); ) { + } + } + }, + + // Wrap as stream, and spliterate then iterate sequentially + PAR_STREAM_SPLITERATOR_FOREACH(true) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + m.apply(source).spliterator().forEachRemaining(b); + } + }, + + PAR_STREAM_TO_ARRAY(true) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + for (double t : m.apply(source).toArray()) + b.accept(t); + } + }, + + // Wrap as parallel stream, get the spliterator, wrap as a stream + toArray + PAR_STREAM_SPLITERATOR_STREAM_TO_ARRAY(true) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + DoubleStream s = m.apply(source); + Spliterator.OfDouble sp = s.spliterator(); + DoubleStream ss = StreamSupport.doubleStream(() -> sp, + StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) + | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED), true); + for (double t : ss.toArray()) + b.accept(t); + } + }, + + PAR_STREAM_TO_ARRAY_CLEAR_SIZED(true) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + S_IN pipe1 = (S_IN) OpTestCase.chain(source, + new FlagDeclaringOp(StreamOpFlag.NOT_SIZED, data.getShape())); + DoubleStream pipe2 = m.apply(pipe1); + + for (double t : pipe2.toArray()) + b.accept(t); + } + }, + + // Wrap as parallel stream + forEach synchronizing + PAR_STREAM_FOR_EACH(true, false) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + m.apply(source).forEach(e -> { + synchronized (data) { + b.accept(e); + } + }); + } + }, + + // Wrap as parallel stream + forEach synchronizing and clear SIZED flag + PAR_STREAM_FOR_EACH_CLEAR_SIZED(true, false) { + > + void run(TestData data, S_IN source, DoubleConsumer b, Function m) { + S_IN pipe1 = (S_IN) OpTestCase.chain(source, + new FlagDeclaringOp(StreamOpFlag.NOT_SIZED, data.getShape())); + m.apply(pipe1).forEach(e -> { + synchronized (data) { + b.accept(e); + } + }); + } + }, + ; + + // The set of scenarios that clean the SIZED flag + public static final Set CLEAR_SIZED_SCENARIOS = Collections.unmodifiableSet( + EnumSet.of(PAR_STREAM_TO_ARRAY_CLEAR_SIZED, PAR_STREAM_FOR_EACH_CLEAR_SIZED)); + + private boolean isParallel; + + private final boolean isOrdered; + + DoubleStreamTestScenario(boolean isParallel) { + this(isParallel, true); + } + + DoubleStreamTestScenario(boolean isParallel, boolean isOrdered) { + this.isParallel = isParallel; + this.isOrdered = isOrdered; + } + + public StreamShape getShape() { + return StreamShape.DOUBLE_VALUE; + } + + public boolean isParallel() { + return isParallel; + } + + public boolean isOrdered() { + return isOrdered; + } + + public , S_OUT extends BaseStream> + void run(TestData data, Consumer b, Function m) { + try (S_IN source = getStream(data)) { + run(data, source, (DoubleConsumer) b, (Function) m); + } + } + + abstract > + void run(TestData data, S_IN source, DoubleConsumer b, Function m); + +}