// 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 { 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 toUrlReferences(List urlNodes) { return urlNodes.stream().map(UrlNode::getUrlReference).collect(Collectors.toList()); } public static Map toUrlReferenceMap(Map urlNodeMap) { return urlNodeMap.entrySet().stream().collect( Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getUrlReference())); } }