List of usage examples for java.lang Class isArray
@HotSpotIntrinsicCandidate public native boolean isArray();
From source file:jp.go.nict.langrid.client.soap.io.SoapResponseParser.java
private static <T> T nodeToType(XPathWorkspace w, Node node, Class<T> clazz, Converter converter) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ConversionException, DOMException, ParseException { if (clazz.isPrimitive()) { return converter.convert(resolveHref(w, node).getTextContent(), clazz); } else if (clazz.equals(String.class)) { return clazz.cast(resolveHref(w, node).getTextContent()); } else if (clazz.equals(byte[].class)) { try {/*from w ww.j a v a 2 s . com*/ return clazz.cast(Base64.decodeBase64(resolveHref(w, node).getTextContent().getBytes("ISO8859-1"))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } else if (clazz.equals(Calendar.class)) { Date date = fmt.get().parse(resolveHref(w, node).getTextContent()); Calendar c = Calendar.getInstance(); c.setTime(date); return clazz.cast(c); } else if (clazz.isArray()) { Class<?> ct = clazz.getComponentType(); List<Object> elements = new ArrayList<Object>(); node = resolveHref(w, node); for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { if (!(child instanceof Element)) continue; elements.add(nodeToType(w, child, ct, converter)); } return clazz.cast(elements.toArray((Object[]) Array.newInstance(ct, elements.size()))); } else { T instance = clazz.newInstance(); node = resolveHref(w, node); for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { if (!(child instanceof Element)) continue; String nn = child.getLocalName(); Method setter = ClassUtil.findSetter(clazz, nn); setter.invoke(instance, nodeToType(w, resolveHref(w, child), setter.getParameterTypes()[0], converter)); } return instance; } }
From source file:com.glaf.core.util.GetterUtils.java
public static long[] getLongValues(Object value, long[] defaultValue) { if (value == null) { return defaultValue; }/*from ww w . java 2 s .co m*/ Class<?> clazz = value.getClass(); if (!clazz.isArray()) { return defaultValue; } Class<?> componentType = clazz.getComponentType(); if (String.class.isAssignableFrom(componentType)) { return getLongValues((String[]) value, defaultValue); } else if (Long.class.isAssignableFrom(componentType)) { return (long[]) value; } else if (Number.class.isAssignableFrom(componentType)) { Number[] numbers = (Number[]) value; long[] values = new long[numbers.length]; for (int i = 0; i < values.length; i++) { values[i] = numbers[i].longValue(); } return values; } return defaultValue; }
From source file:egovframework.rte.itl.integration.type.ListType.java
@Override public boolean isAssignableFrom(Class<?> clazz) { if (super.isAssignableFrom(clazz)) { return true; }/* ww w. ja v a 2 s . c o m*/ if (clazz.isArray()) { return elementType.isAssignableFrom(clazz.getComponentType()); } return false; }
From source file:de.micromata.genome.gwiki.web.tags.GWikiHtmlOptionsCollectionTag.java
@SuppressWarnings({ "unchecked", "rawtypes" }) protected Iterator<?> getIterator(Object collection) throws JspException { Class<?> clcls = collection.getClass(); if (clcls.isArray()) { collection = Arrays.asList((Object[]) collection); }// w ww. j ava 2s.co m if (collection instanceof Collection) { return (((Collection<?>) collection).iterator()); } else if (collection instanceof Iterator) { return ((Iterator<?>) collection); } else if (collection instanceof Map) { return (((Map<?, ?>) collection).entrySet().iterator()); } else if (collection instanceof Enumeration) { return new EnumerationIterator((Enumeration<?>) collection); } else { throw new JspException("form." + property + " does not return a valid collection"); } }
From source file:com.flipkart.flux.client.intercept.WorkflowInterceptor.java
private void checkForBadSignatures(MethodInvocation invocation) { Method method = invocation.getMethod(); final Class<?> returnType = method.getReturnType(); if (!returnType.equals(void.class)) { throw new IllegalSignatureException(new MethodId(method), "A workflow method can only return void"); }/*from ww w.j a va 2s .c o m*/ final Class<?>[] parameterTypes = method.getParameterTypes(); for (Class<?> aParamType : parameterTypes) { if (!Event.class.isAssignableFrom(aParamType) && !aParamType.isArray()) { throw new IllegalSignatureException(new MethodId(method), "Parameter types should implement the Event interface. Collections of events are also not allowed"); } } }
From source file:com.adobe.acs.commons.util.impl.ValueMapTypeConverter.java
private Object convertValue() { if (declaredType instanceof Class<?>) { Class<?> clazz; try {/*from w w w . j a v a 2s. c o m*/ clazz = (Class<?>) declaredType; if (clazz.isArray()) { return handleArrayProperty(clazz); } else { return getValueFromMap(clazz); } } catch (ClassCastException e) { return null; } } else if (ParameterizedType.class.isInstance(declaredType)) { return handleCollectionTypes((ParameterizedType) declaredType); } else { LOG.debug("ValueMapTypeConverter doesn't support non-class types {}", declaredType); return null; } }
From source file:io.servicecomb.swagger.invocation.converter.ConverterMgr.java
protected Converter findCollectionToArray(Type src, Type target) { if (ParameterizedType.class.isAssignableFrom(src.getClass()) && target.getClass().equals(Class.class)) { ParameterizedType srcType = (ParameterizedType) src; Class<?> srcCls = (Class<?>) srcType.getRawType(); Class<?> targetCls = (Class<?>) target; if (Collection.class.isAssignableFrom(srcCls) && targetCls.isArray() && srcType.getActualTypeArguments()[0].equals(targetCls.getComponentType())) { Converter converter = collectionToArrayMap.get(target); if (converter == null) { converter = new SameElementCollectionToArray(targetCls.getComponentType()); collectionToArrayMap.put(target, converter); }/*from w ww. j a va 2 s.com*/ return converter; } } return null; }
From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java
/** * Convert.//w w w. ja v a 2s . com * * @param value the value * @param type the type * @return the object */ protected static Object convert(String value, Class<?> type) { Object newValue = null; if (type.isArray()) { // Indexed value into array newValue = ConvertUtils.convert(value, type.getComponentType()); } else { // Value into scalar newValue = ConvertUtils.convert(value, type); } return newValue; }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Build a nice qualified name for an array: * component type class name + "[]"./*from w w w .j ava2 s . c o m*/ * @param clazz the array class * @return a qualified name for the array class */ private static String getQualifiedNameForArray(Class<?> clazz) { StringBuilder result = new StringBuilder(); while (clazz.isArray()) { clazz = clazz.getComponentType(); result.append(ClassUtils.ARRAY_SUFFIX); } result.insert(0, clazz.getName()); return result.toString(); }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Return the qualified name of the given class: usually simply * the class name, but component type class name + "[]" for arrays. * @param clazz the class/*from w w w .j av a2 s . c om*/ * @return the qualified name of the class */ public static String getQualifiedName(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); if (clazz.isArray()) { return getQualifiedNameForArray(clazz); } else { return clazz.getName(); } }