Here you can find the source of isNumber(Class> type)
Parameter | Description |
---|---|
type | a parameter |
public static boolean isNumber(Class<?> type)
//package com.java2s; import java.util.*; public class Main { private static Map<String, Class<?>> primitives = initializePrimitives(); private static Map<Class<?>, Class<?>> primToNonPrim = initializePrimToNonPrim(); /**/*from www . j av a2 s . com*/ * @param type * @return whether the input type is a number class or a number primitive. */ public static boolean isNumber(Class<?> type) { if (type == null) { return false; } Class<?> forPrim = classForPrimitive(type); if (forPrim != null) { type = forPrim; } return (Number.class.isAssignableFrom(type)); } public static Class<?> classForPrimitive(Class<?> primClass) { return getPrimToNonPrim().get(primClass); } public static Class<?> classForPrimitive(String primClass) { return getPrimitives().get(primClass); } public static Map<Class<?>, Class<?>> getPrimToNonPrim() { if (primToNonPrim == null) { initializePrimToNonPrim(); } return primToNonPrim; } public static Map<String, Class<?>> getPrimitives() { if (primitives == null) { initializePrimitives(); } return primitives; } private static Map<Class<?>, Class<?>> initializePrimToNonPrim() { primToNonPrim = new HashMap<Class<?>, Class<?>>(); primToNonPrim.put(boolean.class, Boolean.class); primToNonPrim.put(byte.class, Byte.class); primToNonPrim.put(char.class, Character.class); primToNonPrim.put(short.class, Short.class); primToNonPrim.put(int.class, Integer.class); primToNonPrim.put(long.class, Long.class); primToNonPrim.put(float.class, Float.class); primToNonPrim.put(double.class, Double.class); primToNonPrim.put(void.class, Void.class); return primToNonPrim; } private static Map<String, Class<?>> initializePrimitives() { primitives = new TreeMap<String, Class<?>>(); for (Class<?> c : getPrimToNonPrim().keySet()) { primitives.put(c.getSimpleName(), c); } // primitives.put( "boolean", boolean.class ); // primitives.put( "byte", byte.class ); // primitives.put( "char", char.class ); // primitives.put( "short", short.class ); // primitives.put( "int", int.class ); // primitives.put( "long", long.class ); // primitives.put( "float", float.class ); // primitives.put( "double", double.class ); // primitives.put( "void", void.class ); return primitives; } }