List of usage examples for java.lang Class isArray
@HotSpotIntrinsicCandidate public native boolean isArray();
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.converter.general.ArrayConverter.java
/** * {@inheritDoc}/*from w w w. j a v a 2 s .c o m*/ */ @Override public boolean canConvertValueForJava(final Object value, final ValueConverter globalDelegate, final Class<?> expectedClass) { boolean canConvert = expectedClass.isArray(); if (canConvert) { final Class<?> componentClass = expectedClass.getComponentType(); if (value instanceof Iterable<?>) { final Collection<?> coll = (Collection<?>) value; for (final Object element : coll) { canConvert = canConvert && globalDelegate.canConvertValueForJava(element, componentClass); if (!canConvert) { break; } } } else if (value.getClass().isArray()) { final int length = Array.getLength(value); for (int idx = 0; idx < length && canConvert; idx++) { canConvert = canConvert && globalDelegate.canConvertValueForJava(Array.get(value, idx), componentClass); } } else { canConvert = false; } } return canConvert; }
From source file:com.metaparadigm.jsonrpc.BeanSerializer.java
@Override public boolean canSerialize(Class clazz, Class jsonClazz) { return (!clazz.isArray() && !clazz.isPrimitive() && !clazz.isInterface() && (jsonClazz == null || jsonClazz == JSONObject.class)); }
From source file:name.ikysil.beanpathdsl.codegen.Context.java
private Class<?> resolveClass(Class<?> clazz) { if (clazz.isArray()) { return clazz.getComponentType(); }// w ww . j a v a 2s . c o m return clazz; }
From source file:com.openmeap.json.JSONObjectBuilder.java
private boolean isSimpleType(Class returnType) { if (returnType.isArray()) { return Boolean[].class.isAssignableFrom(returnType) || Long[].class.isAssignableFrom(returnType) || Double[].class.isAssignableFrom(returnType) || Integer[].class.isAssignableFrom(returnType) || String[].class.isAssignableFrom(returnType); } else {/* ww w . j a v a 2 s .c om*/ return Boolean.class.isAssignableFrom(returnType) || Long.class.isAssignableFrom(returnType) || Double.class.isAssignableFrom(returnType) || Integer.class.isAssignableFrom(returnType) || String.class.isAssignableFrom(returnType); } }
From source file:com.opensymphony.able.introspect.PropertyInfo.java
public boolean isCollection() { Class<?> propertyType = descriptor.getPropertyType(); return propertyType.isArray() || Collection.class.isAssignableFrom(propertyType); }
From source file:com.astamuse.asta4d.web.form.validation.TypeUnMatchValidator.java
@SuppressWarnings("rawtypes") protected String generateValueString(Object originalValue, Class targetType) { String valueString;/*from w w w .j a v a 2 s . co m*/ boolean originalTypeIsArray = originalValue.getClass().isArray(); boolean targetTypeIsArray = targetType.isArray(); if (originalTypeIsArray && targetTypeIsArray) { valueString = createOriginalValueString(Arrays.asList((Object[]) originalValue)); } else if (originalTypeIsArray) { valueString = createOriginalValueString(Arrays.asList((Object[]) originalValue)); } else { valueString = createSingleOriginalValueString(originalValue); } return valueString; }
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.converter.general.ArrayConverter.java
protected Object convertToArray(final Object value, final ValueConverter globalDelegate, final Class<?> expectedClass, final boolean toScript) { final Object result; final Class<?> valueClass = value.getClass(); if (valueClass.isArray()) { final Object arr = Array.newInstance(expectedClass.getComponentType(), Array.getLength(value)); for (int idx = 0; idx < Array.getLength(value); idx++) { final Object converted = toScript ? globalDelegate.convertValueForScript(Array.get(value, idx), expectedClass.getComponentType()) : globalDelegate.convertValueForJava(Array.get(value, idx), expectedClass.getComponentType()); Array.set(arr, idx, converted); }//from w w w. j ava2 s.co m result = arr; } else { final Collection<?> coll; if (value instanceof Collection<?>) { coll = (Collection<?>) value; } else { final List<Object> list = new ArrayList<Object>(); final Iterator<?> it = (Iterator<?>) value; while (it.hasNext()) { list.add(it.next()); } coll = list; } final Object arr = Array.newInstance(expectedClass.getComponentType(), coll.size()); final Iterator<?> it = coll.iterator(); for (int idx = 0; it.hasNext(); idx++) { final Object converted = toScript ? globalDelegate.convertValueForScript(it.next(), expectedClass.getComponentType()) : globalDelegate.convertValueForJava(it.next(), expectedClass.getComponentType()); Array.set(arr, idx, converted); } result = arr; } return result; }
From source file:com.qpark.eip.core.spring.JAXBElementAwarePayloadTypeRouter.java
/** * Selects the most appropriate channel name matching channel identifiers * which are the fully qualified class names encountered while traversing * the payload type hierarchy. To resolve ties and conflicts (e.g., * Serializable and String) it will match: 1. Type name to channel * identifier else... 2. Name of the subclass of the type to channel * identifier else... 3. Name of the Interface of the type to channel * identifier while also preferring direct interface over indirect subclass *//* w w w .ja v a 2s .c o m*/ @Override protected List<Object> getChannelKeys(final Message<?> message) { if (CollectionUtils.isEmpty(this.getChannelMappings())) { return null; } Object o = message.getPayload(); Class<?> type = message.getPayload().getClass(); if (o.getClass().equals(JAXBElement.class)) { type = ((JAXBElement<?>) o).getDeclaredType(); } boolean isArray = type.isArray(); if (isArray) { type = type.getComponentType(); } String closestMatch = this.findClosestMatch(type, isArray); return (closestMatch != null) ? Collections.<Object>singletonList(closestMatch) : null; }
From source file:com.oembedler.moon.graphql.engine.dfs.ResolvableTypeAccessor.java
public boolean isArrayType() { Class<?> rawCls = resolve(); return rawCls.isArray() || Iterable.class.equals(rawCls); }
From source file:com.thesett.util.validation.core.BeanValidationToJsonSchemaImpl.java
private boolean assignType(ConstraintBuilder constraintBuilder, Class<?> propertyType) // NOSONAR { boolean typeAssigned = false; if (propertyType.isArray()) { constraintBuilder.isArray();/*from w w w.ja va2 s .com*/ typeAssigned = true; } else if (Collection.class.isAssignableFrom(propertyType)) { constraintBuilder.isArray(); typeAssigned = true; } else if (propertyType.equals(String.class)) { constraintBuilder.isString(); typeAssigned = true; } else if (propertyType.equals(int.class) || propertyType.equals(Integer.class)) { constraintBuilder.isInteger(); typeAssigned = true; } else if (propertyType.equals(long.class) || propertyType.equals(Long.class)) { constraintBuilder.isInteger(); typeAssigned = true; } else if (propertyType.equals(float.class) || propertyType.equals(Float.class)) { constraintBuilder.isNumber(); typeAssigned = true; } else if (propertyType.equals(double.class) || propertyType.equals(Double.class)) { constraintBuilder.isNumber(); typeAssigned = true; } else if (propertyType.equals(boolean.class) || propertyType.equals(Boolean.class)) { constraintBuilder.isBoolean(); typeAssigned = true; } else if (BigDecimal.class.isAssignableFrom(propertyType)) { constraintBuilder.isNumber(); typeAssigned = true; } else if (Calendar.class.isAssignableFrom(propertyType)) { constraintBuilder.isString(); typeAssigned = true; } return typeAssigned; }