test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java

Print this page
rev 7962 : 8017513: Support for closeable streams
8022237: j.u.s.BaseStream.onClose() has an issue in implementation or requires spec clarification
8022572: Same exception instances thrown from j.u.stream.Stream.onClose() handlers are not listed as suppressed
Summary: BaseStream implements AutoCloseable; Remove CloseableStream and DelegatingStream
Reviewed-by:
Contributed-by: brian.goetz@oracle.com


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

  51         }
  52     },
  53 
  54     STREAM_TO_ARRAY(false) {
  55         <T, S_IN extends BaseStream<T, S_IN>>
  56         void _run(TestData<T, S_IN> data, IntConsumer b, Function<S_IN, IntStream> m) {
  57             for (int t : m.apply(data.stream()).toArray()) {
  58                 b.accept(t);
  59             }
  60         }
  61     },
  62 
  63     STREAM_ITERATOR(false) {
  64         <T, S_IN extends BaseStream<T, S_IN>>
  65         void _run(TestData<T, S_IN> data, IntConsumer b, Function<S_IN, IntStream> m) {
  66             for (PrimitiveIterator.OfInt seqIter = m.apply(data.stream()).iterator(); seqIter.hasNext(); )
  67                 b.accept(seqIter.nextInt());
  68         }
  69     },
  70 




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