Coverage Report - org.apache.giraph.conf.FloatConfOption
 
Classes in this File Line Coverage Branch Coverage Complexity
FloatConfOption
0%
0/13
0%
0/4
1.125
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * 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 and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.giraph.conf;
 19  
 
 20  
 import org.apache.hadoop.conf.Configuration;
 21  
 
 22  
 /**
 23  
  * Float Configuration option
 24  
  */
 25  
 public class FloatConfOption extends AbstractConfOption {
 26  
   /** Default value */
 27  
   private final float defaultValue;
 28  
 
 29  
   /**
 30  
    * Constructor
 31  
    *
 32  
    * @param key Configuration key
 33  
    * @param defaultValue default value
 34  
    * @param description configuration description
 35  
    */
 36  
   public FloatConfOption(String key, float defaultValue, String description) {
 37  0
     super(key, description);
 38  0
     this.defaultValue = defaultValue;
 39  0
   }
 40  
 
 41  
   public float getDefaultValue() {
 42  0
     return defaultValue;
 43  
   }
 44  
 
 45  
   @Override public boolean isDefaultValue(Configuration conf) {
 46  0
     return Float.compare(get(conf), defaultValue) == 0;
 47  
   }
 48  
 
 49  
   @Override public String getDefaultValueStr() {
 50  0
     return Float.toString(defaultValue);
 51  
   }
 52  
 
 53  
   @Override public ConfOptionType getType() {
 54  0
     return ConfOptionType.FLOAT;
 55  
   }
 56  
 
 57  
   /**
 58  
    * Lookup value
 59  
    *
 60  
    * @param conf Configuration
 61  
    * @return value for key, or defaultValue if not present
 62  
    */
 63  
   public float get(Configuration conf) {
 64  0
     return conf.getFloat(getKey(), defaultValue);
 65  
   }
 66  
 
 67  
   /**
 68  
    * Set value
 69  
    *
 70  
    * @param conf Configuration
 71  
    * @param value to set
 72  
    */
 73  
   public void set(Configuration conf, float value) {
 74  0
     conf.setFloat(getKey(), value);
 75  0
   }
 76  
 
 77  
   /**
 78  
    * Set value if it's not already present
 79  
    *
 80  
    * @param conf Configuration
 81  
    * @param value to set
 82  
    */
 83  
   public void setIfUnset(Configuration conf, float value) {
 84  0
     if (!contains(conf)) {
 85  0
       conf.setFloat(getKey(), value);
 86  
     }
 87  0
   }
 88  
 }