jdk/src/java.base/share/classes/java/util/stream/StreamSpliterators.java
changeset 32649 2ee9017c7597
parent 25859 3317bb8137f4
child 35714 05eadb5e7022
equal deleted inserted replaced
32648:1fa861caf840 32649:2ee9017c7597
    55      * spliterator when first operated on.
    55      * spliterator when first operated on.
    56      *
    56      *
    57      * <p>A wrapping spliterator produced from a sequential stream
    57      * <p>A wrapping spliterator produced from a sequential stream
    58      * cannot be split if there are stateful operations present.
    58      * cannot be split if there are stateful operations present.
    59      */
    59      */
    60     private static abstract class AbstractWrappingSpliterator<P_IN, P_OUT,
    60     private abstract static class AbstractWrappingSpliterator<P_IN, P_OUT,
    61                                                               T_BUFFER extends AbstractSpinedBuffer>
    61                                                               T_BUFFER extends AbstractSpinedBuffer>
    62             implements Spliterator<P_OUT> {
    62             implements Spliterator<P_OUT> {
    63 
    63 
    64         // @@@ Detect if stateful operations are present or not
    64         // @@@ Detect if stateful operations are present or not
    65         //     If not then can split otherwise cannot
    65         //     If not then can split otherwise cannot
   605     /**
   605     /**
   606      * A slice Spliterator from a source Spliterator that reports
   606      * A slice Spliterator from a source Spliterator that reports
   607      * {@code SUBSIZED}.
   607      * {@code SUBSIZED}.
   608      *
   608      *
   609      */
   609      */
   610     static abstract class SliceSpliterator<T, T_SPLITR extends Spliterator<T>> {
   610     abstract static class SliceSpliterator<T, T_SPLITR extends Spliterator<T>> {
   611         // The start index of the slice
   611         // The start index of the slice
   612         final long sliceOrigin;
   612         final long sliceOrigin;
   613         // One past the last index of the slice
   613         // One past the last index of the slice
   614         final long sliceFence;
   614         final long sliceFence;
   615 
   615 
   751                     }
   751                     }
   752                 }
   752                 }
   753             }
   753             }
   754         }
   754         }
   755 
   755 
   756         static abstract class OfPrimitive<T,
   756         abstract static class OfPrimitive<T,
   757                 T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>,
   757                 T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>,
   758                 T_CONS>
   758                 T_CONS>
   759                 extends SliceSpliterator<T, T_SPLITR>
   759                 extends SliceSpliterator<T, T_SPLITR>
   760                 implements Spliterator.OfPrimitive<T, T_CONS, T_SPLITR> {
   760                 implements Spliterator.OfPrimitive<T, T_CONS, T_SPLITR> {
   761 
   761 
   897      * Note: The source spliterator may report {@code ORDERED} since that
   897      * Note: The source spliterator may report {@code ORDERED} since that
   898      * spliterator be the result of a previous pipeline stage that was
   898      * spliterator be the result of a previous pipeline stage that was
   899      * collected to a {@code Node}. It is the order of the pipeline stage
   899      * collected to a {@code Node}. It is the order of the pipeline stage
   900      * that governs whether the this slice spliterator is to be used or not.
   900      * that governs whether the this slice spliterator is to be used or not.
   901      */
   901      */
   902     static abstract class UnorderedSliceSpliterator<T, T_SPLITR extends Spliterator<T>> {
   902     abstract static class UnorderedSliceSpliterator<T, T_SPLITR extends Spliterator<T>> {
   903         static final int CHUNK_SIZE = 1 << 7;
   903         static final int CHUNK_SIZE = 1 << 7;
   904 
   904 
   905         // The spliterator to slice
   905         // The spliterator to slice
   906         protected final T_SPLITR s;
   906         protected final T_SPLITR s;
   907         protected final boolean unlimited;
   907         protected final boolean unlimited;
  1058          * Concrete sub-types must also be an instance of type {@code T_CONS}.
  1058          * Concrete sub-types must also be an instance of type {@code T_CONS}.
  1059          *
  1059          *
  1060          * @param <T_BUFF> the type of the spined buffer. Must also be a type of
  1060          * @param <T_BUFF> the type of the spined buffer. Must also be a type of
  1061          *        {@code T_CONS}.
  1061          *        {@code T_CONS}.
  1062          */
  1062          */
  1063         static abstract class OfPrimitive<
  1063         abstract static class OfPrimitive<
  1064                 T,
  1064                 T,
  1065                 T_CONS,
  1065                 T_CONS,
  1066                 T_BUFF extends ArrayBuffer.OfPrimitive<T_CONS>,
  1066                 T_BUFF extends ArrayBuffer.OfPrimitive<T_CONS>,
  1067                 T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>>
  1067                 T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>>
  1068                 extends UnorderedSliceSpliterator<T, T_SPLITR>
  1068                 extends UnorderedSliceSpliterator<T, T_SPLITR>
  1322      *
  1322      *
  1323      * <p>The {@code forEachRemaining} method if invoked will never terminate.
  1323      * <p>The {@code forEachRemaining} method if invoked will never terminate.
  1324      * The {@code tryAdvance} method always returns true.
  1324      * The {@code tryAdvance} method always returns true.
  1325      *
  1325      *
  1326      */
  1326      */
  1327     static abstract class InfiniteSupplyingSpliterator<T> implements Spliterator<T> {
  1327     abstract static class InfiniteSupplyingSpliterator<T> implements Spliterator<T> {
  1328         long estimate;
  1328         long estimate;
  1329 
  1329 
  1330         protected InfiniteSupplyingSpliterator(long estimate) {
  1330         protected InfiniteSupplyingSpliterator(long estimate) {
  1331             this.estimate = estimate;
  1331             this.estimate = estimate;
  1332         }
  1332         }
  1440             }
  1440             }
  1441         }
  1441         }
  1442     }
  1442     }
  1443 
  1443 
  1444     // @@@ Consolidate with Node.Builder
  1444     // @@@ Consolidate with Node.Builder
  1445     static abstract class ArrayBuffer {
  1445     abstract static class ArrayBuffer {
  1446         int index;
  1446         int index;
  1447 
  1447 
  1448         void reset() {
  1448         void reset() {
  1449             index = 0;
  1449             index = 0;
  1450         }
  1450         }
  1468                     action.accept(t);
  1468                     action.accept(t);
  1469                 }
  1469                 }
  1470             }
  1470             }
  1471         }
  1471         }
  1472 
  1472 
  1473         static abstract class OfPrimitive<T_CONS> extends ArrayBuffer {
  1473         abstract static class OfPrimitive<T_CONS> extends ArrayBuffer {
  1474             int index;
  1474             int index;
  1475 
  1475 
  1476             @Override
  1476             @Override
  1477             void reset() {
  1477             void reset() {
  1478                 index = 0;
  1478                 index = 0;