hasCharacteristics ( ) 源码实例Demo

java.util.Spliterator# hasCharacteristics ( ) 源码实例Demo

下面列出了java.util.Spliterator# hasCharacteristics ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk8u   文件: SpliteratorCollisions.java
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    assertContents(splits, exp, isOrdered);
}
 
源代码2 项目: dragonwell8_jdk   文件: SpliteratorTestHelper.java
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter,
        ContentAsserter<T> asserter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    asserter.assertContents(splits, exp, isOrdered);
}
 
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    assertContents(splits, exp, isOrdered);
}
 
源代码4 项目: dragonwell8_jdk   文件: SpliteratorCollisions.java
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    assertContents(splits, exp, isOrdered);
}
 
源代码5 项目: TencentKona-8   文件: SpliteratorTestHelper.java
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter,
        ContentAsserter<T> asserter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    asserter.assertContents(splits, exp, isOrdered);
}
 
private static void assertSpliterator(Spliterator<?> s) {
    if (s.hasCharacteristics(Spliterator.SUBSIZED)) {
        assertTrue(s.hasCharacteristics(Spliterator.SIZED));
    }
    if (s.hasCharacteristics(Spliterator.SIZED)) {
        assertTrue(s.estimateSize() != Long.MAX_VALUE);
        assertTrue(s.getExactSizeIfKnown() >= 0);
    }
    try {
        s.getComparator();
        assertTrue(s.hasCharacteristics(Spliterator.SORTED));
    } catch (IllegalStateException e) {
        assertFalse(s.hasCharacteristics(Spliterator.SORTED));
    }
}
 
源代码7 项目: TencentKona-8   文件: SpliteratorCollisions.java
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    assertContents(splits, exp, isOrdered);
}
 
源代码8 项目: TencentKona-8   文件: SpliteratorCollisions.java
private static void assertSpliterator(Spliterator<?> s) {
    if (s.hasCharacteristics(Spliterator.SUBSIZED)) {
        assertTrue(s.hasCharacteristics(Spliterator.SIZED));
    }
    if (s.hasCharacteristics(Spliterator.SIZED)) {
        assertTrue(s.estimateSize() != Long.MAX_VALUE);
        assertTrue(s.getExactSizeIfKnown() >= 0);
    }
    try {
        s.getComparator();
        assertTrue(s.hasCharacteristics(Spliterator.SORTED));
    } catch (IllegalStateException e) {
        assertFalse(s.hasCharacteristics(Spliterator.SORTED));
    }
}
 
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertRootSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    assertContents(splits, exp, isOrdered);
}
 
private static void assertSpliterator(Spliterator<?> s) {
    if (s.hasCharacteristics(Spliterator.SUBSIZED)) {
        assertTrue(s.hasCharacteristics(Spliterator.SIZED));
    }
    if (s.hasCharacteristics(Spliterator.SIZED)) {
        assertTrue(s.estimateSize() != Long.MAX_VALUE);
        assertTrue(s.getExactSizeIfKnown() >= 0);
    }
    try {
        s.getComparator();
        assertTrue(s.hasCharacteristics(Spliterator.SORTED));
    } catch (IllegalStateException e) {
        assertFalse(s.hasCharacteristics(Spliterator.SORTED));
    }
}
 
源代码11 项目: jdk8u60   文件: SpliteratorTestHelper.java
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter,
        ContentAsserter<T> asserter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    asserter.assertContents(splits, exp, isOrdered);
}
 
源代码12 项目: jdk8u60   文件: SpliteratorTestHelper.java
private static void assertSpliterator(Spliterator<?> s) {
    if (s.hasCharacteristics(Spliterator.SUBSIZED)) {
        assertTrue(s.hasCharacteristics(Spliterator.SIZED));
    }
    if (s.hasCharacteristics(Spliterator.SIZED)) {
        assertTrue(s.estimateSize() != Long.MAX_VALUE);
        assertTrue(s.getExactSizeIfKnown() >= 0);
    }
    try {
        s.getComparator();
        assertTrue(s.hasCharacteristics(Spliterator.SORTED));
    } catch (IllegalStateException e) {
        assertFalse(s.hasCharacteristics(Spliterator.SORTED));
    }
}
 
源代码13 项目: jdk8u60   文件: SpliteratorCollisions.java
private static <T, S extends Spliterator<T>> void testSplitUntilNull(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    Spliterator<T> s = supplier.get();
    boolean isOrdered = s.hasCharacteristics(Spliterator.ORDERED);
    assertSpliterator(s);

    List<T> splits = new ArrayList<>();
    Consumer<T> c = boxingAdapter.apply(splits::add);

    testSplitUntilNull(new SplitNode<T>(c, s));
    assertContents(splits, exp, isOrdered);
}
 
源代码14 项目: jdk1.8-source-analysis   文件: AbstractPipeline.java
/**
 * Get the source spliterator for this pipeline stage.  For a sequential or
 * stateless parallel pipeline, this is the source spliterator.  For a
 * stateful parallel pipeline, this is a spliterator describing the results
 * of all computations up to and including the most recent stateful
 * operation.
 */
@SuppressWarnings("unchecked")
private Spliterator<?> sourceSpliterator(int terminalFlags) {
    // Get the source spliterator of the pipeline
    Spliterator<?> spliterator = null;
    if (sourceStage.sourceSpliterator != null) {
        spliterator = sourceStage.sourceSpliterator;
        sourceStage.sourceSpliterator = null;
    }
    else if (sourceStage.sourceSupplier != null) {
        spliterator = (Spliterator<?>) sourceStage.sourceSupplier.get();
        sourceStage.sourceSupplier = null;
    }
    else {
        throw new IllegalStateException(MSG_CONSUMED);
    }

    if (isParallel() && sourceStage.sourceAnyStateful) {
        // Adapt the source spliterator, evaluating each stateful op
        // in the pipeline up to and including this pipeline stage.
        // The depth and flags of each pipeline stage are adjusted accordingly.
        int depth = 1;
        for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this;
             u != e;
             u = p, p = p.nextStage) {

            int thisOpFlags = p.sourceOrOpFlags;
            if (p.opIsStateful()) {
                depth = 0;

                if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) {
                    // Clear the short circuit flag for next pipeline stage
                    // This stage encapsulates short-circuiting, the next
                    // stage may not have any short-circuit operations, and
                    // if so spliterator.forEachRemaining should be used
                    // for traversal
                    thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT;
                }

                spliterator = p.opEvaluateParallelLazy(u, spliterator);

                // Inject or clear SIZED on the source pipeline stage
                // based on the stage's spliterator
                thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED)
                        ? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED
                        : (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED;
            }
            p.depth = depth++;
            p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags);
        }
    }

    if (terminalFlags != 0)  {
        // Apply flags from the terminal operation to last pipeline stage
        combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags);
    }

    return spliterator;
}
 
源代码15 项目: desugar_jdk_libs   文件: AbstractPipeline.java
/**
 * Get the source spliterator for this pipeline stage.  For a sequential or
 * stateless parallel pipeline, this is the source spliterator.  For a
 * stateful parallel pipeline, this is a spliterator describing the results
 * of all computations up to and including the most recent stateful
 * operation.
 */
@SuppressWarnings("unchecked")
private Spliterator<?> sourceSpliterator(int terminalFlags) {
    // Get the source spliterator of the pipeline
    Spliterator<?> spliterator = null;
    if (sourceStage.sourceSpliterator != null) {
        spliterator = sourceStage.sourceSpliterator;
        sourceStage.sourceSpliterator = null;
    }
    else if (sourceStage.sourceSupplier != null) {
        spliterator = (Spliterator<?>) sourceStage.sourceSupplier.get();
        sourceStage.sourceSupplier = null;
    }
    else {
        throw new IllegalStateException(MSG_CONSUMED);
    }

    if (isParallel() && sourceStage.sourceAnyStateful) {
        // Adapt the source spliterator, evaluating each stateful op
        // in the pipeline up to and including this pipeline stage.
        // The depth and flags of each pipeline stage are adjusted accordingly.
        int depth = 1;
        for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this;
             u != e;
             u = p, p = p.nextStage) {

            int thisOpFlags = p.sourceOrOpFlags;
            if (p.opIsStateful()) {
                depth = 0;

                if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) {
                    // Clear the short circuit flag for next pipeline stage
                    // This stage encapsulates short-circuiting, the next
                    // stage may not have any short-circuit operations, and
                    // if so spliterator.forEachRemaining should be used
                    // for traversal
                    thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT;
                }

                spliterator = p.opEvaluateParallelLazy(u, spliterator);

                // Inject or clear SIZED on the source pipeline stage
                // based on the stage's spliterator
                thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED)
                        ? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED
                        : (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED;
            }
            p.depth = depth++;
            p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags);
        }
    }

    if (terminalFlags != 0)  {
        // Apply flags from the terminal operation to last pipeline stage
        combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags);
    }

    return spliterator;
}
 
源代码16 项目: jdk8u-jdk   文件: AbstractPipeline.java
/**
 * Get the source spliterator for this pipeline stage.  For a sequential or
 * stateless parallel pipeline, this is the source spliterator.  For a
 * stateful parallel pipeline, this is a spliterator describing the results
 * of all computations up to and including the most recent stateful
 * operation.
 */
@SuppressWarnings("unchecked")
private Spliterator<?> sourceSpliterator(int terminalFlags) {
    // Get the source spliterator of the pipeline
    Spliterator<?> spliterator = null;
    if (sourceStage.sourceSpliterator != null) {
        spliterator = sourceStage.sourceSpliterator;
        sourceStage.sourceSpliterator = null;
    }
    else if (sourceStage.sourceSupplier != null) {
        spliterator = (Spliterator<?>) sourceStage.sourceSupplier.get();
        sourceStage.sourceSupplier = null;
    }
    else {
        throw new IllegalStateException(MSG_CONSUMED);
    }

    if (isParallel() && sourceStage.sourceAnyStateful) {
        // Adapt the source spliterator, evaluating each stateful op
        // in the pipeline up to and including this pipeline stage.
        // The depth and flags of each pipeline stage are adjusted accordingly.
        int depth = 1;
        for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this;
             u != e;
             u = p, p = p.nextStage) {

            int thisOpFlags = p.sourceOrOpFlags;
            if (p.opIsStateful()) {
                depth = 0;

                if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) {
                    // Clear the short circuit flag for next pipeline stage
                    // This stage encapsulates short-circuiting, the next
                    // stage may not have any short-circuit operations, and
                    // if so spliterator.forEachRemaining should be used
                    // for traversal
                    thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT;
                }

                spliterator = p.opEvaluateParallelLazy(u, spliterator);

                // Inject or clear SIZED on the source pipeline stage
                // based on the stage's spliterator
                thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED)
                        ? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED
                        : (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED;
            }
            p.depth = depth++;
            p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags);
        }
    }

    if (terminalFlags != 0)  {
        // Apply flags from the terminal operation to last pipeline stage
        combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags);
    }

    return spliterator;
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: AbstractPipeline.java
/**
 * Get the source spliterator for this pipeline stage.  For a sequential or
 * stateless parallel pipeline, this is the source spliterator.  For a
 * stateful parallel pipeline, this is a spliterator describing the results
 * of all computations up to and including the most recent stateful
 * operation.
 */
@SuppressWarnings("unchecked")
private Spliterator<?> sourceSpliterator(int terminalFlags) {
    // Get the source spliterator of the pipeline
    Spliterator<?> spliterator = null;
    if (sourceStage.sourceSpliterator != null) {
        spliterator = sourceStage.sourceSpliterator;
        sourceStage.sourceSpliterator = null;
    }
    else if (sourceStage.sourceSupplier != null) {
        spliterator = (Spliterator<?>) sourceStage.sourceSupplier.get();
        sourceStage.sourceSupplier = null;
    }
    else {
        throw new IllegalStateException(MSG_CONSUMED);
    }

    if (isParallel() && sourceStage.sourceAnyStateful) {
        // Adapt the source spliterator, evaluating each stateful op
        // in the pipeline up to and including this pipeline stage.
        // The depth and flags of each pipeline stage are adjusted accordingly.
        int depth = 1;
        for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this;
             u != e;
             u = p, p = p.nextStage) {

            int thisOpFlags = p.sourceOrOpFlags;
            if (p.opIsStateful()) {
                depth = 0;

                if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) {
                    // Clear the short circuit flag for next pipeline stage
                    // This stage encapsulates short-circuiting, the next
                    // stage may not have any short-circuit operations, and
                    // if so spliterator.forEachRemaining should be used
                    // for traversal
                    thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT;
                }

                spliterator = p.opEvaluateParallelLazy(u, spliterator);

                // Inject or clear SIZED on the source pipeline stage
                // based on the stage's spliterator
                thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED)
                        ? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED
                        : (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED;
            }
            p.depth = depth++;
            p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags);
        }
    }

    if (terminalFlags != 0)  {
        // Apply flags from the terminal operation to last pipeline stage
        combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags);
    }

    return spliterator;
}
 
源代码18 项目: openjdk-jdk8u   文件: AbstractPipeline.java
/**
 * Get the source spliterator for this pipeline stage.  For a sequential or
 * stateless parallel pipeline, this is the source spliterator.  For a
 * stateful parallel pipeline, this is a spliterator describing the results
 * of all computations up to and including the most recent stateful
 * operation.
 */
@SuppressWarnings("unchecked")
private Spliterator<?> sourceSpliterator(int terminalFlags) {
    // Get the source spliterator of the pipeline
    Spliterator<?> spliterator = null;
    if (sourceStage.sourceSpliterator != null) {
        spliterator = sourceStage.sourceSpliterator;
        sourceStage.sourceSpliterator = null;
    }
    else if (sourceStage.sourceSupplier != null) {
        spliterator = (Spliterator<?>) sourceStage.sourceSupplier.get();
        sourceStage.sourceSupplier = null;
    }
    else {
        throw new IllegalStateException(MSG_CONSUMED);
    }

    if (isParallel() && sourceStage.sourceAnyStateful) {
        // Adapt the source spliterator, evaluating each stateful op
        // in the pipeline up to and including this pipeline stage.
        // The depth and flags of each pipeline stage are adjusted accordingly.
        int depth = 1;
        for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this;
             u != e;
             u = p, p = p.nextStage) {

            int thisOpFlags = p.sourceOrOpFlags;
            if (p.opIsStateful()) {
                depth = 0;

                if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) {
                    // Clear the short circuit flag for next pipeline stage
                    // This stage encapsulates short-circuiting, the next
                    // stage may not have any short-circuit operations, and
                    // if so spliterator.forEachRemaining should be used
                    // for traversal
                    thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT;
                }

                spliterator = p.opEvaluateParallelLazy(u, spliterator);

                // Inject or clear SIZED on the source pipeline stage
                // based on the stage's spliterator
                thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED)
                        ? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED
                        : (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED;
            }
            p.depth = depth++;
            p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags);
        }
    }

    if (terminalFlags != 0)  {
        // Apply flags from the terminal operation to last pipeline stage
        combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags);
    }

    return spliterator;
}
 
源代码19 项目: TencentKona-8   文件: AbstractPipeline.java
/**
 * Get the source spliterator for this pipeline stage.  For a sequential or
 * stateless parallel pipeline, this is the source spliterator.  For a
 * stateful parallel pipeline, this is a spliterator describing the results
 * of all computations up to and including the most recent stateful
 * operation.
 */
@SuppressWarnings("unchecked")
private Spliterator<?> sourceSpliterator(int terminalFlags) {
    // Get the source spliterator of the pipeline
    Spliterator<?> spliterator = null;
    if (sourceStage.sourceSpliterator != null) {
        spliterator = sourceStage.sourceSpliterator;
        sourceStage.sourceSpliterator = null;
    }
    else if (sourceStage.sourceSupplier != null) {
        spliterator = (Spliterator<?>) sourceStage.sourceSupplier.get();
        sourceStage.sourceSupplier = null;
    }
    else {
        throw new IllegalStateException(MSG_CONSUMED);
    }

    if (isParallel() && sourceStage.sourceAnyStateful) {
        // Adapt the source spliterator, evaluating each stateful op
        // in the pipeline up to and including this pipeline stage.
        // The depth and flags of each pipeline stage are adjusted accordingly.
        int depth = 1;
        for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this;
             u != e;
             u = p, p = p.nextStage) {

            int thisOpFlags = p.sourceOrOpFlags;
            if (p.opIsStateful()) {
                depth = 0;

                if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) {
                    // Clear the short circuit flag for next pipeline stage
                    // This stage encapsulates short-circuiting, the next
                    // stage may not have any short-circuit operations, and
                    // if so spliterator.forEachRemaining should be used
                    // for traversal
                    thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT;
                }

                spliterator = p.opEvaluateParallelLazy(u, spliterator);

                // Inject or clear SIZED on the source pipeline stage
                // based on the stage's spliterator
                thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED)
                        ? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED
                        : (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED;
            }
            p.depth = depth++;
            p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags);
        }
    }

    if (terminalFlags != 0)  {
        // Apply flags from the terminal operation to last pipeline stage
        combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags);
    }

    return spliterator;
}
 
源代码20 项目: jdk8u60   文件: AbstractPipeline.java
/**
 * Get the source spliterator for this pipeline stage.  For a sequential or
 * stateless parallel pipeline, this is the source spliterator.  For a
 * stateful parallel pipeline, this is a spliterator describing the results
 * of all computations up to and including the most recent stateful
 * operation.
 */
@SuppressWarnings("unchecked")
private Spliterator<?> sourceSpliterator(int terminalFlags) {
    // Get the source spliterator of the pipeline
    Spliterator<?> spliterator = null;
    if (sourceStage.sourceSpliterator != null) {
        spliterator = sourceStage.sourceSpliterator;
        sourceStage.sourceSpliterator = null;
    }
    else if (sourceStage.sourceSupplier != null) {
        spliterator = (Spliterator<?>) sourceStage.sourceSupplier.get();
        sourceStage.sourceSupplier = null;
    }
    else {
        throw new IllegalStateException(MSG_CONSUMED);
    }

    if (isParallel() && sourceStage.sourceAnyStateful) {
        // Adapt the source spliterator, evaluating each stateful op
        // in the pipeline up to and including this pipeline stage.
        // The depth and flags of each pipeline stage are adjusted accordingly.
        int depth = 1;
        for (@SuppressWarnings("rawtypes") AbstractPipeline u = sourceStage, p = sourceStage.nextStage, e = this;
             u != e;
             u = p, p = p.nextStage) {

            int thisOpFlags = p.sourceOrOpFlags;
            if (p.opIsStateful()) {
                depth = 0;

                if (StreamOpFlag.SHORT_CIRCUIT.isKnown(thisOpFlags)) {
                    // Clear the short circuit flag for next pipeline stage
                    // This stage encapsulates short-circuiting, the next
                    // stage may not have any short-circuit operations, and
                    // if so spliterator.forEachRemaining should be used
                    // for traversal
                    thisOpFlags = thisOpFlags & ~StreamOpFlag.IS_SHORT_CIRCUIT;
                }

                spliterator = p.opEvaluateParallelLazy(u, spliterator);

                // Inject or clear SIZED on the source pipeline stage
                // based on the stage's spliterator
                thisOpFlags = spliterator.hasCharacteristics(Spliterator.SIZED)
                        ? (thisOpFlags & ~StreamOpFlag.NOT_SIZED) | StreamOpFlag.IS_SIZED
                        : (thisOpFlags & ~StreamOpFlag.IS_SIZED) | StreamOpFlag.NOT_SIZED;
            }
            p.depth = depth++;
            p.combinedFlags = StreamOpFlag.combineOpFlags(thisOpFlags, u.combinedFlags);
        }
    }

    if (terminalFlags != 0)  {
        // Apply flags from the terminal operation to last pipeline stage
        combinedFlags = StreamOpFlag.combineOpFlags(terminalFlags, combinedFlags);
    }

    return spliterator;
}