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());
}
Aggregations