Coverage Report - com.timjohnstondev.unitconverter.model.ConversionFormula
 
Classes in this File Line Coverage Branch Coverage Complexity
ConversionFormula
100%
14/14
N/A
1
 
 1  
 /**
 2  
  * Copyright 2009 Timothy Johnston Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 3  
  * file except in compliance with the License. You may obtain a copy of the License at
 4  
  * 
 5  
  * http://www.apache.org/licenses/LICENSE-2.0
 6  
  * 
 7  
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 8  
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 9  
  * specific language governing permissions and limitations under the License.
 10  
  */
 11  
 
 12  
 package com.timjohnstondev.unitconverter.model;
 13  
 
 14  
 /**
 15  
  * This is a unit of measure with its related conversion formula to another unit.
 16  
  */
 17  
 public class ConversionFormula implements Conversion
 18  
 {
 19  
   private String unitName;
 20  
   private String unitSymbol;
 21  
   private String toUnitSymbol;
 22  
   private String formula;
 23  
 
 24  
   /**
 25  
    * Constructs a {@code ConversionFormula} setting its name, symbol, to-symbol and formula.
 26  
    * 
 27  
    * @param newUnitName the name of the unit in unabbreviated words
 28  
    * @param newUnitSymbol the symbol of the unit
 29  
    * @param newToUnitSymbol the symbol of the unit to be converted to
 30  
    * @param newFormula the formula to perform the conversion
 31  
    */
 32  
   public ConversionFormula(final String newUnitName, final String newUnitSymbol, final String newToUnitSymbol,
 33  
       final String newFormula)
 34  145
   {
 35  145
     unitName = newUnitName;
 36  145
     unitSymbol = newUnitSymbol;
 37  145
     toUnitSymbol = newToUnitSymbol;
 38  145
     formula = newFormula;
 39  145
   }
 40  
 
 41  
   @Override
 42  
   public final String getUnitName()
 43  
   {
 44  2
     return unitName;
 45  
   }
 46  
 
 47  
   /**
 48  
    * Returns the raw text symbol for the unit being converted to.
 49  
    * 
 50  
    * @return the unit symbol
 51  
    */
 52  
   public final String getToUnitSymbol()
 53  
   {
 54  5
     return toUnitSymbol;
 55  
   }
 56  
 
 57  
   @Override
 58  
   public final String getUnitSymbol()
 59  
   {
 60  6
     return unitSymbol;
 61  
   }
 62  
 
 63  
   @Override
 64  
   public final String getFormattedUnitSymbol()
 65  
   {
 66  3
     return unitSymbol;
 67  
   }
 68  
 
 69  
   @Override
 70  
   public final String getConversion()
 71  
   {
 72  3
     return formula;
 73  
   }
 74  
 
 75  
   @Override
 76  
   public final void setUnitSeparator(final String symbol)
 77  
   {
 78  13
     unitSymbol = unitSymbol.replaceAll("\\*", symbol);
 79  13
     toUnitSymbol = toUnitSymbol.replaceAll("\\*", symbol);
 80  13
   }
 81  
 }