List of usage examples for java.lang Class getComponentType
public Class<?> getComponentType()
From source file:com.discovery.darchrow.lang.ClassUtil.java
/** * class info map for LOGGER.//from w ww .j ava 2 s .c o m * * @param klass * the clz * @return the map for log */ public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) { if (Validator.isNullOrEmpty(klass)) { return null; } Map<String, Object> map = new LinkedHashMap<String, Object>(); map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.feilong.core.date.DatePattern" map.put("clz.getName()", klass.getName());//"com.feilong.core.date.DatePattern" map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern" 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; }
From source file:Mopex.java
/** * Returns a syntactically correct name for a class object. If the class * object represents an array, the proper number of square bracket pairs are * appended to the component type.//from ww w . java2s .c o m * * @return java.lang.String * @param cls * java.lang.Class */ //start extract classNameToString public static String getTypeName(Class cls) { if (!cls.isArray()) { return cls.getName(); } else { return getTypeName(cls.getComponentType()) + "[]"; } }
From source file:net.sf.json.JSONUtils.java
/** * DOCUMENT ME!/*w w w . j av a 2 s.co m*/ * * @param type DOCUMENT ME! * * @return DOCUMENT ME! */ public static Class getInnerComponentType(Class type) { if (!type.isArray()) { return type; } return getInnerComponentType(type.getComponentType()); }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?String ?://from w w w . j a va 2s. c om * * <pre> * short, int, long, float : 0 * char, byte: 0 * String: null * Map, List: null * Integer, Long, Float : null * Date: null * array: null * </pre> * * @param strValue * @param clazz * @return */ @SuppressWarnings("unchecked") public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) { if (DEF_NULL.equals(strValue)) { if (!clazz.isPrimitive()) { return null; } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (DEF_EMPTY.equals(strValue)) { if (clazz.isArray()) { return (T) Array.newInstance(clazz.getComponentType(), 0); } if (Map.class.isAssignableFrom(clazz)) { return (T) Collections.EMPTY_MAP; } if (List.class.isAssignableFrom(clazz)) { return (T) new ArrayList<Object>(); } if (Set.class.isAssignableFrom(clazz)) { return (T) new HashSet<Object>(); } if (String.class.equals(clazz)) { return (T) StringUtils.EMPTY; } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(' '); } if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } if (StringUtils.isBlank(strValue)) {// ? if (autoDefault) { return (T) getInternalDefaultValue(clazz); } else { return null; } } else { if (String.class.equals(clazz)) { return (T) strValue; } if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) { return (T) Short.valueOf(strValue); } if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) { return (T) Integer.valueOf(strValue); } if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) { return (T) Long.valueOf(strValue); } if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) { return (T) Boolean.valueOf(strValue); } if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) { return (T) Float.valueOf(strValue); } if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) { return (T) Double.valueOf(strValue); } if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) { return (T) Byte.valueOf(strValue); } if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) { return (T) Character.valueOf(strValue.charAt(0)); } if (clazz.isArray()) { final Class<?> componentType = clazz.getComponentType(); // String[] if (String.class.equals(componentType)) { return (T) StringUtils.split(strValue, ','); } // ?char[] if (Character.TYPE.equals(componentType)) { return (T) strValue.toCharArray(); } if (Character.class.equals(componentType)) { final char[] tmp = strValue.toCharArray(); final Character[] result = new Character[tmp.length]; for (int i = 0; i < result.length; i++) { result[i] = tmp[i]; } return (T) result; } if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) { return (T) (strValue == null ? null : strValue.getBytes()); } } } return null; }
From source file:com.sinosoft.one.data.jade.rowmapper.DefaultRowMapperFactory.java
private static Class<?> getRowType(StatementMetaData statementMetaData) { Class<?> returnClassType = statementMetaData.getMethod().getReturnType(); if (Collection.class.isAssignableFrom(returnClassType) || Page.class.isAssignableFrom(returnClassType)) { return getRowTypeFromCollectionType(statementMetaData, returnClassType); } else if (Map.class == returnClassType) { return getRowTypeFromMapType(statementMetaData, returnClassType); } else if (returnClassType.isArray() && returnClassType != byte[].class) { // , ??/*from w w w .ja va 2s . c o m*/ return returnClassType.getComponentType(); } // DAO? return returnClassType; }
From source file:org.gridgain.grid.util.json.GridJsonDeserializer.java
/** * Deserializes {@link JSONArray} to Java array of given class. * * @param arr Array for deserialization. * @param cls Class of resulted array.//from w w w.j a v a 2 s. co m * @return Deserialized array. * @throws GridException Thrown if any error occurs while deserialization. */ @SuppressWarnings("unchecked") private static Object buildArray(JSONArray arr, Class cls) throws GridException { assert arr != null; assert cls != null; cls = cls.getComponentType(); List list = new ArrayList(arr.size()); for (Object elem : arr) if (!isDescriptor(elem)) list.add(elem); int size = list.size(); Object res = Array.newInstance(cls, size); for (int i = 0; i < size; i++) Array.set(res, i, deserialize(list.get(i), cls)); return res; }
From source file:jp.go.nict.langrid.servicecontainer.handler.jsonrpc.servlet.JsonRpcServlet.java
private static String prettyName(Class<?> clazz) { StringBuilder postfix = new StringBuilder(); if (Proxy.isProxyClass(clazz)) { return "<em>Proxy Implementation (detailed information unavailable)</em>"; }//from w w w. j av a2s . co m if (clazz.isArray()) { clazz = clazz.getComponentType(); appendGenericsInfo(clazz, postfix); postfix.append("[]"); } else { appendGenericsInfo(clazz, postfix); } String n = clazz.getName(); String sn = clazz.getSimpleName(); return "<span class=\"info\">" + sn + postfix + "<span>" + n + postfix + "</span></span>"; }
From source file:MethodHashing.java
static String getTypeString(Class cl) { if (cl == Byte.TYPE) { return "B"; } else if (cl == Character.TYPE) { return "C"; } else if (cl == Double.TYPE) { return "D"; } else if (cl == Float.TYPE) { return "F"; } else if (cl == Integer.TYPE) { return "I"; } else if (cl == Long.TYPE) { return "J"; } else if (cl == Short.TYPE) { return "S"; } else if (cl == Boolean.TYPE) { return "Z"; } else if (cl == Void.TYPE) { return "V"; } else if (cl.isArray()) { return "[" + getTypeString(cl.getComponentType()); } else {/*from ww w . java 2s. c om*/ return "L" + cl.getName().replace('.', '/') + ";"; } }
From source file:ArrayUtils.java
@SuppressWarnings("unchecked") public static <T> T[] toArray(final Collection<T> c, final Class<? extends T[]> newType) { final int length = c.size(); final T[] array = (T[]) Array.newInstance(newType.getComponentType(), length); if (length > 0) { int i = 0; for (final T elem : c) { array[i++] = elem;// w ww.j a va2 s .c om } } return array; }
From source file:com.gzj.tulip.jade.rowmapper.DefaultRowMapperFactory.java
private static Class<?> getRowType(StatementMetaData statementMetaData) { Class<?> returnClassType = statementMetaData.getReturnType(); if (Collection.class.isAssignableFrom(returnClassType)// || Iterable.class == returnClassType // || Iterator.class == returnClassType) { return getRowTypeFromCollectionType(statementMetaData, returnClassType); } ///* www. j ava2s. c o m*/ else if (Map.class.isAssignableFrom(returnClassType)) { return getRowTypeFromMapType(statementMetaData, returnClassType); } // else if (returnClassType.isArray() && returnClassType != byte[].class) { // , ?? return returnClassType.getComponentType(); } // DAO? return returnClassType; }