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 * Integer configuration option24 */25publicclassIntConfOptionextendsAbstractConfOption {
26/** Default value */27privatefinalint defaultValue;
2829/**30 * Constructor31 *32 * @param key key33 * @param defaultValue default value34 * @param description configuration description35 */36publicIntConfOption(String key, int defaultValue, String description) {
37super(key, description);
38this.defaultValue = defaultValue;
39 }
4041/**42 * Constructor43 *44 * @param key key45 * @param defaultValue default value46 * @param description configuration description47 */48publicIntConfOption(String key, long defaultValue, String description) {
49super(key, description);
50this.defaultValue = (int) defaultValue;
51 }
5253publicint getDefaultValue() {
54return defaultValue;
55 }
5657 @Override publicboolean isDefaultValue(Configuration conf) {
58return get(conf) == defaultValue;
59 }
6061 @Override public String getDefaultValueStr() {
62return Integer.toString(defaultValue);
63 }
6465 @Override publicConfOptionType getType() {
66return ConfOptionType.INTEGER;
67 }
6869/**70 * Lookup value71 *72 * @param conf Configuration73 * @return value for key, or default value if not set74 */75publicint get(Configuration conf) {
76return conf.getInt(getKey(), defaultValue);
77 }
7879/**80 * Set value81 *82 * @param conf Configuration83 * @param value to set84 */85publicvoid set(Configuration conf, int value) {
86 conf.setInt(getKey(), value);
87 }
8889/**90 * Set value if it's not already present91 *92 * @param conf Configuration93 * @param value to set94 */95publicvoid setIfUnset(Configuration conf, int value) {
96if (!contains(conf)) {
97 conf.setInt(getKey(), value);
98 }
99 }
100 }