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 * Float Configuration option24 */25publicclassFloatConfOptionextendsAbstractConfOption {
26/** Default value */27privatefinalfloat defaultValue;
2829/**30 * Constructor31 *32 * @param key Configuration key33 * @param defaultValue default value34 * @param description configuration description35 */36publicFloatConfOption(String key, float defaultValue, String description) {
37super(key, description);
38this.defaultValue = defaultValue;
39 }
4041publicfloat getDefaultValue() {
42return defaultValue;
43 }
4445 @Override publicboolean isDefaultValue(Configuration conf) {
46return Float.compare(get(conf), defaultValue) == 0;
47 }
4849 @Override public String getDefaultValueStr() {
50return Float.toString(defaultValue);
51 }
5253 @Override publicConfOptionType getType() {
54return ConfOptionType.FLOAT;
55 }
5657/**58 * Lookup value59 *60 * @param conf Configuration61 * @return value for key, or defaultValue if not present62 */63publicfloat get(Configuration conf) {
64return conf.getFloat(getKey(), defaultValue);
65 }
6667/**68 * Set value69 *70 * @param conf Configuration71 * @param value to set72 */73publicvoid set(Configuration conf, float value) {
74 conf.setFloat(getKey(), value);
75 }
7677/**78 * Set value if it's not already present79 *80 * @param conf Configuration81 * @param value to set82 */83publicvoid setIfUnset(Configuration conf, float value) {
84if (!contains(conf)) {
85 conf.setFloat(getKey(), value);
86 }
87 }
88 }