List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:org.crazydog.util.spring.ClassUtils.java
/** * Check if the given class represents a primitive (i.e. boolean, byte, * char, short, int, long, float, or double) or a primitive wrapper * (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double). * @param clazz the class to check/*from ww w. jav a2 s .c o m*/ * @return whether the given class is a primitive or primitive wrapper class */ public static boolean isPrimitiveOrWrapper(Class<?> clazz) { org.springframework.util.Assert.notNull(clazz, "Class must not be null"); return (clazz.isPrimitive() || isPrimitiveWrapper(clazz)); }
From source file:org.crazydog.util.spring.ClassUtils.java
/** * Resolve the given class if it is a primitive class, * returning the corresponding primitive wrapper type instead. * @param clazz the class to check/* ww w .j ava2 s .c o m*/ * @return the original class, or a primitive wrapper for the original primitive type */ public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) { org.springframework.util.Assert.notNull(clazz, "Class must not be null"); return (clazz.isPrimitive() && clazz != void.class ? primitiveTypeToWrapperMap.get(clazz) : clazz); }
From source file:name.ikysil.beanpathdsl.codegen.Context.java
private boolean isExcluded(Class<?> clazz) { if (clazz.isPrimitive() || clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isInterface() || clazz.isSynthetic() || clazz.isEnum() || !Modifier.isPublic(clazz.getModifiers()) || (clazz.getPackage() == null)) { return true; }//from w ww. j ava2 s . com IncludedClass includedConfig = includedClasses.get(clazz); if (includedConfig != null) { return false; } ExcludedClass excludedConfig = excludedClasses.get(clazz); if (excludedConfig != null) { return true; } for (ExcludedPackage excludedPackage : excludedPackages) { if (excludedPackage.match(clazz.getPackage())) { return true; } } return false; }
From source file:com.feilong.commons.core.lang.ClassUtil.java
/** * class info map for log./* w w w. jav a2 s . c o m*/ * * @param klass * the clz * @return the map for log */ public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) { Map<String, Object> map = new LinkedHashMap<String, Object>(); //"clz.getCanonicalName()": "com.feilong.commons.core.date.DatePattern", //"clz.getName()": "com.feilong.commons.core.date.DatePattern", //"clz.getSimpleName()": "DatePattern", // getCanonicalName ( Java Language Specification ??) && getName //??class?array? // getName[[Ljava.lang.String?getCanonicalName? map.put("clz.getCanonicalName()", klass.getCanonicalName()); map.put("clz.getName()", klass.getName()); map.put("clz.getSimpleName()", klass.getSimpleName()); map.put("clz.getComponentType()", klass.getComponentType()); // ?? voidboolean?byte?char?short?int?long?float double? map.put("clz.isPrimitive()", klass.isPrimitive()); // ??, map.put("clz.isLocalClass()", klass.isLocalClass()); // ????,?????? map.put("clz.isMemberClass()", klass.isMemberClass()); //isSynthetic()?Class????java??false?trueJVM???java?????? map.put("clz.isSynthetic()", klass.isSynthetic()); map.put("clz.isArray()", klass.isArray()); map.put("clz.isAnnotation()", klass.isAnnotation()); //??true map.put("clz.isAnonymousClass()", klass.isAnonymousClass()); map.put("clz.isEnum()", klass.isEnum()); return map; // Class<?> klass = this.getClass(); // // TypeVariable<?>[] typeParameters = klass.getTypeParameters(); // TypeVariable<?> typeVariable = typeParameters[0]; // // Type[] bounds = typeVariable.getBounds(); // // Type bound = bounds[0]; // // if (log.isDebugEnabled()){ // log.debug("" + (bound instanceof ParameterizedType)); // } // // Class<T> modelClass = ReflectUtil.getGenericModelClass(klass); // return modelClass; }
From source file:com.appleframework.core.utils.ClassUtility.java
/** * <code>fromClass</code> ???? <code>clazz</code> * <p>// ww w. j a va 2 s.co m * ??? <code>object1, object2, ...</code> ???? * <code>class1, class2, * ...</code> * </p> * <p> * * <ol> * <li> <code>clazz</code> <code>null</code> <code>false</code> * </li> * <li>? <code>fromClass</code> <code>null</code> * <code>clazz</code> ?? <code>true</code> <code>null</code> * ?</li> * <li> <code>Class.isAssignableFrom</code> ? <code>clazz</code> * ?? <code>fromClass</code> ??? <code>true</code></li> * <li> <code>clazz</code> ?? <a * href="http://java.sun.com/docs/books/jls/">The Java Language * Specification</a> sections 5.1.1, 5.1.2, 5.1.4Widening Primitive * Conversion? <code>fromClass</code> ???? * <code>clazz</code> <code>long</code> ?? <code>byte</code>? * <code>short</code>?<code>int</code>?<code>long</code>?<code>char</code> * ? <code>java.lang.Byte</code>?<code>java.lang.Short</code>? * <code>java.lang.Integer</code>? <code>java.lang.Long</code> * <code>java.lang.Character</code> ? <code>true</code></li> * <li>?? <code>false</code></li> * </ol> * </p> * * @param clazz <code>null</code> <code>false</code> * @param fromClass ? <code>null</code> ???? * @return ? <code>null</code> */ public static boolean isAssignable(Class<?> clazz, Class<?> fromClass) { if (clazz == null) { return false; } // fromClassnull??clazz??int? if (fromClass == null) { return !clazz.isPrimitive(); } // ??? if (clazz.isAssignableFrom(fromClass)) { return true; } // ??JLS // class?fromClass??? if (clazz.isPrimitive()) { return assignmentTable.get(clazz).contains(fromClass); } return false; }
From source file:com.taobao.adfs.util.Utilities.java
/** * is native primitive or java primitive type *///from w w w . j a v a 2s .c o m public static boolean isNativeOrJavaPrimitiveType(Class<?> clazz) { if (clazz.isPrimitive()) return true; if (clazz.equals(Boolean.class) || clazz.equals(Character.class) || clazz.equals(Byte.class) || clazz.equals(Short.class) || clazz.equals(Integer.class) || clazz.equals(Long.class) || clazz.equals(Float.class) || clazz.equals(Double.class) || clazz.equals(Void.class)) return true; return false; }
From source file:com.metaparadigm.jsonrpc.BeanSerializer.java
@Override public boolean canSerialize(Class clazz, Class jsonClazz) { return (!clazz.isArray() && !clazz.isPrimitive() && !clazz.isInterface() && (jsonClazz == null || jsonClazz == JSONObject.class)); }
From source file:br.com.binarti.simplesearchexpr.DefaultOperatorResolver.java
@Override public SimpleSearchRelationalOperator resolveOperator(Class<?> fieldType, String value, SimpleSearchExpressionField field) { if (String.class.isAssignableFrom(fieldType)) { return (field.getDefaultOperator() == null) ? LIKE : field.getDefaultOperator(); }/* w w w . ja va2 s . c o m*/ if (fieldType.isPrimitive()) { fieldType = ClassUtils.primitiveToWrapper(fieldType); } SimpleSearchRelationalOperator operator = (field.getDefaultOperator() == null) ? EQUALS : field.getDefaultOperator(); if (value != null) { if (Number.class.isAssignableFrom(fieldType) || Date.class.isAssignableFrom(fieldType)) { if (value.contains(INTERVAL_SEPARATOR)) { operator = INTERVAL; } } if (value.contains(LIST_SEPARATOR)) { operator = LIST; } } return operator; }
From source file:com.weibo.api.motan.proxy.RefererInvocationHandler.java
private Object getDefaultReturnValue(Class<?> returnType) { if (returnType != null && returnType.isPrimitive()) { return PrimitiveDefault.getDefaultReturnValue(returnType); }//from ww w . ja v a2 s. c o m return null; }