List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:org.ext4spring.parameter.DefaultParameterResolver.java
private Class<?> resolveParameterType(Method method) { Class<?> type = method.getReturnType(); if (type.isPrimitive()) { return this.typeMap.get(type.getName()); } else {/*from w w w. j av a 2s.c o m*/ return type; } }
From source file:de.alpharogroup.lang.ClassExtensions.java
/** * Gets the {@link ClassType} from the given class. * * @param clazz/*w w w . j a v a2 s. co m*/ * The class. * @return the {@link ClassType} from the given class. */ public static ClassType getClassType(final Class<?> clazz) { if (clazz.isArray()) { return ClassType.ARRAY; } if (isCollection(clazz)) { return ClassType.COLLECTION; } if (isMap(clazz)) { return ClassType.MAP; } if (clazz.isLocalClass()) { return ClassType.LOCAL; } if (clazz.isMemberClass()) { return ClassType.MEMBER; } if (clazz.isPrimitive()) { return ClassType.PRIMITIVE; } if (clazz.isAnnotation()) { return ClassType.ANNOTATION; } if (clazz.isEnum()) { return ClassType.ENUM; } if (clazz.isInterface()) { return ClassType.INTERFACE; } if (clazz.isSynthetic()) { return ClassType.SYNTHETIC; } if (clazz.isAnonymousClass()) { return ClassType.ANONYMOUS; } return ClassType.DEFAULT; }
From source file:com.sinosoft.one.data.jade.statement.JdbcStatement.java
public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters, Querier querier) {/*w w w .j a v a2 s .com*/ this.metaData = statementMetaData; this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters; this.querier = querier; this.sqlType = sqlType; if (sqlType == SQLType.WRITE) { Method method = statementMetaData.getMethod(); Class<?>[] types = method.getParameterTypes(); Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } if (types.length > 0 && List.class.isAssignableFrom(types[0])) { this.batchUpdate = true; if (returnType != void.class && returnType != int[].class && returnType != Integer[].class && returnType != Integer.class) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } else { this.batchUpdate = false; if (returnType != void.class && returnType != Boolean.class && !Number.class.isAssignableFrom(returnType)) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } } else { this.batchUpdate = false; } }
From source file:net.paoding.rose.jade.statement.JdbcStatement.java
public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters, Querier querier) {// www. j a v a2 s . com this.metaData = statementMetaData; this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters; this.querier = querier; this.sqlType = sqlType; if (sqlType == SQLType.WRITE) { Method method = statementMetaData.getMethod(); Class<?>[] types = method.getParameterTypes(); Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } if (types.length > 0 && List.class.isAssignableFrom(types[0])) { this.batchUpdate = true; if (returnType != void.class && returnType != int[].class && returnType != Integer[].class && returnType != Integer.class) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } else { this.batchUpdate = false; if (Number.class.isAssignableFrom(returnType)) { throw new IllegalArgumentException("error return type:" + method.getDeclaringClass().getName() + "#" + method.getName() + "-->" + returnType); } } } else { this.batchUpdate = false; } }
From source file:ca.oson.json.util.ObjectUtil.java
public static boolean isMapOrObject(Class valueType) { if (valueType == null) { // no idea, just assume return true; }// w w w . j a va 2s . c o m if (Map.class.isAssignableFrom(valueType)) { return true; } if (valueType.isPrimitive() || valueType.isEnum()) { return false; } if (Number.class.isAssignableFrom(valueType) || Date.class.isAssignableFrom(valueType)) { return false; } if (isArrayOrCollection(valueType)) { return false; } if (valueType == String.class || valueType == Character.class || valueType == Boolean.class) { return false; } return true; }
From source file:edu.umich.flowfence.client.QuarentineModule.java
private static <T> Class<? extends T> checkClass(String className, Class<T> clazz, ClassLoader loader) throws ClassNotFoundException { Class<?> resultClazz; if ("void".equals(className)) { if ("void".equals(clazz.getName())) { return clazz; } else if ("java.lang.Void".equals(clazz.getName())) { return clazz; } else {//from w w w .j a va 2s . c o m throw new ClassCastException("Void type in non-void context"); } } resultClazz = ClassUtils.getClass(loader, className, true); // Special handling for primitives. // If we can be handled by one of the primitive conversions, allow it. if (resultClazz.isPrimitive()) { if (ClassUtils.isAssignable(resultClazz, clazz, true)) { return clazz; } else { throw new ClassCastException("Cannot convert " + className + " to " + clazz.getName()); } } return resultClazz.asSubclass(clazz); }
From source file:com.weibo.api.motan.config.AbstractConfig.java
private boolean isPrimitive(Class<?> type) { return type.isPrimitive() || type == String.class || type == Character.class || type == Boolean.class || type == Byte.class || type == Short.class || type == Integer.class || type == Long.class || type == Float.class || type == Double.class; }
From source file:com.gzj.tulip.jade.statement.UpdateQuerier.java
public UpdateQuerier(DataAccessFactory dataAccessFactory, StatementMetaData metaData) { this.dataAccessFactory = dataAccessFactory; // ?//w w w. jav a2 s . c o m Class<?> returnType = metaData.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } this.returnType = returnType; this.returnGeneratedKeys = metaData.getReturnGeneratedKeys(); }
From source file:com.adobe.acs.commons.util.impl.ValueMapTypeConverter.java
private Object handleArrayProperty(Class<?> clazz) { // handle case of primitive/wrapper arrays Class<?> componentType = clazz.getComponentType(); if (componentType.isPrimitive()) { Class<?> wrapper = ClassUtils.primitiveToWrapper(componentType); if (wrapper != componentType) { Object wrapperArray = getValueFromMap(Array.newInstance(wrapper, 0).getClass()); if (wrapperArray != null) { return unwrapArray(wrapperArray, componentType); }//from ww w. j av a 2 s . c o m } } else { Object wrapperArray = getValueFromMap(Array.newInstance(componentType, 0).getClass()); if (wrapperArray != null) { return unwrapArray(wrapperArray, componentType); } } return null; }
From source file:net.yck.wkrdb.common.shared.PropertyConverter.java
/** * Performs a data type conversion from the specified value object to the * given target data class. If additional information is required for this * conversion, it is obtained from {@code DefaultConversionHandler.INSTANCE} * object. If the class is a primitive type (Integer.TYPE, Boolean.TYPE, * etc), the value returned will use the wrapper type (Integer.class, * Boolean.class, etc)./* w ww .j ava2s. c o m*/ * * @param cls * the target class of the converted value * @param value * the value to convert * @return the converted value * @throws ConversionException * if the value is not compatible with the requested type */ public static Object to(Class<?> cls, Object value) throws ConversionException { if (cls.isInstance(value)) { return value; // no conversion needed } if (String.class.equals(cls)) { return String.valueOf(value); } if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) { return toBoolean(value); } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) { return toCharacter(value); } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) { if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) { return toInteger(value); } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) { return toLong(value); } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) { return toByte(value); } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) { return toShort(value); } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) { return toFloat(value); } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) { return toDouble(value); } else if (BigInteger.class.equals(cls)) { return toBigInteger(value); } else if (BigDecimal.class.equals(cls)) { return toBigDecimal(value); } } else if (Date.class.equals(cls)) { return toDate(value, DefaultConversionHandler.INSTANCE.getDateFormat()); } else if (Calendar.class.equals(cls)) { return toCalendar(value, DefaultConversionHandler.INSTANCE.getDateFormat()); } else if (URL.class.equals(cls)) { return toURL(value); } else if (Locale.class.equals(cls)) { return toLocale(value); } else if (isEnum(cls)) { return convertToEnum(cls, value); } else if (Color.class.equals(cls)) { return toColor(value); } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) { return toInternetAddress(value); } else if (InetAddress.class.isAssignableFrom(cls)) { return toInetAddress(value); } throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")" + " can't be converted to a " + cls.getName() + " object"); }