SystemProperty.java
1.51 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 fi.codecrew.moya.utilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Gather all system properties in here as enums, so we have some kind of
* understanding what kind of properties there are.
*
* @author tuomari
*
*/
public enum SystemProperty {
MOYA_IRC_SERVER,
MOYA_IRC_CHANNEL("#moya-debug"),
MOYA_IRC_SERVERPASS(),
;
private final String defaultValue;
private final Integer defaultIntegerValue;
private static final Logger logger = LoggerFactory.getLogger(SystemProperty.class);
private SystemProperty() {
defaultValue = null;
defaultIntegerValue = null;
}
private SystemProperty(String value) {
defaultValue = value;
defaultIntegerValue = null;
}
private SystemProperty(Integer value) {
defaultIntegerValue = value;
defaultValue = null;
}
public String getDefaultValue() {
return defaultValue;
}
public String getValueOrDefault() {
String val = System.getProperty(this.name());
if (val == null) {
val = defaultValue;
}
return val;
}
public Integer getIntvalueOrDefault() {
String val = System.getProperty(this.name());
Integer intval = null;
try {
intval = Integer.parseInt(val);
} catch (Throwable t) {
intval = null;
logger.warn("Unable to parse system property '{}' value '{}' as integer. Defaulting to {}", name(), val, defaultIntegerValue);
}
if (val == null) {
intval = defaultIntegerValue;
}
return intval;
}
public String getValueOrNull() {
String val = System.getProperty(this.name());
return val;
}
}