diff options
Diffstat (limited to 'config-lib/src/main/java/com/yahoo/config/UrlNode.java')
-rw-r--r-- | config-lib/src/main/java/com/yahoo/config/UrlNode.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/config-lib/src/main/java/com/yahoo/config/UrlNode.java b/config-lib/src/main/java/com/yahoo/config/UrlNode.java new file mode 100644 index 00000000000..0ed70ce0f50 --- /dev/null +++ b/config-lib/src/main/java/com/yahoo/config/UrlNode.java @@ -0,0 +1,65 @@ +// Copyright 2018 Yahoo Holdings. 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.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Represents a 'url' in a {@link ConfigInstance}, which will be downloaded + * and made available as a {@link File}. Stored in the config builder as a + * {@link UrlReference} to identify fields of this type for special handling + * in the ConfigPayloadApplier. + * + * @author lesters + */ +public class UrlNode extends LeafNode<File> { + + private final UrlReference url; + + public UrlNode() { + url = null; + } + + public UrlNode(UrlReference url) { + super(true); + this.url = url; + this.value = new File(url.value()); + } + + public File value() { + return value; + } + + @Override + public String toString() { + return (value == null) ? "(null)" : '"' + getValue() + '"'; + } + + @Override + public String getValue() { + return value.toString(); + } + + @Override + protected boolean doSetValue(@NonNull String value) { + throw new UnsupportedOperationException("doSetValue should not be necessary since the library anymore!"); + } + + public UrlReference getUrlReference() { + return url; + } + + public static List<UrlReference> toUrlReferences(List<UrlNode> urlNodes) { + return urlNodes.stream().map(UrlNode::getUrlReference).collect(Collectors.toList()); + } + + public static Map<String, UrlReference> toUrlReferenceMap(Map<String, UrlNode> urlNodeMap) { + return urlNodeMap.entrySet().stream().collect( + Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getUrlReference())); + } + +} |