forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakedConfigKey.java
More file actions
72 lines (62 loc) · 1.76 KB
/
FakedConfigKey.java
File metadata and controls
72 lines (62 loc) · 1.76 KB
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
68
69
70
71
72
package act.conf;
import act.Act;
import java.util.List;
import java.util.Map;
public enum FakedConfigKey implements ConfigKey {
GATEWAY_ENABLED("gateway.enabled"),
GATEWAY_DISABLED("gateway.disabled"),
CONN_CNT("connection.count"),
CONN_TTL("connection.ttl"),
TIMEOUT("timeout.long"),
DAYS("days.int"),
HOME_TMP("tmp.dir"),
AMOUNT("amount.float"),
SOURCE_VERSION("source.version"),
PATH("path"),
FOO("foo.bar") {
@Override
public <T> T val(Map<String, ?> configuration) {
Object v = configuration.get(key());
if (null == v) {
v = "foobar";
} else {
String s = v.toString();
if ("foo".equalsIgnoreCase(s)) {
v = "bar";
} else if ("bar".equalsIgnoreCase(s)) {
v = "foo";
} else {
v = "barfoo";
}
}
return (T)v;
}
}
;
private static ConfigKeyHelper helper = new ConfigKeyHelper(Act.F.MODE_ACCESSOR, FakedConfigKey.class.getClassLoader());
private String key;
private Object defVal;
FakedConfigKey(String key) {
this(key, null);
}
FakedConfigKey(String key, Object defVal) {
this.key = key;
this.defVal = defVal;
}
@Override
public String key() {
return key;
}
@Override
public Object defVal() {
return defVal;
}
@Override
public <T> T val(Map<String, ?> configuration) {
return helper.getConfiguration(this, configuration);
}
@Override
public <T> List<T> implList(String key, Map<String, ?> configuration, Class<T> c) {
return helper.getImplList(key, configuration, c);
}
}