Coverage Report - ca.uhn.hl7v2.model.DataTypeUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
DataTypeUtil
84%
16/19
83%
5/6
2.333
 
 1  
 /**
 2  
  * The contents of this file are subject to the Mozilla Public License Version 1.1
 3  
  * (the "License"); you may not use this file except in compliance with the License.
 4  
  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 5  
  * Software distributed under the License is distributed on an "AS IS" basis,
 6  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
 7  
  * specific language governing rights and limitations under the License.
 8  
  *
 9  
  * The Original Code is "DataTypeUtil.java".  Description:
 10  
  * "This class is used to provide utility functions for other datatype classes and methods."
 11  
  *
 12  
  * The Initial Developer of the Original Code is University Health Network. Copyright (C)
 13  
  * 2001.  All Rights Reserved.
 14  
  *
 15  
  * Contributor(s): ______________________________________.
 16  
  *
 17  
  * Alternatively, the contents of this file may be used under the terms of the
 18  
  * GNU General Public License (the "GPL"), in which case the provisions of the GPL are
 19  
  * applicable instead of those above.  If you wish to allow use of your version of this
 20  
  * file only under the terms of the GPL and not to allow others to use your version
 21  
  * of this file under the MPL, indicate your decision by deleting  the provisions above
 22  
  * and replace  them with the notice and other provisions required by the GPL License.
 23  
  * If you do not delete the provisions above, a recipient may use your version of
 24  
  * this file under either the MPL or the GPL.
 25  
  *
 26  
  */
 27  
 
 28  
 package ca.uhn.hl7v2.model;
 29  
 
 30  
 import java.util.*;
 31  
 
 32  
 /**
 33  
  * This class is used to provide utility functions for other datatype classes and methods.
 34  
  */
 35  
 
 36  
 public class DataTypeUtil {
 37  
     
 38  0
     public DataTypeUtil() {
 39  0
     }//end zero arg constructor
 40  
     
 41  
     
 42  
     /**
 43  
      * This method will preappend the zeros to the beginning of num such that the total length
 44  
      * equals totalDigitLength. It will also return the string representation of the new number.
 45  
      */
 46  
     public static String preAppendZeroes(int num, int totalDigitLength){
 47  
     /* preappend the zeros to the beginning of num such that the total length
 48  
      equals totalDigitLength. Return the string representation of the new number*/
 49  3383
         String a = String.valueOf(num);
 50  3383
         if (a.length() >= totalDigitLength)
 51  815
             return a;
 52  
         else {
 53  2568
             int preAppendAmnt = totalDigitLength - a.length();
 54  5450
             for (int j=0; j < preAppendAmnt; j++){
 55  2882
                 a = "0"+a;
 56  
             }//end for
 57  2568
             return a;
 58  
         }//end else
 59  
     }//end method
 60  
     
 61  
     
 62  
     /**
 63  
      * This method will return a signed four digit integer indicating the local
 64  
      * GMT offset. This is the HL7 Offset format in integer representation.
 65  
      */
 66  
     public static int getLocalGMTOffset(){
 67  
         int offSet;
 68  2
         GregorianCalendar currentTime = new GregorianCalendar();
 69  2
         int gmtOffSet = currentTime.get(GregorianCalendar.ZONE_OFFSET);
 70  
         int offSetSignInt;
 71  2
         if (gmtOffSet < 0 ){
 72  2
             offSetSignInt = -1;
 73  
         }
 74  
         else{
 75  0
             offSetSignInt = 1;
 76  
         }
 77  
         //get the absolute value of the gmtOffSet
 78  2
         int absGmtOffSet = Math.abs(gmtOffSet);
 79  2
         int gmtOffSetHours = absGmtOffSet/(3600*1000);
 80  2
         int gmtOffSetMin = (absGmtOffSet / 60000) % (60);
 81  
         //return the offset value HL7 format
 82  2
         offSet = ((gmtOffSetHours*100)+gmtOffSetMin) * offSetSignInt;
 83  2
         return offSet;        
 84  
     }//end method
 85  
     
 86  
     
 87  
 }//end class
 88