1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18package org.apache.giraph.conf;
1920import org.apache.hadoop.conf.Configuration;
21import org.apache.log4j.Logger;
2223import com.google.common.base.Objects;
24import com.google.common.collect.ComparisonChain;
2526/**27 * Abstract base class of configuration options28 */29publicabstractclassAbstractConfOption30implements Comparable<AbstractConfOption> {
31/** Logger */32privatestaticfinal Logger LOG = Logger.getLogger(AbstractConfOption.class);
3334/** Key for configuration */35privatefinal String key;
3637/** Configuration option description */38privatefinal String description;
3940/**41 * Constructor42 *43 * @param key configuration key44 * @param description configuration description45 */46publicAbstractConfOption(String key, String description) {
47this.key = key;
48this.description = description;
49 }
5051public String getKey() {
52return key;
53 }
5455/**56 * @return the description57 */58public String getDescription() {
59return description;
60 }
6162/**63 * Check if option is set in configuration64 *65 * @param conf Configuration66 * @return true if option is set67 */68publicboolean contains(Configuration conf) {
69return conf.get(key) != null;
70 }
7172 @Override publicint compareTo(AbstractConfOption o) {
73return ComparisonChain.start()
74 .compare(getType(), o.getType())
75 .compare(key, o.key)
76 .result();
77 }
7879 @Override
80publicboolean equals(Object o) {
81if (this == o) {
82returntrue;
83 }
84if (!(o instanceof AbstractConfOption)) {
85return false;
86 }
8788AbstractConfOption that = (AbstractConfOption) o;
89return Objects.equal(getType(), that.getType()) &&
90 Objects.equal(key, that.key);
91 }
9293 @Override
94publicint hashCode() {
95return Objects.hashCode(key);
96 }
9798 @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");
102return sb.toString();
103 }
104105/**106 * Check if the value set is the same as the default value107 *108 * @param conf Configuration109 * @return true if value set is default value110 */111publicabstractboolean isDefaultValue(Configuration conf);
112113/**114 * Get string representation of default value115 *116 * @return String117 */118publicabstract String getDefaultValueStr();
119120/**121 * Get type this option holds122 *123 * @return ConfOptionType124 */125publicabstractConfOptionType getType();
126 }