1 |
26600
|
sandro.lab
|
package eu.dnetlib.data.mapreduce;
|
2 |
|
|
|
3 |
|
|
import java.util.List;
|
4 |
|
|
|
5 |
|
|
public class OptionalConfig {
|
6 |
|
|
|
7 |
|
|
private com.typesafe.config.Config config;
|
8 |
|
|
|
9 |
|
|
public OptionalConfig(com.typesafe.config.Config config) {
|
10 |
|
|
this.config = config;
|
11 |
|
|
}
|
12 |
|
|
|
13 |
|
|
protected Object safe(String path) {
|
14 |
|
|
return config.hasPath(path) ? config.getAnyRef(path) : null;
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
public Integer getInt(String path) {
|
18 |
|
|
return (Integer) safe(path);
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
public String getString(String path) {
|
22 |
|
|
return (String) safe(path);
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
@SuppressWarnings("unchecked")
|
26 |
|
|
public <T> List<T> getList(String path) {
|
27 |
|
|
return (List<T>) safe(path);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
public Double getDouble(String path) {
|
31 |
|
|
Object safe = safe(path);
|
32 |
|
|
if (safe instanceof Integer) {
|
33 |
|
|
return Double.parseDouble(safe.toString());
|
34 |
|
|
}
|
35 |
|
|
return (Double) safe;
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
public Object getObject(String path) {
|
39 |
|
|
return safe(path);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
public Boolean getBoolean(String path) {
|
43 |
|
|
return (Boolean) safe(path);
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
public Boolean hasPath(String path) {
|
47 |
|
|
return getConfig().hasPath(path);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
public com.typesafe.config.Config getConfig() {
|
51 |
|
|
return config;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
}
|