Search in sources :

Example 1 with ListResultSet

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());
        }
    };
}
Also used : InternalGroup(com.google.gerrit.entities.InternalGroup) MergeabilityComputationBehavior(com.google.gerrit.server.change.MergeabilityComputationBehavior) IndexUtils(com.google.gerrit.server.index.IndexUtils) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ProjectData(com.google.gerrit.index.project.ProjectData) ResultSet(com.google.gerrit.index.query.ResultSet) Assisted(com.google.inject.assistedinject.Assisted) Config(org.eclipse.jgit.lib.Config) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) ListResultSet(com.google.gerrit.index.query.ListResultSet) ImmutableList(com.google.common.collect.ImmutableList) AccountIndex(com.google.gerrit.server.index.account.AccountIndex) Map(java.util.Map) FieldBundle(com.google.gerrit.index.query.FieldBundle) Change(com.google.gerrit.entities.Change) Predicate(com.google.gerrit.index.query.Predicate) AccountGroup(com.google.gerrit.entities.AccountGroup) FieldDef(com.google.gerrit.index.FieldDef) Schema(com.google.gerrit.index.Schema) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Account(com.google.gerrit.entities.Account) QueryOptions(com.google.gerrit.index.QueryOptions) Instant(java.time.Instant) Index(com.google.gerrit.index.Index) ChangeField(com.google.gerrit.server.index.change.ChangeField) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SitePaths(com.google.gerrit.server.config.SitePaths) Project(com.google.gerrit.entities.Project) DataSource(com.google.gerrit.index.query.DataSource) GroupIndex(com.google.gerrit.server.index.group.GroupIndex) AccountState(com.google.gerrit.server.account.AccountState) Comparator(java.util.Comparator) ChangeIndex(com.google.gerrit.server.index.change.ChangeIndex) ListResultSet(com.google.gerrit.index.query.ListResultSet) FieldBundle(com.google.gerrit.index.query.FieldBundle) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DataSource(com.google.gerrit.index.query.DataSource) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Account (com.google.gerrit.entities.Account)1 AccountGroup (com.google.gerrit.entities.AccountGroup)1 Change (com.google.gerrit.entities.Change)1 InternalGroup (com.google.gerrit.entities.InternalGroup)1 Project (com.google.gerrit.entities.Project)1 FieldDef (com.google.gerrit.index.FieldDef)1 Index (com.google.gerrit.index.Index)1 QueryOptions (com.google.gerrit.index.QueryOptions)1 Schema (com.google.gerrit.index.Schema)1 ProjectData (com.google.gerrit.index.project.ProjectData)1 ProjectIndex (com.google.gerrit.index.project.ProjectIndex)1 DataSource (com.google.gerrit.index.query.DataSource)1 FieldBundle (com.google.gerrit.index.query.FieldBundle)1 ListResultSet (com.google.gerrit.index.query.ListResultSet)1 Predicate (com.google.gerrit.index.query.Predicate)1 ResultSet (com.google.gerrit.index.query.ResultSet)1