use of com.google.gerrit.index.query.ListResultSet in project gerrit by GerritCodeReview.
the class AbstractFakeIndex method getSource.
@Override
public DataSource<V> getSource(Predicate<V> p, QueryOptions opts) {
List<V> results;
synchronized (indexedDocuments) {
results = indexedDocuments.values().stream().map(doc -> valueFor(doc)).filter(doc -> p.asMatchable().match(doc)).sorted(sortingComparator()).skip(opts.start()).limit(opts.limit()).collect(toImmutableList());
}
return new DataSource<>() {
@Override
public int getCardinality() {
return results.size();
}
@Override
public ResultSet<V> read() {
return new ListResultSet<>(results);
}
@Override
public ResultSet<FieldBundle> readRaw() {
ImmutableList.Builder<FieldBundle> fieldBundles = ImmutableList.builder();
for (V result : results) {
ImmutableListMultimap.Builder<String, Object> fields = ImmutableListMultimap.builder();
for (FieldDef<V, ?> field : getSchema().getFields().values()) {
if (field.get(result) == null) {
continue;
}
if (field.isRepeatable()) {
fields.putAll(field.getName(), (Iterable<?>) field.get(result));
} else {
fields.put(field.getName(), field.get(result));
}
}
fieldBundles.add(new FieldBundle(fields.build()));
}
return new ListResultSet<>(fieldBundles.build());
}
};
}
Aggregations