Coverage Report - org.dozer.converters.IntegerConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
IntegerConverter
100%
8/8
100%
6/6
6
 
 1  
 /**
 2  
  * Copyright 2005-2013 Dozer Project
 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  
 package org.dozer.converters;
 17  
 
 18  
 import org.apache.commons.beanutils.Converter;
 19  
 import org.dozer.util.MappingUtils;
 20  
 
 21  
 /**
 22  
  * Internal class for converting Supported Data Types --> Integer. Only intended for internal use.
 23  
  * 
 24  
  * @author tierney.matt
 25  
  */
 26  2
 public class IntegerConverter implements Converter {
 27  
 
 28  1
   private static org.apache.commons.beanutils.converters.IntegerConverter commonsConverter = new org.apache.commons.beanutils.converters.IntegerConverter();
 29  
 
 30  
   @SuppressWarnings("rawtypes")
 31  
   public Object convert(Class destClass, Object srcObj) {
 32  
     // Boolean to Int not supported in apache common's int converter and this is why this class is req'd
 33  850
     if (Boolean.class.isAssignableFrom(srcObj.getClass())) {
 34  6
       boolean value = (Boolean) srcObj;
 35  6
       return (value ? 1 : 0);
 36  844
     } else if (MappingUtils.isEnumType(srcObj.getClass())) {
 37  4
       return ((Enum) srcObj).ordinal();
 38  
     } else {
 39  840
       return commonsConverter.convert(destClass, srcObj);
 40  
     }
 41  
   }
 42  
 
 43  
 }