当前位置: 首页>>代码示例>>Java>>正文


Java Spliterator.hasCharacteristics方法代码示例

本文整理汇总了Java中java.util.Spliterator.hasCharacteristics方法的典型用法代码示例。如果您正苦于以下问题:Java Spliterator.hasCharacteristics方法的具体用法?Java Spliterator.hasCharacteristics怎么用?Java Spliterator.hasCharacteristics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Spliterator的用法示例。


在下文中一共展示了Spliterator.hasCharacteristics方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: trySplitTestingSize

import java.util.Spliterator; //导入方法依赖的package包/类
@Nullable
private static <E> Spliterator<E> trySplitTestingSize(Spliterator<E> spliterator) {
  boolean subsized = spliterator.hasCharacteristics(Spliterator.SUBSIZED);
  long originalSize = spliterator.estimateSize();
  Spliterator<E> trySplit = spliterator.trySplit();
  if (spliterator.estimateSize() > originalSize) {
    fail(
        format(
            "estimated size of spliterator after trySplit (%s) is larger than original size (%s)",
            spliterator.estimateSize(),
            originalSize));
  }
  if (trySplit != null) {
    if (trySplit.estimateSize() > originalSize) {
      fail(
          format(
              "estimated size of trySplit result (%s) is larger than original size (%s)",
              trySplit.estimateSize(),
              originalSize));
    }
  }
  if (subsized) {
    if (trySplit != null) {
      assertEquals(
          "sum of estimated sizes of trySplit and original spliterator after trySplit",
          originalSize,
          trySplit.estimateSize() + spliterator.estimateSize());
    } else {
      assertEquals(
          "estimated size of spliterator after failed trySplit",
          originalSize,
          spliterator.estimateSize());
    }
  }
  return trySplit;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:37,代码来源:SpliteratorTester.java

示例2: testSplitUntilNull

import java.util.Spliterator; //导入方法依赖的package包/类
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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:SpliteratorTestHelper.java

示例3: assertSpliterator

import java.util.Spliterator; //导入方法依赖的package包/类
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));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:SpliteratorTestHelper.java

示例4: testSplitUntilNull

import java.util.Spliterator; //导入方法依赖的package包/类
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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:SpliteratorCollisions.java

示例5: testSplitUntilNull

import java.util.Spliterator; //导入方法依赖的package包/类
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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:SpliteratorTraversingAndSplittingTest.java

示例6: testElementRemovalDuringTraversal

import java.util.Spliterator; //导入方法依赖的package包/类
/**
 * All elements removed in the middle of CONCURRENT traversal.
 */
public void testElementRemovalDuringTraversal() {
    Collection c = impl.emptyCollection();
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    int n = rnd.nextInt(6);
    ArrayList copy = new ArrayList();
    for (int i = 0; i < n; i++) {
        Object x = impl.makeElement(i);
        copy.add(x);
        c.add(x);
    }
    ArrayList iterated = new ArrayList();
    ArrayList spliterated = new ArrayList();
    Spliterator s = c.spliterator();
    Iterator it = c.iterator();
    for (int i = rnd.nextInt(n + 1); --i >= 0; ) {
        assertTrue(s.tryAdvance(spliterated::add));
        if (rnd.nextBoolean()) assertTrue(it.hasNext());
        iterated.add(it.next());
    }
    Consumer alwaysThrows = e -> { throw new AssertionError(); };
    if (s.hasCharacteristics(Spliterator.CONCURRENT)) {
        c.clear();          // TODO: many more removal methods
        if (testImplementationDetails
            && !(c instanceof java.util.concurrent.ArrayBlockingQueue)) {
            if (rnd.nextBoolean())
                assertFalse(s.tryAdvance(alwaysThrows));
            else
                s.forEachRemaining(alwaysThrows);
        }
        if (it.hasNext()) iterated.add(it.next());
        if (rnd.nextBoolean()) assertIteratorExhausted(it);
    }
    assertTrue(copy.containsAll(iterated));
    assertTrue(copy.containsAll(spliterated));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:Collection8Test.java

示例7: testGetComparator_IllegalStateException

import java.util.Spliterator; //导入方法依赖的package包/类
/**
 * Spliterator.getComparator throws IllegalStateException iff the
 * spliterator does not report SORTED.
 */
public void testGetComparator_IllegalStateException() {
    Collection c = impl.emptyCollection();
    Spliterator s = c.spliterator();
    boolean reportsSorted = s.hasCharacteristics(Spliterator.SORTED);
    try {
        s.getComparator();
        assertTrue(reportsSorted);
    } catch (IllegalStateException ex) {
        assertFalse(reportsSorted);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Collection8Test.java

示例8: sourceSpliterator

import java.util.Spliterator; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:66,代码来源:AbstractPipeline.java


注:本文中的java.util.Spliterator.hasCharacteristics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。