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;
2122import com.google.common.base.Objects;
23import com.google.common.collect.Lists;
2425import java.util.List;
2627/**28 * String Configuration option29 */30publicclassStrConfOptionextendsAbstractConfOption {
31/** Default value */32privatefinal String defaultValue;
3334/**35 * Constructor36 *37 * @param key key38 * @param defaultValue default value39 * @param description configuration description40 */41publicStrConfOption(String key, String defaultValue, String description) {
42super(key, description);
43this.defaultValue = defaultValue;
44 }
4546public String getDefaultValue() {
47return defaultValue;
48 }
4950 @Override publicboolean isDefaultValue(Configuration conf) {
51return Objects.equal(get(conf), defaultValue);
52 }
5354 @Override public String getDefaultValueStr() {
55return defaultValue;
56 }
5758 @Override publicConfOptionType getType() {
59return ConfOptionType.STRING;
60 }
6162/**63 * Lookup value64 *65 * @param conf Configuration66 * @return value for key, or defaultValue67 */68public String get(Configuration conf) {
69return conf.get(getKey(), defaultValue);
70 }
7172/**73 * Lookup value with user defined defaultValue74 *75 * @param conf Configuration76 * @param defaultVal default value to use77 * @return value for key, or defaultVal passed in78 */79public String getWithDefault(Configuration conf, String defaultVal) {
80return conf.get(getKey(), defaultVal);
81 }
8283/**84 * Get array of values for key85 *86 * @param conf Configuration87 * @return array of values for key88 */89public String[] getArray(Configuration conf) {
90return conf.getStrings(getKey(), defaultValue);
91 }
9293/**94 * Get list of values for key95 *96 * @param conf Configuration97 * @return list of values for key98 */99public List<String> getList(Configuration conf) {
100return Lists.newArrayList(getArray(conf));
101 }
102103/**104 * Set value for key105 *106 * @param conf Configuration107 * @param value to set108 */109publicvoid set(Configuration conf, String value) {
110 conf.set(getKey(), value);
111 }
112113/**114 * Set value if not already present115 *116 * @param conf Configuration117 * @param value to set118 */119publicvoid setIfUnset(Configuration conf, String value) {
120 conf.setIfUnset(getKey(), value);
121 }
122 }