List of usage examples for java.lang Class getComponentType
public Class<?> getComponentType()
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Check if the given class represents an array of primitives, * i.e. boolean, byte, char, short, int, long, float, or double. * @param clazz the class to check/*from w w w . ja v a2 s.co m*/ * @return whether the given class is a primitive array class */ public static boolean isPrimitiveArray(Class clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isArray() && clazz.getComponentType().isPrimitive()); }
From source file:ArrayUtils.java
@SuppressWarnings("unchecked") private static <T, U> T[] copyOfRange(final U[] original, final int from, final int to, final Class<? extends T[]> newType) { final int newLength = to - from; if (newLength < 0) { throw new IllegalArgumentException(from + " > " + to); }// w w w . j ava2 s . co m final T[] copy = ((Object) newType == (Object) Object[].class) ? (T[]) new Object[newLength] : (T[]) Array.newInstance(newType.getComponentType(), newLength); System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength)); return copy; }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * 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/*from w ww . j a v a2s. c om*/ * @return whether the given class is a primitive wrapper array class */ public static boolean isPrimitiveWrapperArray(Class clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType())); }
From source file:com.swingtech.commons.testing.JavaBeanTester.java
private static Object buildValue(Class<?> clazz) throws InstantiationException, IllegalAccessException, IllegalArgumentException, SecurityException, InvocationTargetException { // If we are using a Mocking framework try that first... final Object mockedObject = buildMockValue(clazz); if (mockedObject != null) { return mockedObject; }//from ww w . j av a 2 s .com // Next check for a no-arg constructor final Constructor<?>[] ctrs = clazz.getConstructors(); for (Constructor<?> ctr : ctrs) { if (ctr.getParameterTypes().length == 0) { // The class has a no-arg constructor, so just call it return ctr.newInstance(); } } // Specific rules for common classes if (clazz == String.class) { return "testvalue"; } else if (clazz.isArray()) { return Array.newInstance(clazz.getComponentType(), 1); } else if (clazz == boolean.class || clazz == Boolean.class) { return true; } else if (clazz == int.class || clazz == Integer.class) { return 1; } else if (clazz == long.class || clazz == Long.class) { return 1L; } else if (clazz == double.class || clazz == Double.class) { return 1.0D; } else if (clazz == float.class || clazz == Float.class) { return 1.0F; } else if (clazz == char.class || clazz == Character.class) { return 'Y'; // Add your own rules here } else { fail("Unable to build an instance of class " + clazz.getName() + ", please add some code to the " + JavaBeanTester.class.getName() + " class to do this."); return null; // for the compiler } }
From source file:com.gzj.tulip.jade.rowmapper.ArrayRowMapper.java
public ArrayRowMapper(Class<?> returnType) { this.componentType = returnType.getComponentType(); }
From source file:com.bstek.dorado.data.entity.EntityUtils.java
/** * ???/*from ww w . j ava 2 s. co m*/ */ public static boolean isSimpleType(Class<?> cl) { boolean b = (String.class.equals(cl) || cl.isPrimitive() || Boolean.class.equals(cl) || Number.class.isAssignableFrom(cl) || cl.isEnum() || Date.class.isAssignableFrom(cl) || Character.class.isAssignableFrom(cl)); if (!b && cl.isArray()) { b = isSimpleType(cl.getComponentType()); } return b; }
From source file:org.apache.hadoop.hive.metastore.VerifyingObjectStore.java
private static void dumpObject(StringBuilder errorStr, String name, Object p, Class<?> c, int level) throws IllegalAccessException { String offsetStr = repeat(" ", level); if (p == null || c == String.class || c.isPrimitive() || ClassUtils.wrapperToPrimitive(c) != null) { errorStr.append(offsetStr).append(name + ": [" + p + "]\n"); } else if (ClassUtils.isAssignable(c, Iterable.class)) { errorStr.append(offsetStr).append(name + " is an iterable\n"); Iterator<?> i1 = ((Iterable<?>) p).iterator(); int i = 0; while (i1.hasNext()) { Object o1 = i1.next(); Class<?> t = o1 == null ? Object.class : o1.getClass(); // ... dumpObject(errorStr, name + "[" + (i++) + "]", o1, t, level + 1); }/*from ww w . ja v a2 s . c o m*/ } else if (c.isArray()) { int len = Array.getLength(p); Class<?> t = c.getComponentType(); errorStr.append(offsetStr).append(name + " is an array\n"); for (int i = 0; i < len; ++i) { dumpObject(errorStr, name + "[" + i + "]", Array.get(p, i), t, level + 1); } } else if (ClassUtils.isAssignable(c, Map.class)) { Map<?, ?> c1 = (Map<?, ?>) p; errorStr.append(offsetStr).append(name + " is a map\n"); dumpObject(errorStr, name + ".keys", c1.keySet(), Set.class, level + 1); dumpObject(errorStr, name + ".vals", c1.values(), Collection.class, level + 1); } else { errorStr.append(offsetStr).append(name + " is of type " + c.getCanonicalName() + "\n"); // TODO: this doesn't include superclass. Field[] fields = c.getDeclaredFields(); AccessibleObject.setAccessible(fields, true); for (int i = 0; i < fields.length; i++) { Field f = fields[i]; if (f.getName().indexOf('$') != -1 || Modifier.isStatic(f.getModifiers())) continue; dumpObject(errorStr, name + "." + f.getName(), f.get(p), f.getType(), level + 1); } } }
From source file:com.feilong.commons.core.lang.ClassUtil.java
/** * class info map for log./*from w w w . j a v a 2s . 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:info.novatec.testit.livingdoc.converter.ArrayConverter.java
protected boolean isArray(Class<?> type) { return type.getComponentType() != null; }
From source file:com.laxser.blitz.web.paramresolver.ResolverFactoryImpl.java
private static boolean addIndexAliasParamNameIfNeccessary(ParamMetaData metaData) { Class<?>[] paramTypes = metaData.getMethod().getParameterTypes(); int index = metaData.getIndex(); // index0 int uriParamIndex = 0; // uriParamIndex**1** int breakIndex = 0;// breakIndex0 for (; breakIndex < paramTypes.length && breakIndex <= index; breakIndex++) { Class<?> type = paramTypes[breakIndex]; if (type.isArray()) { type = type.getComponentType(); } else if (Collection.class.isAssignableFrom(type)) { Class<?>[] generics = compileGenericParameterTypesDetail(metaData.getMethod(), breakIndex); if (generics == null) { return false; }/*from w w w. ja v a 2 s .c o m*/ Assert.isTrue(generics.length > 0); type = generics[0]; } if (ClassUtils.isPrimitiveOrWrapper(type) || type == String.class || Date.class.isAssignableFrom(type)) { uriParamIndex++; } } if ((breakIndex - 1) == index && uriParamIndex > 0) { String alias = "$" + uriParamIndex; metaData.addAliasParamName(alias); if (logger.isDebugEnabled()) { logger.debug("add index alias paramName: '" + alias + "' for " + metaData.getControllerClass().getName() + "." + metaData.getMethod().getName() + "(..." + metaData.getParamType() + "[index=" + breakIndex + "] ...)"); } return true; } return false; }