test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java

Print this page
rev 7630 : 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
Reviewed-by: henryjen
rev 7633 : 8017513: Support for closeable streams
Reviewed-by:
Contributed-by: brian.goetz@oracle.com


  22  */
  23 package java.util.stream;
  24 
  25 import java.util.Iterator;
  26 import java.util.Spliterator;
  27 import java.util.function.Consumer;
  28 import java.util.function.Function;
  29 
  30 /**
  31  * Test scenarios for reference streams.
  32  *
  33  * Each scenario is provided with a data source, a function that maps a fresh
  34  * stream (as provided by the data source) to a new stream, and a sink to
  35  * receive results.  Each scenario describes a different way of computing the
  36  * stream contents.  The test driver will ensure that all scenarios produce
  37  * the same output (modulo allowable differences in ordering).
  38  */
  39 @SuppressWarnings({"rawtypes", "unchecked"})
  40 public enum StreamTestScenario implements OpTestCase.BaseStreamTestScenario {
  41 
  42     STREAM_FOR_EACH(false) {
  43         <T, U, S_IN extends BaseStream<T, S_IN>>
  44         void _run(TestData<T, S_IN> data, Consumer<U> b, Function<S_IN, Stream<U>> m) {
  45             Stream<U> s = m.apply(data.stream());
  46             if (s.isParallel()) {
  47                 s = s.sequential();
  48             }
  49             s.forEach(b);

  50         }
  51     },
  52 
  53     // Collec to list
  54     STREAM_COLLECT(false) {
  55         <T, U, S_IN extends BaseStream<T, S_IN>>
  56         void _run(TestData<T, S_IN> data, Consumer<U> b, Function<S_IN, Stream<U>> m) {
  57             for (U t : m.apply(data.stream()).collect(Collectors.toList())) {
  58                 b.accept(t);
  59             }
  60         }
  61     },
  62 
  63     // To array
  64     STREAM_TO_ARRAY(false) {
  65         <T, U, S_IN extends BaseStream<T, S_IN>>
  66         void _run(TestData<T, S_IN> data, Consumer<U> b, Function<S_IN, Stream<U>> m) {
  67             for (Object t : m.apply(data.stream()).toArray()) {
  68                 b.accept((U) t);
  69             }




  22  */
  23 package java.util.stream;
  24 
  25 import java.util.Iterator;
  26 import java.util.Spliterator;
  27 import java.util.function.Consumer;
  28 import java.util.function.Function;
  29 
  30 /**
  31  * Test scenarios for reference streams.
  32  *
  33  * Each scenario is provided with a data source, a function that maps a fresh
  34  * stream (as provided by the data source) to a new stream, and a sink to
  35  * receive results.  Each scenario describes a different way of computing the
  36  * stream contents.  The test driver will ensure that all scenarios produce
  37  * the same output (modulo allowable differences in ordering).
  38  */
  39 @SuppressWarnings({"rawtypes", "unchecked"})
  40 public enum StreamTestScenario implements OpTestCase.BaseStreamTestScenario {
  41 
  42     STREAM_FOR_EACH_WITH_CLOSE(false) {
  43         <T, U, S_IN extends BaseStream<T, S_IN>>
  44         void _run(TestData<T, S_IN> data, Consumer<U> b, Function<S_IN, Stream<U>> m) {
  45             Stream<U> s = m.apply(data.stream());
  46             if (s.isParallel()) {
  47                 s = s.sequential();
  48             }
  49             s.forEach(b);
  50             s.close();
  51         }
  52     },
  53 
  54     // Collec to list
  55     STREAM_COLLECT(false) {
  56         <T, U, S_IN extends BaseStream<T, S_IN>>
  57         void _run(TestData<T, S_IN> data, Consumer<U> b, Function<S_IN, Stream<U>> m) {
  58             for (U t : m.apply(data.stream()).collect(Collectors.toList())) {
  59                 b.accept(t);
  60             }
  61         }
  62     },
  63 
  64     // To array
  65     STREAM_TO_ARRAY(false) {
  66         <T, U, S_IN extends BaseStream<T, S_IN>>
  67         void _run(TestData<T, S_IN> data, Consumer<U> b, Function<S_IN, Stream<U>> m) {
  68             for (Object t : m.apply(data.stream()).toArray()) {
  69                 b.accept((U) t);
  70             }