View Javadoc

1   /*
2    * Copyright 2004-2010 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  
17  package org.seasar.cubby.spi.impl;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  /**
23   * 型変換のためのユーティリティクラスです。
24   * 
25   * @author baba
26   */
27  class ConversionUtils {
28  
29  	private static Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_MAP = new HashMap<Class<?>, Class<?>>();
30  
31  	static {
32  		PRIMITIVE_TO_WRAPPER_MAP.put(Character.TYPE, Character.class);
33  		PRIMITIVE_TO_WRAPPER_MAP.put(Byte.TYPE, Byte.class);
34  		PRIMITIVE_TO_WRAPPER_MAP.put(Short.TYPE, Short.class);
35  		PRIMITIVE_TO_WRAPPER_MAP.put(Integer.TYPE, Integer.class);
36  		PRIMITIVE_TO_WRAPPER_MAP.put(Long.TYPE, Long.class);
37  		PRIMITIVE_TO_WRAPPER_MAP.put(Double.TYPE, Double.class);
38  		PRIMITIVE_TO_WRAPPER_MAP.put(Float.TYPE, Float.class);
39  		PRIMITIVE_TO_WRAPPER_MAP.put(Boolean.TYPE, Boolean.class);
40  	}
41  
42  	/**
43       * 
44       */
45  	protected ConversionUtils() {
46  	}
47  
48  	/**
49  	 * プリミティブの場合はラッパークラス、そうでない場合はもとのクラスを返します。
50  	 * 
51  	 * @param clazz
52  	 * @return {@link Class}
53  	 */
54  	public static Class<?> getWrapperClassIfPrimitive(final Class<?> clazz) {
55  		if (PRIMITIVE_TO_WRAPPER_MAP.containsKey(clazz)) {
56  			return PRIMITIVE_TO_WRAPPER_MAP.get(clazz);
57  		} else {
58  			return clazz;
59  		}
60  	}
61  
62  }