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


Java Spliterator.estimateSize方法代码示例

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


在下文中一共展示了Spliterator.estimateSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: filter

import java.util.Spliterator; //导入方法依赖的package包/类
/** Returns a {@code Spliterator} filtered by the specified predicate. */
static <T> Spliterator<T> filter(Spliterator<T> fromSpliterator, Predicate<? super T> predicate) {
  checkNotNull(fromSpliterator);
  checkNotNull(predicate);
  class Splitr implements Spliterator<T>, Consumer<T> {
    T holder = null;

    @Override
    public void accept(T t) {
      this.holder = t;
    }

    @Override
    public boolean tryAdvance(Consumer<? super T> action) {
      while (fromSpliterator.tryAdvance(this)) {
        try {
          if (predicate.test(holder)) {
            action.accept(holder);
            return true;
          }
        } finally {
          holder = null;
        }
      }
      return false;
    }

    @Override
    public Spliterator<T> trySplit() {
      Spliterator<T> fromSplit = fromSpliterator.trySplit();
      return (fromSplit == null) ? null : filter(fromSplit, predicate);
    }

    @Override
    public long estimateSize() {
      return fromSpliterator.estimateSize() / 2;
    }

    @Override
    public Comparator<? super T> getComparator() {
      return fromSpliterator.getComparator();
    }

    @Override
    public int characteristics() {
      return fromSpliterator.characteristics()
          & (Spliterator.DISTINCT
              | Spliterator.NONNULL
              | Spliterator.ORDERED
              | Spliterator.SORTED);
    }
  }
  return new Splitr();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:55,代码来源:CollectSpliterators.java

示例3: BatchingSpliterator

import java.util.Spliterator; //导入方法依赖的package包/类
private BatchingSpliterator(Spliterator<T> original, int batchSize){
	super(original.estimateSize() / batchSize, original.characteristics());
	this.original = original;
	this.batchSize = batchSize;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:6,代码来源:StreamTool.java

示例4: testSplitUntilNull

import java.util.Spliterator; //导入方法依赖的package包/类
private static <T> void testSplitUntilNull(SplitNode<T> e) {
    // Use an explicit stack to avoid a StackOverflowException when testing a Spliterator
    // that when repeatedly split produces a right-balanced (and maybe degenerate) tree, or
    // for a spliterator that is badly behaved.
    Deque<SplitNode<T>> stack = new ArrayDeque<>();
    stack.push(e);

    int iteration = 0;
    while (!stack.isEmpty()) {
        assertTrue(iteration++ < MAXIMUM_STACK_CAPACITY, "Exceeded maximum stack modification count of 1 << 18");

        e = stack.pop();
        Spliterator<T> parentAndRightSplit = e.s;

        long parentEstimateSize = parentAndRightSplit.estimateSize();
        assertTrue(parentEstimateSize >= 0,
                   String.format("Split size estimate %d < 0", parentEstimateSize));

        long parentSize = parentAndRightSplit.getExactSizeIfKnown();
        Spliterator<T> leftSplit = parentAndRightSplit.trySplit();
        if (leftSplit == null) {
            parentAndRightSplit.forEachRemaining(e.c);
            continue;
        }

        assertSpliterator(leftSplit, e.rootCharacteristics);
        assertSpliterator(parentAndRightSplit, e.rootCharacteristics);

        if (parentEstimateSize != Long.MAX_VALUE && leftSplit.estimateSize() > 0
            && parentAndRightSplit.estimateSize() > 0) {
            assertTrue(leftSplit.estimateSize() < parentEstimateSize,
                       String.format("Left split size estimate %d >= parent split size estimate %d",
                                     leftSplit.estimateSize(), parentEstimateSize));
            assertTrue(parentAndRightSplit.estimateSize() < parentEstimateSize,
                       String.format("Right split size estimate %d >= parent split size estimate %d",
                                     leftSplit.estimateSize(), parentEstimateSize));
        }
        else {
            assertTrue(leftSplit.estimateSize() <= parentEstimateSize,
                       String.format("Left split size estimate %d > parent split size estimate %d",
                                     leftSplit.estimateSize(), parentEstimateSize));
            assertTrue(parentAndRightSplit.estimateSize() <= parentEstimateSize,
                       String.format("Right split size estimate %d > parent split size estimate %d",
                                     leftSplit.estimateSize(), parentEstimateSize));
        }

        long leftSize = leftSplit.getExactSizeIfKnown();
        long rightSize = parentAndRightSplit.getExactSizeIfKnown();
        if (parentSize >= 0 && leftSize >= 0 && rightSize >= 0)
            assertEquals(parentSize, leftSize + rightSize,
                         String.format("exact left split size %d + exact right split size %d != parent exact split size %d",
                                       leftSize, rightSize, parentSize));

        // Add right side to stack first so left side is popped off first
        stack.push(e.fromSplit(parentAndRightSplit));
        stack.push(e.fromSplit(leftSplit));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:59,代码来源:SpliteratorTestHelper.java

示例5: testSplitUntilNull

import java.util.Spliterator; //导入方法依赖的package包/类
private static <T> void testSplitUntilNull(SplitNode<T> e) {
    // Use an explicit stack to avoid a StackOverflowException when testing a Spliterator
    // that when repeatedly split produces a right-balanced (and maybe degenerate) tree, or
    // for a spliterator that is badly behaved.
    Deque<SplitNode<T>> stack = new ArrayDeque<>();
    stack.push(e);

    int iteration = 0;
    while (!stack.isEmpty()) {
        assertTrue(iteration++ < MAXIMUM_STACK_CAPACITY, "Exceeded maximum stack modification count of 1 << 18");

        e = stack.pop();
        Spliterator<T> parentAndRightSplit = e.s;

        long parentEstimateSize = parentAndRightSplit.estimateSize();
        assertTrue(parentEstimateSize >= 0,
                   String.format("Split size estimate %d < 0", parentEstimateSize));

        long parentSize = parentAndRightSplit.getExactSizeIfKnown();
        Spliterator<T> leftSplit = parentAndRightSplit.trySplit();
        if (leftSplit == null) {
            parentAndRightSplit.forEachRemaining(e.c);
            continue;
        }

        assertSpliterator(leftSplit, e.rootCharacteristics);
        assertSpliterator(parentAndRightSplit, e.rootCharacteristics);

        if (parentEstimateSize != Long.MAX_VALUE && leftSplit.estimateSize() > 0 && parentAndRightSplit.estimateSize() > 0) {
            assertTrue(leftSplit.estimateSize() < parentEstimateSize,
                       String.format("Left split size estimate %d >= parent split size estimate %d", leftSplit.estimateSize(), parentEstimateSize));
            assertTrue(parentAndRightSplit.estimateSize() < parentEstimateSize,
                       String.format("Right split size estimate %d >= parent split size estimate %d", leftSplit.estimateSize(), parentEstimateSize));
        }
        else {
            assertTrue(leftSplit.estimateSize() <= parentEstimateSize,
                       String.format("Left split size estimate %d > parent split size estimate %d", leftSplit.estimateSize(), parentEstimateSize));
            assertTrue(parentAndRightSplit.estimateSize() <= parentEstimateSize,
                       String.format("Right split size estimate %d > parent split size estimate %d", leftSplit.estimateSize(), parentEstimateSize));
        }

        long leftSize = leftSplit.getExactSizeIfKnown();
        long rightSize = parentAndRightSplit.getExactSizeIfKnown();
        if (parentSize >= 0 && leftSize >= 0 && rightSize >= 0)
            assertEquals(parentSize, leftSize + rightSize,
                         String.format("exact left split size %d + exact right split size %d != parent exact split size %d",
                                       leftSize, rightSize, parentSize));

        // Add right side to stack first so left side is popped off first
        stack.push(e.fromSplit(parentAndRightSplit));
        stack.push(e.fromSplit(leftSplit));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:54,代码来源:SpliteratorCollisions.java


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