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 import org.apache.log4j.Logger;
22
23 import com.google.common.base.Objects;
24 import com.google.common.collect.ComparisonChain;
25
26
27
28
29 public abstract class AbstractConfOption
30 implements Comparable<AbstractConfOption> {
31
32 private static final Logger LOG = Logger.getLogger(AbstractConfOption.class);
33
34
35 private final String key;
36
37
38 private final String description;
39
40
41
42
43
44
45
46 public AbstractConfOption(String key, String description) {
47 this.key = key;
48 this.description = description;
49 }
50
51 public String getKey() {
52 return key;
53 }
54
55
56
57
58 public String getDescription() {
59 return description;
60 }
61
62
63
64
65
66
67
68 public boolean contains(Configuration conf) {
69 return conf.get(key) != null;
70 }
71
72 @Override public int compareTo(AbstractConfOption o) {
73 return ComparisonChain.start()
74 .compare(getType(), o.getType())
75 .compare(key, o.key)
76 .result();
77 }
78
79 @Override
80 public boolean equals(Object o) {
81 if (this == o) {
82 return true;
83 }
84 if (!(o instanceof AbstractConfOption)) {
85 return false;
86 }
87
88 AbstractConfOption that = (AbstractConfOption) o;
89 return Objects.equal(getType(), that.getType()) &&
90 Objects.equal(key, that.key);
91 }
92
93 @Override
94 public int hashCode() {
95 return Objects.hashCode(key);
96 }
97
98 @Override public String toString() {
99 StringBuilder sb = new StringBuilder(30);
100 sb.append(" ").append(key).append(" => ").append(getDefaultValueStr());
101 sb.append(" (").append(getType().toString().toLowerCase()).append(")\n");
102 return sb.toString();
103 }
104
105
106
107
108
109
110
111 public abstract boolean isDefaultValue(Configuration conf);
112
113
114
115
116
117
118 public abstract String getDefaultValueStr();
119
120
121
122
123
124
125 public abstract ConfOptionType getType();
126 }