1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.giraph.conf;
19
20 import org.apache.hadoop.conf.Configuration;
21
22 import com.google.common.base.Objects;
23 import com.google.common.collect.Lists;
24
25 import java.util.List;
26
27
28
29
30 public class StrConfOption extends AbstractConfOption {
31
32 private final String defaultValue;
33
34
35
36
37
38
39
40
41 public StrConfOption(String key, String defaultValue, String description) {
42 super(key, description);
43 this.defaultValue = defaultValue;
44 }
45
46 public String getDefaultValue() {
47 return defaultValue;
48 }
49
50 @Override public boolean isDefaultValue(Configuration conf) {
51 return Objects.equal(get(conf), defaultValue);
52 }
53
54 @Override public String getDefaultValueStr() {
55 return defaultValue;
56 }
57
58 @Override public ConfOptionType getType() {
59 return ConfOptionType.STRING;
60 }
61
62
63
64
65
66
67
68 public String get(Configuration conf) {
69 return conf.get(getKey(), defaultValue);
70 }
71
72
73
74
75
76
77
78
79 public String getWithDefault(Configuration conf, String defaultVal) {
80 return conf.get(getKey(), defaultVal);
81 }
82
83
84
85
86
87
88
89 public String[] getArray(Configuration conf) {
90 return conf.getStrings(getKey(), defaultValue);
91 }
92
93
94
95
96
97
98
99 public List<String> getList(Configuration conf) {
100 return Lists.newArrayList(getArray(conf));
101 }
102
103
104
105
106
107
108
109 public void set(Configuration conf, String value) {
110 conf.set(getKey(), value);
111 }
112
113
114
115
116
117
118
119 public void setIfUnset(Configuration conf, String value) {
120 conf.setIfUnset(getKey(), value);
121 }
122 }