Coverage Report - org.seasar.cubby.spi.impl.ConversionUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
ConversionUtils
87%
13/15
100%
2/2
0
 
 1  
 /*
 2  
  * Copyright 2004-2009 the Seasar Foundation and the Others.
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.spi.impl;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 /**
 22  
  * 型変換のためのユーティリティクラスです。
 23  
  * 
 24  
  * @author baba
 25  
  * @since 2.0.0
 26  
  */
 27  
 class ConversionUtils {
 28  
 
 29  1
         private static Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_MAP = new HashMap<Class<?>, Class<?>>();
 30  
 
 31  
         static {
 32  1
                 PRIMITIVE_TO_WRAPPER_MAP.put(Character.TYPE, Character.class);
 33  1
                 PRIMITIVE_TO_WRAPPER_MAP.put(Byte.TYPE, Byte.class);
 34  1
                 PRIMITIVE_TO_WRAPPER_MAP.put(Short.TYPE, Short.class);
 35  1
                 PRIMITIVE_TO_WRAPPER_MAP.put(Integer.TYPE, Integer.class);
 36  1
                 PRIMITIVE_TO_WRAPPER_MAP.put(Long.TYPE, Long.class);
 37  1
                 PRIMITIVE_TO_WRAPPER_MAP.put(Double.TYPE, Double.class);
 38  1
                 PRIMITIVE_TO_WRAPPER_MAP.put(Float.TYPE, Float.class);
 39  1
                 PRIMITIVE_TO_WRAPPER_MAP.put(Boolean.TYPE, Boolean.class);
 40  1
         }
 41  
 
 42  
         /**
 43  
      * 
 44  
      */
 45  0
         protected ConversionUtils() {
 46  0
         }
 47  
 
 48  
         /**
 49  
          * プリミティブの場合はラッパークラス、そうでない場合はもとのクラスを返します。
 50  
          * 
 51  
          * @param clazz
 52  
          * @return {@link Class}
 53  
          */
 54  
         public static Class<?> getWrapperClassIfPrimitive(final Class<?> clazz) {
 55  347
                 if (PRIMITIVE_TO_WRAPPER_MAP.containsKey(clazz)) {
 56  51
                         return PRIMITIVE_TO_WRAPPER_MAP.get(clazz);
 57  
                 } else {
 58  296
                         return clazz;
 59  
                 }
 60  
         }
 61  
 
 62  
 }