Coverage Report - net.sf.ezmorph.primitive.AbstractIntegerMorpher
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractIntegerMorpher
93%
14/15
100%
2/2
1.333
 
 1  
 /*
 2  
  * Copyright 2006-2007 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package net.sf.ezmorph.primitive;
 18  
 
 19  
 import java.util.Locale;
 20  
 
 21  
 /**
 22  
  * Base class por primitive integer conversion.
 23  
  *
 24  
  * @author Andres Almiray <aalmiray@users.sourceforge.net>
 25  
  */
 26  
 public abstract class AbstractIntegerMorpher extends AbstractPrimitiveMorpher
 27  
 {
 28  
    public AbstractIntegerMorpher()
 29  
    {
 30  828
       super();
 31  828
    }
 32  
 
 33  
    /**
 34  
     * @param useDefault if morph() should return a default value if the value to
 35  
     *        be morphed is null
 36  
     */
 37  
    public AbstractIntegerMorpher( boolean useDefault )
 38  
    {
 39  2775
       super( useDefault );
 40  2775
    }
 41  
 
 42  
    /**
 43  
     * Trims the String from the begining to the first "."
 44  
     */
 45  
    protected String getIntegerValue( Object obj )
 46  
    {
 47  
       // use en_US Locale
 48  367
       Locale defaultLocale = Locale.getDefault();
 49  367
       String str = null;
 50  
       try{
 51  367
          Locale.setDefault( Locale.US );
 52  367
          str = String.valueOf( obj );
 53  
       }
 54  0
       finally{
 55  367
          Locale.setDefault( defaultLocale );
 56  91
       }
 57  
 
 58  367
       int index = str.indexOf( "." );
 59  367
       if( index != -1 ){
 60  80
          str = str.substring( 0, index );
 61  
       }
 62  367
       return str;
 63  
    }
 64  
 }