Search in sources :

Example 1 with CloseableIterator

use of org.apache.tinkerpop.gremlin.structure.util.CloseableIterator in project janusgraph by JanusGraph.

the class CloseableIteratorUtilsTest method testFilter.

@Test
public void testFilter() {
    MutableBoolean closed = new MutableBoolean(false);
    Iterator<Integer> raw = IntStream.range(0, 10).iterator();
    CloseableIterator<Integer> unfiltered = new CloseableIterator<Integer>() {

        @Override
        public boolean hasNext() {
            return raw.hasNext();
        }

        @Override
        public Integer next() {
            return raw.next();
        }

        @Override
        public void close() {
            closed.setTrue();
        }
    };
    CloseableIterator iterator = CloseableIteratorUtils.filter(unfiltered, num -> num % 2 == 0);
    for (int i = 0; i < 10; i += 2) {
        assertEquals(i, iterator.next());
    }
    assertFalse(closed.getValue());
    assertFalse(iterator.hasNext());
    assertTrue(closed.getValue());
}
Also used : CloseableIterator(org.apache.tinkerpop.gremlin.structure.util.CloseableIterator) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.jupiter.api.Test)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 CloseableIterator (org.apache.tinkerpop.gremlin.structure.util.CloseableIterator)1 Test (org.junit.jupiter.api.Test)1