summaryrefslogtreecommitdiffstats
path: root/java/com/google/gerrit/index/IndexDefinition.java
blob: f283bf17390869f6565d8cc1356ed6308da9999f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.index;

import com.google.common.collect.ImmutableSortedMap;
import com.google.gerrit.common.Nullable;

/**
 * Definition of an index over a Gerrit data type.
 *
 * <p>An <em>index</em> includes a set of schema definitions along with the specific implementations
 * used to query the secondary index implementation in a running server. If you are just interested
 * in the static definition of one or more schemas, see the implementations of {@link
 * SchemaDefinitions}.
 */
public abstract class IndexDefinition<K, V, I extends Index<K, V>> {
  public interface IndexFactory<K, V, I extends Index<K, V>> {
    I create(Schema<V> schema);
  }

  private final SchemaDefinitions<V> schemaDefs;
  private final IndexCollection<K, V, I> indexCollection;
  private final IndexFactory<K, V, I> indexFactory;
  private final SiteIndexer<K, V, I> siteIndexer;

  protected IndexDefinition(
      SchemaDefinitions<V> schemaDefs,
      IndexCollection<K, V, I> indexCollection,
      IndexFactory<K, V, I> indexFactory,
      @Nullable SiteIndexer<K, V, I> siteIndexer) {
    this.schemaDefs = schemaDefs;
    this.indexCollection = indexCollection;
    this.indexFactory = indexFactory;
    this.siteIndexer = siteIndexer;
  }

  public final String getName() {
    return schemaDefs.getName();
  }

  public final ImmutableSortedMap<Integer, Schema<V>> getSchemas() {
    return schemaDefs.getSchemas();
  }

  public final Schema<V> getLatest() {
    return schemaDefs.getLatest();
  }

  public final IndexCollection<K, V, I> getIndexCollection() {
    return indexCollection;
  }

  public final IndexFactory<K, V, I> getIndexFactory() {
    return indexFactory;
  }

  @Nullable
  public final SiteIndexer<K, V, I> getSiteIndexer() {
    return siteIndexer;
  }
}