List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:Main.java
public static boolean isAssignableFrom(Class<?> toClass, Class<?> fromClass) { if (toClass == Object.class && !fromClass.isPrimitive()) { return true; }//from ww w . j av a2 s. co m if (toClass.isPrimitive()) { fromClass = getPrimitiveClassIfWrapper(fromClass); } return toClass.isAssignableFrom(fromClass); }
From source file:Main.java
/** * <p>Converts the specified primitive Class object to its corresponding * wrapper Class object.</p>//from www.j a va 2 s. com * * <p>NOTE: From v2.2, this method handles <code>Void.TYPE</code>, * returning <code>Void.TYPE</code>.</p> * * @param cls the class to convert, may be null * @return the wrapper class for <code>cls</code> or <code>cls</code> if * <code>cls</code> is not a primitive. <code>null</code> if null input. * @since 2.1 */ public static Class primitiveToWrapper(Class cls) { Class convertedClass = cls; if (cls != null && cls.isPrimitive()) { convertedClass = (Class) primitiveWrapperMap.get(cls); } return convertedClass; }
From source file:Main.java
/** * <p>Converts the specified primitive Class object to its corresponding * wrapper Class object.</p>// w w w.j ava 2 s . co m * * <p>NOTE: From v2.2, this method handles {@code Void.TYPE}, * returning {@code Void.TYPE}.</p> * * @param cls the class to convert, may be null * @return the wrapper class for {@code cls} or {@code cls} if * {@code cls} is not a primitive. {@code null} if null input. * @since 2.1 */ public static Class<?> primitiveToWrapper(Class<?> cls) { Class<?> convertedClass = cls; if (cls != null && cls.isPrimitive()) { convertedClass = primitiveWrapperMap.get(cls); } return convertedClass; }
From source file:com.magnet.max.android.util.TypeUtil.java
/** * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * * @param type// w ww.j a v a 2s. co m * The class to query or null. * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * @since 3.1 */ public static boolean isPrimitiveOrWrapper(final Class<?> type) { return type != null && (type.isPrimitive() || isPrimitiveWrapper(type)); }
From source file:Main.java
public static boolean isSerializable(Object obj) { Class<?> clz = obj.getClass(); return clz.isPrimitive() || primitives.contains(clz) || obj instanceof String || obj instanceof Map || obj instanceof JSONArray || obj instanceof JSONObject; }
From source file:Main.java
/** * Get a list of the name of variables of the class received * @param klass Class to get the variable names * @return List<String>[] of length 3 with variable names: [0]: primitives, [1]: arrays, [2]: objects */// ww w. j a va2 s .c o m public static List<String>[] getVariableNames(Class klass) { //array to return List<String>[] varNames = new List[3]; for (int i = 0; i < 3; i++) { varNames[i] = new ArrayList<>(); } //add all valid fields do { Field[] fields = klass.getDeclaredFields(); for (Field field : fields) { if (!Modifier.isTransient(field.getModifiers())) { //get the type Class type = field.getType(); if (type.isPrimitive() || (type == Integer.class) || (type == Float.class) || (type == Double.class) || (type == Boolean.class) || (type == String.class)) { varNames[0].add(field.getName()); } else if (type.isArray()) { varNames[1].add(field.getName()); } else { varNames[2].add(field.getName()); } } } klass = klass.getSuperclass(); } while (klass != null); //return array return varNames; }
From source file:Main.java
public static boolean isTypeCompatibleWithArgumentType(Class<?> actual, Class<?> formal) { if (actual.isPrimitive() && formal.isPrimitive()) { return isConvertible(actual, formal); } else if (actual.isPrimitive()) { return isConvertible(actual, convertToPrimitiveType(formal)); } else if (formal.isPrimitive()) { return isConvertible(convertToPrimitiveType(actual), formal); } else {// w w w . j a v a 2 s . c om return formal.isAssignableFrom(actual); } }
From source file:Main.java
/** * <p>/* w w w . j ava2 s . c om*/ * Converts the specified primitive Class object to its corresponding * wrapper Class object. * </p> * * <p> * NOTE: From v2.2, this method handles {@code Void.TYPE}, returning * {@code Void.TYPE}. * </p> * * @param cls * the class to convert, may be null * @return the wrapper class for {@code cls} or {@code cls} if {@code cls} * is not a primitive. {@code null} if null input. * @since 2.1 */ public static Class<?> primitiveToWrapper(final Class<?> cls) { Class<?> convertedClass = cls; if (cls != null && cls.isPrimitive()) { convertedClass = PRIMITIVE_WRAPPER_MAP.get(cls); } return convertedClass; }
From source file:Main.java
/** * Determines whether specified type is supported as attributes data or for text-based * node property./*from w w w. j ava 2 s.c om*/ * @param type Type that needs to be checked. * @return true if and only if type is supported as attributed type. */ public static boolean isSupportedAttributeClass(Class<?> type) { if (type == null) throw new NullPointerException("Type can not be null."); if (type.isPrimitive()) return true; return (supportedAttrTypes.contains(type)); }
From source file:Main.java
/** * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * /*from w w w. j a v a 2 s. com*/ * @param type * The class to query or null. * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * @since 3.1 */ public static boolean isPrimitiveOrWrapper(Class<?> type) { if (type == null) { return false; } return type.isPrimitive() || isPrimitiveWrapper(type); }