當前位置: 首頁>>代碼示例>>Java>>正文


Java Spliterator.forEachRemaining方法代碼示例

本文整理匯總了Java中java.util.Spliterator.forEachRemaining方法的典型用法代碼示例。如果您正苦於以下問題:Java Spliterator.forEachRemaining方法的具體用法?Java Spliterator.forEachRemaining怎麽用?Java Spliterator.forEachRemaining使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Spliterator的用法示例。


在下文中一共展示了Spliterator.forEachRemaining方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: print

import java.util.Spliterator; //導入方法依賴的package包/類
public void print () {
	Sheet sheet =  getOrCreateSummary();
	Iterator<Row> rows = sheet.rowIterator();
	int index=0;
	while (rows.hasNext()) {
		Row row = (Row) rows.next();
		System.out.println("Row ---> " + index);
		Spliterator<Cell> cells = row.spliterator();
		cells.forEachRemaining(new Consumer<Cell> () {
			@Override
			public void accept(Cell cell) {
				System.out.print(cell.toString());
				System.out.print(";");
			}
		});
		System.out.println();
		index++;
	}
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:XLTestSummarySheet.java

示例2: testSplitAfterFullTraversal

import java.util.Spliterator; //導入方法依賴的package包/類
private static <T, S extends Spliterator<T>> void testSplitAfterFullTraversal(
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    // Full traversal using tryAdvance
    Spliterator<T> spliterator = supplier.get();
    while (spliterator.tryAdvance(boxingAdapter.apply(e -> { }))) { }
    Spliterator<T> split = spliterator.trySplit();
    assertNull(split);

    // Full traversal using forEach
    spliterator = supplier.get();
    spliterator.forEachRemaining(boxingAdapter.apply(e -> { }));
    split = spliterator.trySplit();
    assertNull(split);

    // Full traversal using tryAdvance then forEach
    spliterator = supplier.get();
    spliterator.tryAdvance(boxingAdapter.apply(e -> { }));
    spliterator.forEachRemaining(boxingAdapter.apply(e -> { }));
    split = spliterator.trySplit();
    assertNull(split);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:SpliteratorTestHelper.java

示例3: forEach

import java.util.Spliterator; //導入方法依賴的package包/類
@Override
<E> void forEach(Spliterator<E> spliterator, Consumer<? super E> consumer) {
  for (Spliterator<E> prefix = trySplitTestingSize(spliterator);
      prefix != null;
      prefix = trySplitTestingSize(spliterator)) {
    forEach(prefix, consumer);
  }
  long size = spliterator.getExactSizeIfKnown();
  long[] counter = {0};
  spliterator.forEachRemaining(e -> {
    consumer.accept(e);
    counter[0]++;
  });
  if (size >= 0) {
    assertEquals(size, counter[0]);
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:SpliteratorTester.java

示例4: testSpliterator

import java.util.Spliterator; //導入方法依賴的package包/類
static <T, S extends Spliterator<T>> void testSpliterator(Supplier<S> supplier,
                                                          UnaryOperator<Consumer<T>> boxingAdapter,
                                                          ContentAsserter<T> asserter) {
    ArrayList<T> fromForEach = new ArrayList<>();
    Spliterator<T> spliterator = supplier.get();
    Consumer<T> addToFromForEach = boxingAdapter.apply(fromForEach::add);
    spliterator.forEachRemaining(addToFromForEach);

    Collection<T> exp = Collections.unmodifiableList(fromForEach);

    testNullPointerException(supplier);
    testForEach(exp, supplier, boxingAdapter, asserter);
    testTryAdvance(exp, supplier, boxingAdapter, asserter);
    testMixedTryAdvanceForEach(exp, supplier, boxingAdapter, asserter);
    testMixedTraverseAndSplit(exp, supplier, boxingAdapter, asserter);
    testSplitAfterFullTraversal(supplier, boxingAdapter);
    testSplitOnce(exp, supplier, boxingAdapter, asserter);
    testSplitSixDeep(exp, supplier, boxingAdapter, asserter);
    testSplitUntilNull(exp, supplier, boxingAdapter, asserter);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:SpliteratorTestHelper.java

示例5: mixedTraverseAndSplit

import java.util.Spliterator; //導入方法依賴的package包/類
static<U> void mixedTraverseAndSplit(Consumer<U> b, Spliterator<U> splTop) {
    Spliterator<U> spl1, spl2, spl3;
    splTop.tryAdvance(b);
    spl2 = splTop.trySplit();
    if (spl2 != null) {
        spl2.tryAdvance(b);
        spl1 = spl2.trySplit();
        if (spl1 != null) {
            spl1.tryAdvance(b);
            spl1.forEachRemaining(b);
        }
        spl2.tryAdvance(b);
        spl2.forEachRemaining(b);
    }
    splTop.tryAdvance(b);
    spl3 = splTop.trySplit();
    if (spl3 != null) {
        spl3.tryAdvance(b);
        spl3.forEachRemaining(b);
    }
    splTop.tryAdvance(b);
    splTop.forEachRemaining(b);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:SpliteratorTestHelper.java

示例6: testSplitAfterFullTraversal

import java.util.Spliterator; //導入方法依賴的package包/類
private static <T, S extends Spliterator<T>> void testSplitAfterFullTraversal(
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    // Full traversal using tryAdvance
    Spliterator<T> spliterator = supplier.get();
    while (spliterator.tryAdvance(boxingAdapter.apply(e -> { }))) { }
    Spliterator<T> split = spliterator.trySplit();
    assertNull(split);

    // Full traversal using forEach
    spliterator = supplier.get();
    spliterator.forEachRemaining(boxingAdapter.apply(e -> {
    }));
    split = spliterator.trySplit();
    assertNull(split);

    // Full traversal using tryAdvance then forEach
    spliterator = supplier.get();
    spliterator.tryAdvance(boxingAdapter.apply(e -> { }));
    spliterator.forEachRemaining(boxingAdapter.apply(e -> {
    }));
    split = spliterator.trySplit();
    assertNull(split);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:SpliteratorCollisions.java

示例7: testStickySpliteratorExhaustion

import java.util.Spliterator; //導入方法依賴的package包/類
/**
 * Concurrent Spliterators, once exhausted, stay exhausted.
 */
public void testStickySpliteratorExhaustion() throws Throwable {
    if (!impl.isConcurrent()) return;
    if (!testImplementationDetails) return;
    final ThreadLocalRandom rnd = ThreadLocalRandom.current();
    final Consumer alwaysThrows = e -> { throw new AssertionError(); };
    final Collection c = impl.emptyCollection();
    final Spliterator s = c.spliterator();
    if (rnd.nextBoolean()) {
        assertFalse(s.tryAdvance(alwaysThrows));
    } else {
        s.forEachRemaining(alwaysThrows);
    }
    final Object one = impl.makeElement(1);
    // Spliterator should not notice added element
    c.add(one);
    if (rnd.nextBoolean()) {
        assertFalse(s.tryAdvance(alwaysThrows));
    } else {
        s.forEachRemaining(alwaysThrows);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:Collection8Test.java

示例8: testSplitOnce

import java.util.Spliterator; //導入方法依賴的package包/類
private static <T, S extends Spliterator<T>> void testSplitOnce(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter) {
    S spliterator = supplier.get();
    long sizeIfKnown = spliterator.getExactSizeIfKnown();
    boolean isOrdered = spliterator.hasCharacteristics(Spliterator.ORDERED);

    ArrayList<T> fromSplit = new ArrayList<>();
    Spliterator<T> s1 = supplier.get();
    Spliterator<T> s2 = s1.trySplit();
    long s1Size = s1.getExactSizeIfKnown();
    long s2Size = (s2 != null) ? s2.getExactSizeIfKnown() : 0;
    Consumer<T> addToFromSplit = boxingAdapter.apply(fromSplit::add);
    if (s2 != null)
        s2.forEachRemaining(addToFromSplit);
    s1.forEachRemaining(addToFromSplit);

    if (sizeIfKnown >= 0) {
        assertEquals(sizeIfKnown, fromSplit.size());
        if (s1Size >= 0 && s2Size >= 0)
            assertEquals(sizeIfKnown, s1Size + s2Size);
    }
    assertContents(fromSplit, exp, isOrdered);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:SpliteratorTraversingAndSplittingTest.java

示例9: truncate

import java.util.Spliterator; //導入方法依賴的package包/類
/**
 * Return a node describing a subsequence of the elements of this node,
 * starting at the given inclusive start offset and ending at the given
 * exclusive end offset.
 *
 * @param from The (inclusive) starting offset of elements to include, must
 *             be in range 0..count().
 * @param to The (exclusive) end offset of elements to include, must be
 *           in range 0..count().
 * @param generator A function to be used to create a new array, if needed,
 *                  for reference nodes.
 * @return the truncated node
 */
default Node<T> truncate(long from, long to, IntFunction<T[]> generator) {
    if (from == 0 && to == count())
        return this;
    Spliterator<T> spliterator = spliterator();
    long size = to - from;
    Node.Builder<T> nodeBuilder = Nodes.builder(size, generator);
    nodeBuilder.begin(size);
    for (int i = 0; i < from && spliterator.tryAdvance(e -> { }); i++) { }
    if (to == count()) {
        spliterator.forEachRemaining(nodeBuilder);
    } else {
        for (int i = 0; i < size && spliterator.tryAdvance(nodeBuilder); i++) { }
    }
    nodeBuilder.end();
    return nodeBuilder.build();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:Node.java

示例10: testCharacteristics

import java.util.Spliterator; //導入方法依賴的package包/類
@Test(dataProvider = "Source.Non.Binding.Characteristics")
public <T> void testCharacteristics(String description, Supplier<Source<T>> ss) {
    Source<T> source = ss.get();
    Spliterator<T> s = source.spliterator();

    s.characteristics();
    source.update();

    Set<T> a = new HashSet<>();
    s.forEachRemaining(a::add);

    Set<T> e = new HashSet<>();
    source.spliterator().forEachRemaining(e::add);
    assertEquals(a, e);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:SpliteratorLateBindingTest.java

示例11: copyInto

import java.util.Spliterator; //導入方法依賴的package包/類
@Override
final <P_IN> void copyInto(Sink<P_IN> wrappedSink, Spliterator<P_IN> spliterator) {
    Objects.requireNonNull(wrappedSink);

    if (!StreamOpFlag.SHORT_CIRCUIT.isKnown(getStreamAndOpFlags())) {
        wrappedSink.begin(spliterator.getExactSizeIfKnown());
        spliterator.forEachRemaining(wrappedSink);
        wrappedSink.end();
    }
    else {
        copyIntoWithCancel(wrappedSink, spliterator);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:AbstractPipeline.java

示例12: testSplitOnce

import java.util.Spliterator; //導入方法依賴的package包/類
private static <T, S extends Spliterator<T>> void testSplitOnce(
        Collection<T> exp,
        Supplier<S> supplier,
        UnaryOperator<Consumer<T>> boxingAdapter,
        ContentAsserter<T> asserter) {
    S spliterator = supplier.get();
    long sizeIfKnown = spliterator.getExactSizeIfKnown();
    boolean isOrdered = spliterator.hasCharacteristics(Spliterator.ORDERED);

    ArrayList<T> fromSplit = new ArrayList<>();
    Spliterator<T> s1 = supplier.get();
    Spliterator<T> s2 = s1.trySplit();
    long s1Size = s1.getExactSizeIfKnown();
    long s2Size = (s2 != null) ? s2.getExactSizeIfKnown() : 0;
    Consumer<T> addToFromSplit = boxingAdapter.apply(fromSplit::add);
    if (s2 != null)
        s2.forEachRemaining(addToFromSplit);
    s1.forEachRemaining(addToFromSplit);

    if (sizeIfKnown >= 0) {
        assertEquals(sizeIfKnown, fromSplit.size());
        if (s1Size >= 0 && s2Size >= 0)
            assertEquals(sizeIfKnown, s1Size + s2Size);
    }

    asserter.assertContents(fromSplit, exp, isOrdered);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:28,代碼來源:SpliteratorTestHelper.java

示例13: lateBindingTestWithForEach

import java.util.Spliterator; //導入方法依賴的package包/類
@Test(dataProvider = "Source")
public <T> void lateBindingTestWithForEach(String description, Supplier<Source<T>> ss) {
    Source<T> source = ss.get();
    Collection<T> c = source.asCollection();
    Spliterator<T> s = c.spliterator();

    source.update();

    Set<T> r = new HashSet<>();
    s.forEachRemaining(r::add);

    assertEquals(r, new HashSet<>(c));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:SpliteratorLateBindingFailFastTest.java

示例14: forEach

import java.util.Spliterator; //導入方法依賴的package包/類
@Override
<E> void forEach(Spliterator<E> spliterator, Consumer<? super E> consumer) {
  for (Spliterator<E> prefix = trySplitTestingSize(spliterator);
      prefix != null;
      prefix = trySplitTestingSize(spliterator)) {
    forEach(prefix, consumer);
  }
  spliterator.forEachRemaining(consumer);
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:10,代碼來源:SpliteratorTester.java

示例15: 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


注:本文中的java.util.Spliterator.forEachRemaining方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。