Search in sources :

Example 1 with AbstractPrimitiveLongBaseIterator

use of org.neo4j.collection.PrimitiveLongCollections.AbstractPrimitiveLongBaseIterator in project neo4j by neo4j.

the class PrimitiveLongCollectionsTest method shouldNotContinueToCallNextOnHasNextFalse.

@Test
void shouldNotContinueToCallNextOnHasNextFalse() {
    // GIVEN
    AtomicLong count = new AtomicLong(2);
    LongIterator iterator = new AbstractPrimitiveLongBaseIterator() {

        @Override
        protected boolean fetchNext() {
            return count.decrementAndGet() >= 0 && next(count.get());
        }
    };
    // WHEN/THEN
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertEquals(1L, iterator.next());
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertEquals(0L, iterator.next());
    assertFalse(iterator.hasNext());
    assertFalse(iterator.hasNext());
    assertEquals(-1L, count.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LongIterator(org.eclipse.collections.api.iterator.LongIterator) AbstractPrimitiveLongBaseIterator(org.neo4j.collection.PrimitiveLongCollections.AbstractPrimitiveLongBaseIterator) Test(org.junit.jupiter.api.Test)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)1 LongIterator (org.eclipse.collections.api.iterator.LongIterator)1 Test (org.junit.jupiter.api.Test)1 AbstractPrimitiveLongBaseIterator (org.neo4j.collection.PrimitiveLongCollections.AbstractPrimitiveLongBaseIterator)1