Java Reflection Primitive isPrimitiveWrapperArray(Class clazz)

Here you can find the source of isPrimitiveWrapperArray(Class clazz)

Description

Check if the given class represents an array of primitive wrappers, i.e.

License

Apache License

Parameter

Parameter Description
clazz the class to check

Return

whether the given class is a primitive wrapper array class

Declaration

public static boolean isPrimitiveWrapperArray(Class clazz) 

Method Source Code

//package com.java2s;
/**//ww  w.ja v  a2 s  .c  o m
 *
 * Copyright 2008-2009 (C) The original author or authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**
     * Map with primitive wrapper type as key and corresponding primitive
     * type as value, for example: Integer.class -> int.class.
     */
    private static final Map primitiveWrapperTypeMap = new HashMap(8);

    /**
     * Check if the given class represents an array of primitive wrappers,
     * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
     *
     * @param clazz the class to check
     * @return whether the given class is a primitive wrapper array class
     */
    public static boolean isPrimitiveWrapperArray(Class clazz) {
        if (clazz == null)
            throw new IllegalArgumentException("Class must not be null");
        return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType()));
    }

    /**
     * Check if the given class represents a primitive wrapper,
     * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
     *
     * @param clazz the class to check
     * @return whether the given class is a primitive wrapper class
     */
    public static boolean isPrimitiveWrapper(Class clazz) {
        if (clazz == null)
            throw new IllegalArgumentException("Class must not be null");
        return primitiveWrapperTypeMap.containsKey(clazz);
    }
}

Related

  1. isPrimitiveOrWrapper(final Class type)
  2. isPrimitiveWrapper(Class clazz)
  3. isPrimitiveWrapper(Class clazz)
  4. isPrimitiveWrapper(Class klass)
  5. isPrimitiveWrapper(final Class type)
  6. isPrimitiveWrapperClass(Class primitiveWrapperClass)
  7. isWrapper(Class clazz)
  8. isWrapper(Class dataType)
  9. isWrapperAndPrimitivePair(Class c1, Class c2)