List of usage examples for java.lang Class getComponentType
public Class<?> getComponentType()
From source file:org.apache.openjpa.meta.FieldMetaData.java
public void setType(Class type) { _val.setType(type); if (type.isArray()) _elem.setType(type.getComponentType()); else if (type == Properties.class) { _key.setType(String.class); _elem.setType(String.class); }//from w w w . j a v a2 s . c o m }
From source file:org.apache.openjpa.meta.FieldMetaData.java
public void setDeclaredType(Class type) { _val.setDeclaredType(type); if (type.isArray()) _elem.setDeclaredType(type.getComponentType()); else if (type == Properties.class) { _key.setDeclaredType(String.class); _elem.setDeclaredType(String.class); }/*from w ww.ja va2 s . c o m*/ }
From source file:de.hasait.clap.impl.CLAPOptionNode.java
private CLAPOptionNode(final CLAP pCLAP, final Class<T> pResultClass, final Character pShortKey, final String pLongKey, final boolean pRequired, final Integer pArgCount, final Character pMultiArgSplit, final String pDescriptionNLSKey, final String pArgUsageNLSKey) { super(pCLAP); if (pShortKey != null && pShortKey == getCLAP().getShortOptPrefix()) { throw new IllegalArgumentException(); }//from w w w . j av a2s. c om if (pLongKey != null && pLongKey.contains(getCLAP().getLongOptEquals())) { throw new IllegalArgumentException(); } if (pArgCount == null) { // autodetect using resultClass if (pResultClass.isArray() || Collection.class.isAssignableFrom(pResultClass)) { _argCount = CLAP.UNLIMITED_ARG_COUNT; } else if (pResultClass.equals(Boolean.class) || pResultClass.equals(Boolean.TYPE)) { _argCount = 0; } else { _argCount = 1; } } else { if (pArgCount < 0 && pArgCount != CLAP.UNLIMITED_ARG_COUNT) { throw new IllegalArgumentException(); } if (pResultClass.isArray() || Collection.class.isAssignableFrom(pResultClass)) { if (pArgCount == 0) { throw new IllegalArgumentException(); } } else if (pResultClass.equals(Boolean.class) || pResultClass.equals(Boolean.TYPE)) { if (pArgCount != 0 && pArgCount != 1) { throw new IllegalArgumentException(); } } else { if (pArgCount != 1) { throw new IllegalArgumentException(); } } _argCount = pArgCount; } if (pShortKey == null && pLongKey == null && _argCount == 0) { throw new IllegalArgumentException(); } if (pResultClass.isArray()) { final Class<?> componentType = pResultClass.getComponentType(); final CLAPConverter<?> converter = pCLAP.getConverter(componentType); _mapper = new Mapper<T>() { @Override public T transform(final String[] pStringValues) { final T result = (T) Array.newInstance(componentType, pStringValues.length); for (int i = 0; i < pStringValues.length; i++) { try { Array.set(result, i, converter.convert(pStringValues[i])); } catch (final Exception e) { throw new RuntimeException(e); } } return result; } }; } else if (Collection.class.isAssignableFrom(pResultClass)) { _mapper = null; } else { final CLAPConverter<? extends T> converter = pCLAP.getConverter(pResultClass); _mapper = new Mapper<T>() { @Override public T transform(final String[] pStringValues) { if (pStringValues.length == 0 && (pResultClass.equals(Boolean.class) || pResultClass.equals(Boolean.TYPE))) { return (T) Boolean.TRUE; } return converter.convert(pStringValues[0]); } }; } _shortKey = pShortKey; _longKey = pLongKey; _required = pRequired; _multiArgSplit = pMultiArgSplit; _descriptionNLSKey = pDescriptionNLSKey; _argUsageNLSKey = pArgUsageNLSKey; _resultClass = pResultClass; }
From source file:it.delli.mwebc.utils.DefaultCastHelper.java
public Object toType(String value, Class<?> type) { Object obj = null;/*from www. j a va 2s .com*/ try { if (value != null) { if (type.getName().equals(String.class.getName())) { obj = toString(value); } else if (type.getName().equals(String[].class.getName())) { obj = toStringArray(value); } else if (type.getName().equals(Character.class.getName())) { obj = toCharacter(value); } else if (type.getName().equals(Character[].class.getName())) { obj = toCharacterArray(value); } else if (type.getName().equals(Integer.class.getName())) { obj = toInteger(value); } else if (type.getName().equals(Integer[].class.getName())) { obj = toIntegerArray(value); } else if (type.getName().equals(Long.class.getName())) { obj = toLong(value); } else if (type.getName().equals(Long[].class.getName())) { obj = toLongArray(value); } else if (type.getName().equals(Double.class.getName())) { obj = toDouble(value); } else if (type.getName().equals(Double[].class.getName())) { obj = toDoubleArray(value); } else if (type.getName().equals(Boolean.class.getName())) { obj = toBoolean(value); } else if (type.getName().equals(Boolean[].class.getName())) { obj = toBooleanArray(value); } else if (type.getName().equals(Date.class.getName())) { obj = toDate(value); } else if (type.getName().equals(Date[].class.getName())) { obj = toDateArray(value); } else if (type.getName().equals(Color.class.getName())) { obj = toColor(value); } else if (type.getName().equals(Color[].class.getName())) { obj = toColorArray(value); } else if (type.isEnum()) { for (int i = 0; i < type.getEnumConstants().length; i++) { if (type.getEnumConstants()[i].toString().equals(value)) { obj = type.getEnumConstants()[i]; } } } else if (type.isArray() && type.getComponentType().isEnum()) { String[] tmp = value.split(","); Enum[] array = new Enum[tmp.length]; for (int j = 0; j < tmp.length; j++) { String item = tmp[j].trim(); for (int i = 0; i < type.getComponentType().getEnumConstants().length; i++) { if (type.getComponentType().getEnumConstants()[i].toString().equals(item)) { array[j] = (Enum) type.getComponentType().getEnumConstants()[i]; } } } obj = array; } else if (type.getName().equals(Map.class.getName()) || type.getName().equals(HashMap.class.getName()) || type.getName().equals(LinkedHashMap.class.getName())) { obj = toMap(value, type); } } } catch (Exception e) { e.printStackTrace(); } return obj; }
From source file:com.microsoft.windowsazure.mobileservices.MobileServiceClient.java
/** * Invokes a custom API//from ww w . j ava 2s. c o m * * @param apiName The API name * @param body The object to send as the request body * @param httpMethod The HTTP Method used to invoke the API * @param parameters The query string parameters sent in the request * @param clazz The API result class */ public <E> ListenableFuture<E> invokeApi(String apiName, Object body, String httpMethod, List<Pair<String, String>> parameters, final Class<E> clazz) { if (clazz == null) { throw new IllegalArgumentException("clazz cannot be null"); } JsonElement json = null; if (body != null) { if (body instanceof JsonElement) { json = (JsonElement) body; } else { json = getGsonBuilder().create().toJsonTree(body); } } final SettableFuture<E> future = SettableFuture.create(); ListenableFuture<JsonElement> internalFuture = this.invokeApiInternal(apiName, json, httpMethod, parameters, EnumSet.of(MobileServiceFeatures.TypedApiCall)); Futures.addCallback(internalFuture, new FutureCallback<JsonElement>() { @Override public void onFailure(Throwable e) { future.setException(e); } @Override @SuppressWarnings("unchecked") public void onSuccess(JsonElement jsonElement) { Class<?> concreteClass = clazz; if (clazz.isArray()) { concreteClass = clazz.getComponentType(); } List<?> entities = JsonEntityParser.parseResults(jsonElement, getGsonBuilder().create(), concreteClass); if (clazz.isArray()) { E array = (E) Array.newInstance(concreteClass, entities.size()); for (int i = 0; i < entities.size(); i++) { Array.set(array, i, entities.get(i)); } future.set(array); } else { future.set((E) entities.get(0)); } } }); return future; }
From source file:com.espertech.esper.event.bean.BeanEventType.java
private void initialize(boolean isConfigured) { PropertyListBuilder propertyListBuilder = PropertyListBuilderFactory.createBuilder(optionalLegacyDef); List<InternalEventPropDescriptor> properties = propertyListBuilder.assessProperties(clazz); this.propertyDescriptors = new EventPropertyDescriptor[properties.size()]; this.propertyDescriptorMap = new HashMap<String, EventPropertyDescriptor>(); this.propertyNames = new String[properties.size()]; this.simpleProperties = new HashMap<String, SimplePropertyInfo>(); this.mappedPropertyDescriptors = new HashMap<String, InternalEventPropDescriptor>(); this.indexedPropertyDescriptors = new HashMap<String, InternalEventPropDescriptor>(); if (usesSmartResolutionStyle()) { simpleSmartPropertyTable = new HashMap<String, List<SimplePropertyInfo>>(); mappedSmartPropertyTable = new HashMap<String, List<SimplePropertyInfo>>(); indexedSmartPropertyTable = new HashMap<String, List<SimplePropertyInfo>>(); }/*from www . j a va2 s.c om*/ if ((optionalLegacyDef == null) || (optionalLegacyDef .getCodeGeneration() != ConfigurationEventTypeLegacy.CodeGeneration.DISABLED)) { // get CGLib fast class fastClass = null; try { fastClass = FastClass.create(Thread.currentThread().getContextClassLoader(), clazz); } catch (Throwable ex) { log.warn(".initialize Unable to obtain CGLib fast class and/or method implementation for class " + clazz.getName() + ", error msg is " + ex.getMessage(), ex); fastClass = null; } } int count = 0; for (InternalEventPropDescriptor desc : properties) { String propertyName = desc.getPropertyName(); Class underlyingType; Class componentType; boolean isRequiresIndex; boolean isRequiresMapkey; boolean isIndexed; boolean isMapped; boolean isFragment; if (desc.getPropertyType().equals(EventPropertyType.SIMPLE)) { EventPropertyGetter getter; Class type; if (desc.getReadMethod() != null) { getter = PropertyHelper.getGetter(desc.getReadMethod(), fastClass, eventAdapterService); type = desc.getReadMethod().getReturnType(); } else { if (desc.getAccessorField() == null) { // Ignore property continue; } getter = new ReflectionPropFieldGetter(desc.getAccessorField(), eventAdapterService); type = desc.getAccessorField().getType(); } underlyingType = type; componentType = null; isRequiresIndex = false; isRequiresMapkey = false; isIndexed = false; isMapped = false; if (JavaClassHelper.isImplementsInterface(type, Map.class)) { isMapped = true; // We do not yet allow to fragment maps entries. // Class genericType = JavaClassHelper.getGenericReturnTypeMap(desc.getReadMethod(), desc.getAccessorField()); isFragment = false; if (desc.getReadMethod() != null) { componentType = JavaClassHelper.getGenericReturnTypeMap(desc.getReadMethod(), false); } else if (desc.getAccessorField() != null) { componentType = JavaClassHelper.getGenericFieldTypeMap(desc.getAccessorField(), false); } else { componentType = Object.class; } } else if (type.isArray()) { isIndexed = true; isFragment = JavaClassHelper.isFragmentableType(type.getComponentType()); componentType = type.getComponentType(); } else if (JavaClassHelper.isImplementsInterface(type, Iterable.class)) { isIndexed = true; Class genericType = JavaClassHelper.getGenericReturnType(desc.getReadMethod(), desc.getAccessorField(), true); isFragment = JavaClassHelper.isFragmentableType(genericType); if (genericType != null) { componentType = genericType; } else { componentType = Object.class; } } else { isMapped = false; isFragment = JavaClassHelper.isFragmentableType(type); } simpleProperties.put(propertyName, new SimplePropertyInfo(type, getter, desc)); // Recognize that there may be properties with overlapping case-insentitive names if (usesSmartResolutionStyle()) { // Find the property in the smart property table String smartPropertyName = propertyName.toLowerCase(); List<SimplePropertyInfo> propertyInfoList = simpleSmartPropertyTable.get(smartPropertyName); if (propertyInfoList == null) { propertyInfoList = new ArrayList<SimplePropertyInfo>(); simpleSmartPropertyTable.put(smartPropertyName, propertyInfoList); } // Enter the property into the smart property list SimplePropertyInfo propertyInfo = new SimplePropertyInfo(type, getter, desc); propertyInfoList.add(propertyInfo); } } else if (desc.getPropertyType().equals(EventPropertyType.MAPPED)) { mappedPropertyDescriptors.put(propertyName, desc); underlyingType = desc.getReturnType(); componentType = Object.class; isRequiresIndex = false; isRequiresMapkey = desc.getReadMethod().getParameterTypes().length > 0; isIndexed = false; isMapped = true; isFragment = false; // Recognize that there may be properties with overlapping case-insentitive names if (usesSmartResolutionStyle()) { // Find the property in the smart property table String smartPropertyName = propertyName.toLowerCase(); List<SimplePropertyInfo> propertyInfoList = mappedSmartPropertyTable.get(smartPropertyName); if (propertyInfoList == null) { propertyInfoList = new ArrayList<SimplePropertyInfo>(); mappedSmartPropertyTable.put(smartPropertyName, propertyInfoList); } // Enter the property into the smart property list SimplePropertyInfo propertyInfo = new SimplePropertyInfo(desc.getReturnType(), null, desc); propertyInfoList.add(propertyInfo); } } else if (desc.getPropertyType().equals(EventPropertyType.INDEXED)) { indexedPropertyDescriptors.put(propertyName, desc); underlyingType = desc.getReturnType(); componentType = null; isRequiresIndex = desc.getReadMethod().getParameterTypes().length > 0; isRequiresMapkey = false; isIndexed = true; isMapped = false; isFragment = JavaClassHelper.isFragmentableType(desc.getReturnType()); if (usesSmartResolutionStyle()) { // Find the property in the smart property table String smartPropertyName = propertyName.toLowerCase(); List<SimplePropertyInfo> propertyInfoList = indexedSmartPropertyTable.get(smartPropertyName); if (propertyInfoList == null) { propertyInfoList = new ArrayList<SimplePropertyInfo>(); indexedSmartPropertyTable.put(smartPropertyName, propertyInfoList); } // Enter the property into the smart property list SimplePropertyInfo propertyInfo = new SimplePropertyInfo(desc.getReturnType(), null, desc); propertyInfoList.add(propertyInfo); } } else { continue; } propertyNames[count] = desc.getPropertyName(); EventPropertyDescriptor descriptor = new EventPropertyDescriptor(desc.getPropertyName(), underlyingType, componentType, isRequiresIndex, isRequiresMapkey, isIndexed, isMapped, isFragment); propertyDescriptors[count++] = descriptor; propertyDescriptorMap.put(descriptor.getPropertyName(), descriptor); } // Determine event type super types superTypes = getSuperTypes(clazz, eventAdapterService.getBeanEventTypeFactory()); if (superTypes != null && superTypes.length == 0) { superTypes = null; } // Determine deep supertypes // Get Java super types (superclasses and interfaces), deep get of all in the tree Set<Class> supers = new HashSet<Class>(); getSuper(clazz, supers); removeJavaLibInterfaces(supers); // Remove "java." super types // Cache the supertypes of this event type for later use deepSuperTypes = new HashSet<EventType>(); for (Class superClass : supers) { EventType superType = eventAdapterService.getBeanEventTypeFactory().createBeanType(superClass.getName(), superClass, false, false, isConfigured); deepSuperTypes.add(superType); } }
From source file:javadz.beanutils.BeanUtilsBean.java
/** * <p>Copy the specified property value to the specified destination bean, * performing any type conversion that is required. If the specified * bean does not have a property of the specified name, or the property * is read only on the destination bean, return without * doing anything. If you have custom destination property types, register * {@link Converter}s for them by calling the <code>register()</code> * method of {@link ConvertUtils}.</p> * * <p><strong>IMPLEMENTATION RESTRICTIONS</strong>:</p> * <ul>/*www . j a v a2 s . c om*/ * <li>Does not support destination properties that are indexed, * but only an indexed setter (as opposed to an array setter) * is available.</li> * <li>Does not support destination properties that are mapped, * but only a keyed setter (as opposed to a Map setter) * is available.</li> * <li>The desired property type of a mapped setter cannot be * determined (since Maps support any data type), so no conversion * will be performed.</li> * </ul> * * @param bean Bean on which setting is to be performed * @param name Property name (can be nested/indexed/mapped/combo) * @param value Value to be set * * @exception IllegalAccessException if the caller does not have * access to the property accessor method * @exception InvocationTargetException if the property accessor method * throws an exception */ public void copyProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException { // Trace logging (if enabled) if (log.isTraceEnabled()) { StringBuffer sb = new StringBuffer(" copyProperty("); sb.append(bean); sb.append(", "); sb.append(name); sb.append(", "); if (value == null) { sb.append("<NULL>"); } else if (value instanceof String) { sb.append((String) value); } else if (value instanceof String[]) { String[] values = (String[]) value; sb.append('['); for (int i = 0; i < values.length; i++) { if (i > 0) { sb.append(','); } sb.append(values[i]); } sb.append(']'); } else { sb.append(value.toString()); } sb.append(')'); log.trace(sb.toString()); } // Resolve any nested expression to get the actual target bean Object target = bean; Resolver resolver = getPropertyUtils().getResolver(); while (resolver.hasNested(name)) { try { target = getPropertyUtils().getProperty(target, resolver.next(name)); name = resolver.remove(name); } catch (NoSuchMethodException e) { return; // Skip this property setter } } if (log.isTraceEnabled()) { log.trace(" Target bean = " + target); log.trace(" Target name = " + name); } // Declare local variables we will require String propName = resolver.getProperty(name); // Simple name of target property Class type = null; // Java type of target property int index = resolver.getIndex(name); // Indexed subscript value (if any) String key = resolver.getKey(name); // Mapped key value (if any) // Calculate the target property type if (target instanceof DynaBean) { DynaClass dynaClass = ((DynaBean) target).getDynaClass(); DynaProperty dynaProperty = dynaClass.getDynaProperty(propName); if (dynaProperty == null) { return; // Skip this property setter } type = dynaProperty.getType(); } else { PropertyDescriptor descriptor = null; try { descriptor = getPropertyUtils().getPropertyDescriptor(target, name); if (descriptor == null) { return; // Skip this property setter } } catch (NoSuchMethodException e) { return; // Skip this property setter } type = descriptor.getPropertyType(); if (type == null) { // Most likely an indexed setter on a POJB only if (log.isTraceEnabled()) { log.trace(" target type for property '" + propName + "' is null, so skipping ths setter"); } return; } } if (log.isTraceEnabled()) { log.trace(" target propName=" + propName + ", type=" + type + ", index=" + index + ", key=" + key); } // Convert the specified value to the required type and store it if (index >= 0) { // Destination must be indexed value = convert(value, type.getComponentType()); try { getPropertyUtils().setIndexedProperty(target, propName, index, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } else if (key != null) { // Destination must be mapped // Maps do not know what the preferred data type is, // so perform no conversions at all // FIXME - should we create or support a TypedMap? try { getPropertyUtils().setMappedProperty(target, propName, key, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } else { // Destination must be simple value = convert(value, type); try { getPropertyUtils().setSimpleProperty(target, propName, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } }
From source file:org.apache.axis.wsdl.fromJava.Types.java
/** * Create a top-level element declaration in our generated schema * * @param qname//from w w w .j av a 2s .co m * @param javaType * @param typeQName * @param nillable nillable attribute of the element * @param itemQName * @throws AxisFault */ public void writeElementDecl(QName qname, Class javaType, QName typeQName, boolean nillable, QName itemQName) throws AxisFault { if (writtenElementQNames.contains(qname)) { return; } String name = qname.getLocalPart(); Element element = docHolder.createElement("element"); // Generate an element name that matches the type. element.setAttribute("name", name); if (nillable) { element.setAttribute("nillable", "true"); } /* * These are not legal on top-level elements! * (feel free to delete this block after say Oct 2005) if (omittable) { element.setAttribute("minOccurs", "0"); element.setAttribute("maxOccurs", "1"); } if (javaType.isArray()) { element.setAttribute("maxOccurs", "unbounded"); } */ if (javaType.isArray()) { // TODO : Should check to see if this array type is specifically mapped String componentType = writeType(javaType.getComponentType()); Element complexType = createLiteralArrayElement(componentType, itemQName); element.appendChild(complexType); } else { // Write the type for this element, handling anonymous or named // types appropriately. makeTypeElement(javaType, typeQName, element); } writeSchemaElementDecl(qname, element); }
From source file:org.eclipse.january.dataset.AbstractDataset.java
/** * Fill dataset from object at depth dimension * @param obj/*from w ww. ja va 2s .c o m*/ * @param depth * @param pos position */ protected void fillData(Object obj, final int depth, final int[] pos) { if (obj == null) { int dtype = getDType(); if (dtype == FLOAT32) set(Float.NaN, pos); else if (dtype == FLOAT64) set(Double.NaN, pos); return; } Class<?> clazz = obj.getClass(); if (obj instanceof List<?>) { List<?> jl = (List<?>) obj; int l = jl.size(); for (int i = 0; i < l; i++) { Object lo = jl.get(i); fillData(lo, depth + 1, pos); pos[depth]++; } pos[depth] = 0; } else if (clazz.isArray()) { int l = Array.getLength(obj); if (clazz.equals(odata.getClass())) { System.arraycopy(obj, 0, odata, get1DIndex(pos), l); } else if (clazz.getComponentType().isPrimitive()) { for (int i = 0; i < l; i++) { set(Array.get(obj, i), pos); pos[depth]++; } pos[depth] = 0; } else { for (int i = 0; i < l; i++) { fillData(Array.get(obj, i), depth + 1, pos); pos[depth]++; } pos[depth] = 0; } } else if (obj instanceof IDataset) { boolean[] a = new boolean[shape.length]; for (int i = depth; i < a.length; i++) a[i] = true; setSlice(obj, getSliceIteratorFromAxes(pos, a)); } else { set(obj, pos); } }
From source file:Main.java
/** * convert value to given type./*from ww w . j ava 2 s .co m*/ * null safe. * * @param value value for convert * @param type will converted type * @return value while converted */ public static Object convertCompatibleType(Object value, Class<?> type) { if (value == null || type == null || type.isAssignableFrom(value.getClass())) { return value; } if (value instanceof String) { String string = (String) value; if (char.class.equals(type) || Character.class.equals(type)) { if (string.length() != 1) { throw new IllegalArgumentException(String.format("CAN NOT convert String(%s) to char!" + " when convert String to char, the String MUST only 1 char.", string)); } return string.charAt(0); } else if (type.isEnum()) { return Enum.valueOf((Class<Enum>) type, string); } else if (type == BigInteger.class) { return new BigInteger(string); } else if (type == BigDecimal.class) { return new BigDecimal(string); } else if (type == Short.class || type == short.class) { return Short.valueOf(string); } else if (type == Integer.class || type == int.class) { return Integer.valueOf(string); } else if (type == Long.class || type == long.class) { return Long.valueOf(string); } else if (type == Double.class || type == double.class) { return Double.valueOf(string); } else if (type == Float.class || type == float.class) { return Float.valueOf(string); } else if (type == Byte.class || type == byte.class) { return Byte.valueOf(string); } else if (type == Boolean.class || type == boolean.class) { return Boolean.valueOf(string); } else if (type == Date.class) { try { return new SimpleDateFormat(DATE_FORMAT).parse((String) value); } catch (ParseException e) { throw new IllegalStateException("Failed to parse date " + value + " by format " + DATE_FORMAT + ", cause: " + e.getMessage(), e); } } else if (type == Class.class) { return forName((String) value); } } else if (value instanceof Number) { Number number = (Number) value; if (type == byte.class || type == Byte.class) { return number.byteValue(); } else if (type == short.class || type == Short.class) { return number.shortValue(); } else if (type == int.class || type == Integer.class) { return number.intValue(); } else if (type == long.class || type == Long.class) { return number.longValue(); } else if (type == float.class || type == Float.class) { return number.floatValue(); } else if (type == double.class || type == Double.class) { return number.doubleValue(); } else if (type == BigInteger.class) { return BigInteger.valueOf(number.longValue()); } else if (type == BigDecimal.class) { return BigDecimal.valueOf(number.doubleValue()); } else if (type == Date.class) { return new Date(number.longValue()); } } else if (value instanceof Collection) { Collection collection = (Collection) value; if (type.isArray()) { int length = collection.size(); Object array = Array.newInstance(type.getComponentType(), length); int i = 0; for (Object item : collection) { Array.set(array, i++, item); } return array; } else if (!type.isInterface()) { try { Collection result = (Collection) type.newInstance(); result.addAll(collection); return result; } catch (Throwable e) { e.printStackTrace(); } } else if (type == List.class) { return new ArrayList<>(collection); } else if (type == Set.class) { return new HashSet<>(collection); } } else if (value.getClass().isArray() && Collection.class.isAssignableFrom(type)) { Collection collection; if (!type.isInterface()) { try { collection = (Collection) type.newInstance(); } catch (Throwable e) { collection = new ArrayList<>(); } } else if (type == Set.class) { collection = new HashSet<>(); } else { collection = new ArrayList<>(); } int length = Array.getLength(value); for (int i = 0; i < length; i++) { collection.add(Array.get(value, i)); } return collection; } return value; }