diff options
author | gjoranv <gv@verizonmedia.com> | 2021-04-13 12:28:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 12:28:42 +0200 |
commit | c752d3e4bcc1946358ccdee716f4141bf87748df (patch) | |
tree | bf3ee4c16006437ac79b893cc09e1e05c8714339 /container-core/src/main/java/com/yahoo/container/di/componentgraph/core/Keys.java | |
parent | 86097c6b1e4a59cef5b9dfcdec021213520b51ac (diff) | |
parent | bbff5a9bb8854d7100b4981af9aa226d74ae0227 (diff) |
Merge pull request #17380 from vespa-engine/gjoranv/merge-di-into-core_2
Gjoranv/merge di into core 2 [run-systemtest]
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/di/componentgraph/core/Keys.java')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/di/componentgraph/core/Keys.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/Keys.java b/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/Keys.java new file mode 100644 index 00000000000..be80fc1616d --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/Keys.java @@ -0,0 +1,39 @@ +// Copyright 2018 Yahoo Holdings. 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; + } + +} |