aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileTypeRegistry.java
blob: 3c4c92275813720f18d41e7b76d666613276309f (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.profile.types;

import com.yahoo.component.ComponentId;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.search.Query;
import com.yahoo.search.query.profile.QueryProfileRegistry;

/**
 * A registry of query profile types
 *
 * @author bratseth
 */
public class QueryProfileTypeRegistry extends ComponentRegistry<QueryProfileType> {

    private int nextAnonymousId = 0;

    private final int nativeProfileCount;

    public QueryProfileTypeRegistry() {
        Query.addNativeQueryProfileTypesTo(this);
        nativeProfileCount = allComponents().size();
    }

    /** Register this type by its id */
    public void register(QueryProfileType type) {
        super.register(type.getId(), type);
    }

    /** Returns true if this has types in addition to the native Vespa types */
    public boolean hasApplicationTypes() {
        return allComponents().size() > nativeProfileCount;
    }

    @Override
    public void freeze() {
        if (isFrozen()) return;
        for (QueryProfileType queryProfileType : allComponents())
            queryProfileType.freeze();
    }

    public static QueryProfileTypeRegistry emptyFrozen() {
        QueryProfileTypeRegistry registry = new QueryProfileTypeRegistry();
        registry.freeze();
        return registry;
    }

    public ComponentId createAnonymousId(String name) {
        return ComponentId.newAnonymous(name + "_" + (nextAnonymousId++));
    }

}