Path: blob/master/src/java.desktop/share/classes/com/sun/beans/finder/PrimitiveWrapperMap.java
41161 views
/*1* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package com.sun.beans.finder;2526import java.util.HashMap;27import java.util.Map;2829/**30* This utility class associates31* name of primitive type with appropriate wrapper.32*33* @since 1.734*35* @author Sergey A. Malenkov36*/37public final class PrimitiveWrapperMap {3839/**40* Replaces all primitive types in specified array with wrappers.41*42* @param types array of classes where all primitive types43* will be replaced by appropriate wrappers44*/45static void replacePrimitivesWithWrappers(Class<?>[] types) {46for (int i = 0; i < types.length; i++) {47if (types[i] != null) {48if (types[i].isPrimitive()) {49types[i] = getType(types[i].getName());50}51}52}53}5455/**56* Returns wrapper for primitive type by its name.57*58* @param name the name of primitive type59* @return found wrapper for primitive type,60* or {@code null} if not found61*/62public static Class<?> getType(String name) {63return map.get(name);64}6566private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);6768static {69map.put(Boolean.TYPE.getName(), Boolean.class);70map.put(Character.TYPE.getName(), Character.class);71map.put(Byte.TYPE.getName(), Byte.class);72map.put(Short.TYPE.getName(), Short.class);73map.put(Integer.TYPE.getName(), Integer.class);74map.put(Long.TYPE.getName(), Long.class);75map.put(Float.TYPE.getName(), Float.class);76map.put(Double.TYPE.getName(), Double.class);77map.put(Void.TYPE.getName(), Void.class);78}7980/**81* Disable instantiation.82*/83private PrimitiveWrapperMap() {84}85}868788