aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/Keys.java
blob: bd36cca1f63f86871d2208a61b80c598732e6b60 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.di.componentgraph.core;

import com.google.inject.Key;
import com.yahoo.config.ConfigInstance;
import com.yahoo.vespa.config.ConfigKey;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ollivir
 */
public class Keys {

    static Key<?> createKey(Type instanceType, Annotation annotation) {
        if (annotation == null) {
            return Key.get(instanceType);
        } else {
            return Key.get(instanceType, annotation);
        }
    }

    @SuppressWarnings("unchecked")
    public static Map<ConfigKey<ConfigInstance>, ConfigInstance> invariantCopy(Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> configs) {
        Map<ConfigKey<ConfigInstance>, ConfigInstance> ret = new HashMap<>();
        configs.forEach((k, v) -> ret.put((ConfigKey<ConfigInstance>) k, v));
        return ret;
    }

    public static Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> covariantCopy(Map<ConfigKey<ConfigInstance>, ConfigInstance> configs) {
        Map<ConfigKey<? extends ConfigInstance>, ConfigInstance> ret = new HashMap<>();
        configs.forEach((k, v) -> ret.put(k, v));
        return ret;
    }

}