aboutsummaryrefslogtreecommitdiffstats
path: root/config-lib/src/main/java/com/yahoo/config/PathNode.java
blob: 1cdd354941bbe924bacaa152a4e34391fc53d773 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright Vespa.ai. 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.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
 */
public class PathNode extends LeafNode<Path> {

    private final FileReference fileReference;

    public PathNode() {
        fileReference = null;
    }

    public PathNode(FileReference fileReference) {
        super(true);
        this.value = Path.of(fileReference.value());
        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(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;
    }

}