SingletonPrimitiveSpliteratorOfInt implements Spliterator.OfInt { @Override public boolean tryAdvance(IntConsumer consumer) { Objects.requireNonNull(consumer); if (estimatedSize > 0) { estimatedSize--; consumer.accept(element); return true; } return false; } SingletonPrimitiveSpliteratorOfInt(int element); @Override OfInt trySplit(); @Override boolean tryAdvance(IntConsumer consumer); @Override void forEachRemaining(IntConsumer consumer); @Override long estimateSize(); @Override int characteristics();  }
@Test void tryAdvanceIntConsumer() { assertTrue(instance.tryAdvance((IntConsumer) i -> cnt.incrementAndGet())); assertEquals(1, cnt.get()); }
@Test void tryAdvanceConsumer() { assertTrue(instance.tryAdvance((Consumer<Integer>) i -> cnt.incrementAndGet())); assertEquals(1, cnt.get()); }
@Test void tryAdvanceIntConsumerAfterAdvance() { instance.tryAdvance((IntConsumer) i -> {}); assertFalse(instance.tryAdvance((IntConsumer) i -> cnt.incrementAndGet())); assertEquals(0, cnt.get()); }
@Test void tryAdvanceConsumerAfterAdvance() { instance.tryAdvance((Consumer<Integer>) i -> {}); assertFalse(instance.tryAdvance((Consumer<Integer>) i -> cnt.incrementAndGet())); assertEquals(0, cnt.get()); }