aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/IndexFactsFactory.java
blob: 482c9e3c6ba36bc842ede32b542cbe9a0bbebf7e (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude;

import com.yahoo.config.subscription.ConfigGetter;
import com.yahoo.config.ConfigInstance;
import com.yahoo.search.config.IndexInfoConfig;
import com.yahoo.container.QrSearchersConfig;

/**
 * @author Simon Thoresen Hult
 */
public abstract class IndexFactsFactory {

    public static IndexFacts newInstance(String configId) {
        return new IndexFacts(new IndexModel(resolveConfig(IndexInfoConfig.class, configId),
                                             resolveConfig(QrSearchersConfig.class, configId)));

    }

    public static IndexFacts newInstance(String indexInfoConfigId, String qrSearchersConfigId) {
        return new IndexFacts(new IndexModel(resolveConfig(IndexInfoConfig.class, indexInfoConfigId),
                                             resolveConfig(QrSearchersConfig.class, qrSearchersConfigId)));

    }

    @SuppressWarnings("deprecation")
    private static <T extends ConfigInstance> T resolveConfig(Class<T> configClass, String configId) {
        if (configId == null) return null;
        return ConfigGetter.getConfig(configClass, configId);
    }

}