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;
2122/**23 * Long configuration option24 */25publicclassLongConfOptionextendsAbstractConfOption {
26/** Default value */27privatelong defaultValue;
2829/**30 * Constructor31 *32 * @param key key33 * @param defaultValue default value34 * @param description configuration description35 */36publicLongConfOption(String key, long defaultValue, String description) {
37super(key, description);
38this.defaultValue = defaultValue;
39 }
4041publiclong getDefaultValue() {
42return defaultValue;
43 }
4445 @Override publicboolean isDefaultValue(Configuration conf) {
46return get(conf) == defaultValue;
47 }
4849 @Override public String getDefaultValueStr() {
50return Long.toString(defaultValue);
51 }
5253 @Override publicConfOptionType getType() {
54return ConfOptionType.LONG;
55 }
5657/**58 * Lookup value59 *60 * @param conf Configuration61 * @return value set for key, or defaultValue62 */63publiclong get(Configuration conf) {
64return conf.getLong(getKey(), defaultValue);
65 }
6667/**68 * Lookup value, use passed in default value if not found.69 *70 * @param conf Configuration71 * @param val default value to use72 * @return set for key, or default value passed in73 */74publiclong getWithDefault(Configuration conf, long val) {
75return conf.getLong(getKey(), val);
76 }
7778/**79 * Set value for key80 *81 * @param conf Configuration82 * @param value to set83 */84publicvoid set(Configuration conf, long value) {
85 conf.setLong(getKey(), value);
86 }
8788/**89 * Set value if it's not already present90 *91 * @param conf Configuration92 * @param value to set93 */94publicvoid setIfUnset(Configuration conf, long value) {
95if (!contains(conf)) {
96 conf.setLong(getKey(), value);
97 }
98 }
99 }