View Javadoc

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   */
26  class ConversionUtils {
27  
28  	private static Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_MAP = new HashMap<Class<?>, Class<?>>();
29  
30  	static {
31  		PRIMITIVE_TO_WRAPPER_MAP.put(Character.TYPE, Character.class);
32  		PRIMITIVE_TO_WRAPPER_MAP.put(Byte.TYPE, Byte.class);
33  		PRIMITIVE_TO_WRAPPER_MAP.put(Short.TYPE, Short.class);
34  		PRIMITIVE_TO_WRAPPER_MAP.put(Integer.TYPE, Integer.class);
35  		PRIMITIVE_TO_WRAPPER_MAP.put(Long.TYPE, Long.class);
36  		PRIMITIVE_TO_WRAPPER_MAP.put(Double.TYPE, Double.class);
37  		PRIMITIVE_TO_WRAPPER_MAP.put(Float.TYPE, Float.class);
38  		PRIMITIVE_TO_WRAPPER_MAP.put(Boolean.TYPE, Boolean.class);
39  	}
40  
41  	/**
42       * 
43       */
44  	protected ConversionUtils() {
45  	}
46  
47  	/**
48  	 * プリミティブの場合はラッパークラス、そうでない場合はもとのクラスを返します。
49  	 * 
50  	 * @param clazz
51  	 * @return {@link Class}
52  	 */
53  	public static Class<?> getWrapperClassIfPrimitive(final Class<?> clazz) {
54  		if (PRIMITIVE_TO_WRAPPER_MAP.containsKey(clazz)) {
55  			return PRIMITIVE_TO_WRAPPER_MAP.get(clazz);
56  		} else {
57  			return clazz;
58  		}
59  	}
60  
61  }