summaryrefslogtreecommitdiffstats
path: root/config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java
Publish
Diffstat (limited to 'config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java')
-rw-r--r--config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java b/config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java
new file mode 100644
index 00000000000..789969662da
--- /dev/null
+++ b/config-lib/src/main/java/com/yahoo/config/LeafNodeMaps.java
@@ -0,0 +1,65 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.config;
+
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * @author gjoranv
+ * @since 5.1.17
+ */
+public class LeafNodeMaps {
+
+ /**
+ * Converts a map of String→NODE to String→REAL, where REAL is the underlying value type.
+ */
+ public static <NODE extends LeafNode<REAL>, REAL>
+ Map<String, REAL> asValueMap(Map<String, NODE> input)
+ {
+ Map<String, REAL> ret = new LinkedHashMap<>();
+ for(String key : input.keySet()) {
+ ret.put(key, input.get(key).value());
+ }
+ return Collections.unmodifiableMap(ret);
+ }
+
+ /**
+ * Converts a map of String→REAL to String→NODE, where REAL is the underlying value type.
+ */
+ @SuppressWarnings("unchecked")
+ public static <NODE extends LeafNode<REAL>, REAL>
+ Map<String, NODE> asNodeMap(Map<String, REAL> input, NODE defaultNode)
+ {
+ Map<String, NODE> ret = new LinkedHashMap<>();
+ for(String key : input.keySet()) {
+ NODE node = (NODE)defaultNode.clone();
+ node.value = input.get(key);
+ ret.put(key, node);
+ }
+ return Collections.unmodifiableMap(ret);
+ }
+
+
+ /**
+ * Special case for file type, since FileNode param type (FileReference) is not same as type (String) in config builder
+ */
+ public static Map<String, FileNode> asFileNodeMap(Map<String, String> stringMap) {
+ Map<String, FileNode> fileNodeMap = new LinkedHashMap<>();
+ for (Map.Entry<String, String> e : stringMap.entrySet()) {
+ fileNodeMap.put(e.getKey(), new FileNode(e.getValue()));
+ }
+ return Collections.unmodifiableMap(fileNodeMap);
+ }
+
+ public static Map<String, PathNode> asPathNodeMap(Map<String, FileReference> fileReferenceMap) {
+ Map<String, PathNode> pathNodeMap = new LinkedHashMap<>();
+ for (Map.Entry<String, FileReference> e : fileReferenceMap.entrySet()) {
+ pathNodeMap.put(e.getKey(), new PathNode(e.getValue()));
+ }
+ return Collections.unmodifiableMap(pathNodeMap);
+ }
+
+}