List of usage examples for java.lang Class getComponentType
public Class<?> getComponentType()
From source file:CopyOnWriteArrayList.java
private static Object[] copyOf(Object[] original, int newLength, Class newType) { Object[] copy = (Object[]) java.lang.reflect.Array.newInstance(newType.getComponentType(), newLength); System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength)); return copy;//from w w w . j a va2 s . co m }
From source file:com.dianping.resource.io.util.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//ww w . ja v a2 s .c o 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:com.glaf.core.util.ReflectUtils.java
/** * get class desc. boolean[].class => "[Z" Object.class => * "Ljava/lang/Object;"/*from w w w . ja v a 2s. co m*/ * * @param c * class. * @return desc. * @throws NotFoundException */ public static String getDesc(Class<?> c) { StringBuilder ret = new StringBuilder(); while (c.isArray()) { ret.append('['); c = c.getComponentType(); } if (c.isPrimitive()) { String t = c.getName(); if ("void".equals(t)) ret.append(JVM_VOID); else if ("boolean".equals(t)) ret.append(JVM_BOOLEAN); else if ("byte".equals(t)) ret.append(JVM_BYTE); else if ("char".equals(t)) ret.append(JVM_CHAR); else if ("double".equals(t)) ret.append(JVM_DOUBLE); else if ("float".equals(t)) ret.append(JVM_FLOAT); else if ("int".equals(t)) ret.append(JVM_INT); else if ("long".equals(t)) ret.append(JVM_LONG); else if ("short".equals(t)) ret.append(JVM_SHORT); } else { ret.append('L'); ret.append(c.getName().replace('.', '/')); ret.append(';'); } return ret.toString(); }
From source file:com.freetmp.common.util.ClassUtils.java
public static boolean isPrimitiveArray(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isArray() && clazz.getComponentType().isPrimitive()); }
From source file:com.glaf.core.util.GetterUtils.java
public static String[] getStringValues(Object value, String[] defaultValue) { if (value == null) { return defaultValue; }/*from w ww . j a va2 s . co m*/ Class<?> clazz = value.getClass(); if (clazz.isArray()) { Class<?> componentType = clazz.getComponentType(); if (String.class.isAssignableFrom(componentType)) { return getStringValues((String[]) value, defaultValue); } } return defaultValue; }
From source file:com.glaf.core.util.ReflectUtils.java
/** * get name. java.lang.Object[][].class => "java.lang.Object[][]" * //from w w w . j a va 2 s. c om * @param c * class. * @return name. */ public static String getName(Class<?> c) { if (c.isArray()) { StringBuilder sb = new StringBuilder(); do { sb.append("[]"); c = c.getComponentType(); } while (c.isArray()); return c.getName() + sb.toString(); } return c.getName(); }
From source file:com.glaf.core.util.GetterUtils.java
public static float[] getFloatValues(Object value, float[] defaultValue) { if (value == null) { return defaultValue; }/*from w ww.j a v a 2 s.c om*/ Class<?> clazz = value.getClass(); if (clazz.isArray()) { Class<?> componentType = clazz.getComponentType(); if (String.class.isAssignableFrom(componentType)) { return getFloatValues((String[]) value, defaultValue); } else if (Float.class.isAssignableFrom(componentType)) { return (float[]) value; } } return defaultValue; }
From source file:com.glaf.core.util.GetterUtils.java
public static int[] getIntegerValues(Object value, int[] defaultValue) { if (value == null) { return defaultValue; }/* w ww. j a va 2s .c o m*/ Class<?> clazz = value.getClass(); if (clazz.isArray()) { Class<?> componentType = clazz.getComponentType(); if (String.class.isAssignableFrom(componentType)) { return getIntegerValues((String[]) value, defaultValue); } else if (Integer.class.isAssignableFrom(componentType)) { return (int[]) value; } } return defaultValue; }
From source file:com.glaf.core.util.GetterUtils.java
public static short[] getShortValues(Object value, short[] defaultValue) { if (value == null) { return defaultValue; }/* ww w .j a v a 2s . c o m*/ Class<?> clazz = value.getClass(); if (clazz.isArray()) { Class<?> componentType = clazz.getComponentType(); if (String.class.isAssignableFrom(componentType)) { return getShortValues((String[]) value, defaultValue); } else if (Short.class.isAssignableFrom(componentType)) { return (short[]) value; } } return defaultValue; }
From source file:info.novatec.testit.livingdoc.converter.ArrayConverter.java
@Override public Object parse(String value, Class<?> type) { String text = removeSquareBrackets(value); List<Object> values = new ArrayList<Object>(); if (StringUtils.isBlank(text)) { return CollectionUtil.toArray(values, type.getComponentType()); }/* w w w .j av a2 s . com*/ String[] parts = text.split(separators); for (String part : parts) { values.add(TypeConversion.parse(part.trim(), type.getComponentType())); } return CollectionUtil.toArray(values, type.getComponentType()); }