blob: d71439ebb9a7b47bac0d7009065268f980d2365b (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;
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(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()));
}
}
|