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 | 0 | public abstract class AbstractConfOption |
30 | |
implements Comparable<AbstractConfOption> { |
31 | |
|
32 | 0 | 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 | 0 | public AbstractConfOption(String key, String description) { |
47 | 0 | this.key = key; |
48 | 0 | this.description = description; |
49 | 0 | } |
50 | |
|
51 | |
public String getKey() { |
52 | 0 | return key; |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public String getDescription() { |
59 | 0 | return description; |
60 | |
} |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public boolean contains(Configuration conf) { |
69 | 0 | return conf.get(key) != null; |
70 | |
} |
71 | |
|
72 | |
@Override public int compareTo(AbstractConfOption o) { |
73 | 0 | return ComparisonChain.start() |
74 | 0 | .compare(getType(), o.getType()) |
75 | 0 | .compare(key, o.key) |
76 | 0 | .result(); |
77 | |
} |
78 | |
|
79 | |
@Override |
80 | |
public boolean equals(Object o) { |
81 | 0 | if (this == o) { |
82 | 0 | return true; |
83 | |
} |
84 | 0 | if (!(o instanceof AbstractConfOption)) { |
85 | 0 | return false; |
86 | |
} |
87 | |
|
88 | 0 | AbstractConfOption that = (AbstractConfOption) o; |
89 | 0 | return Objects.equal(getType(), that.getType()) && |
90 | 0 | Objects.equal(key, that.key); |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public int hashCode() { |
95 | 0 | return Objects.hashCode(key); |
96 | |
} |
97 | |
|
98 | |
@Override public String toString() { |
99 | 0 | StringBuilder sb = new StringBuilder(30); |
100 | 0 | sb.append(" ").append(key).append(" => ").append(getDefaultValueStr()); |
101 | 0 | sb.append(" (").append(getType().toString().toLowerCase()).append(")\n"); |
102 | 0 | 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 | |
} |