summaryrefslogtreecommitdiffstats
path: root/config-lib/src/main/java/com/yahoo/config/PathNode.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-lib/src/main/java/com/yahoo/config/PathNode.java')
-rw-r--r--config-lib/src/main/java/com/yahoo/config/PathNode.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/config-lib/src/main/java/com/yahoo/config/PathNode.java b/config-lib/src/main/java/com/yahoo/config/PathNode.java
new file mode 100644
index 00000000000..91676137214
--- /dev/null
+++ b/config-lib/src/main/java/com/yahoo/config/PathNode.java
@@ -0,0 +1,71 @@
+// 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 edu.umd.cs.findbugs.annotations.NonNull;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Represents a 'path' in a {@link ConfigInstance}, usually a filename.
+ *
+ * @author gjoranv
+ * @since 5.1.30
+ */
+public class PathNode extends LeafNode<Path> {
+
+ private final FileReference fileReference;
+
+ public PathNode() {
+ fileReference = null;
+ }
+
+ public PathNode(FileReference fileReference) {
+ super(true);
+ this.value = new File(fileReference.value()).toPath();
+ this.fileReference = fileReference;
+ }
+
+ public Path value() {
+ return value;
+ }
+
+ @Override
+ public String getValue() {
+ return value.toString();
+ }
+
+ @Override
+ public String toString() {
+ return (value == null) ? "(null)" : '"' + getValue() + '"';
+ }
+
+ @Override
+ protected boolean doSetValue(@NonNull String stringVal) {
+ throw new UnsupportedOperationException("doSetValue should not be necessary since the library anymore!");
+ }
+
+ public FileReference getFileReference() {
+ return fileReference;
+ }
+
+ public static List<FileReference> toFileReferences(List<PathNode> pathNodes) {
+ List<FileReference> fileReferences = new ArrayList<>();
+ for (PathNode pathNode : pathNodes)
+ fileReferences.add(pathNode.getFileReference());
+ return fileReferences;
+ }
+
+ public static Map<String, FileReference> toFileReferenceMap(Map<String, PathNode> map) {
+ Map<String, FileReference> ret = new LinkedHashMap<>();
+ for (Map.Entry<String, PathNode> e : map.entrySet()) {
+ ret.put(e.getKey(), e.getValue().getFileReference());
+ }
+ return ret;
+ }
+
+}