use of com.baidu.hugegraph.iterator.LimitIterator in project hugegraph-common by hugegraph.
the class LimitIteratorTest method testNextWithOriginIteratorReturnNullElem.
@Test
public void testNextWithOriginIteratorReturnNullElem() {
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(null);
list.add(3);
Iterator<Integer> vals = list.iterator();
AtomicInteger callbackCount = new AtomicInteger(0);
Iterator<Integer> results = new LimitIterator<>(vals, val -> {
callbackCount.incrementAndGet();
return false;
});
Assert.assertTrue(results.hasNext());
for (int i = 0; i < 2; i++) {
results.next();
}
Assert.assertFalse(results.hasNext());
Assert.assertEquals(2, callbackCount.get());
}
use of com.baidu.hugegraph.iterator.LimitIterator in project hugegraph-common by hugegraph.
the class LimitIteratorTest method testLimit.
@Test
public void testLimit() {
AtomicInteger callbackCount = new AtomicInteger(0);
Iterator<Integer> values = DATA.iterator();
int limit = 2;
Function<Integer, Boolean> filter = value -> {
return callbackCount.incrementAndGet() > limit;
};
Iterator<Integer> results = new LimitIterator<>(values, filter);
List<Integer> actual = new ArrayList<>();
while (results.hasNext()) {
actual.add(results.next());
}
Assert.assertEquals(3, callbackCount.get());
Assert.assertEquals(ImmutableList.of(1, 2), actual);
}
use of com.baidu.hugegraph.iterator.LimitIterator in project incubator-hugegraph by apache.
the class HugeTraverser method edgesOfVertex.
@Watched
protected Iterator<Edge> edgesOfVertex(Id source, Directions dir, Map<Id, String> labels, long limit) {
if (labels == null || labels.isEmpty()) {
return this.edgesOfVertex(source, dir, (Id) null, limit);
}
ExtendableIterator<Edge> results = new ExtendableIterator<>();
for (Id label : labels.keySet()) {
E.checkNotNull(label, "edge label");
results.extend(this.edgesOfVertex(source, dir, label, limit));
}
if (limit == NO_LIMIT) {
return results;
}
long[] count = new long[1];
return new LimitIterator<>(results, e -> {
return count[0]++ >= limit;
});
}
Aggregations