List of usage examples for java.lang Class isArray
@HotSpotIntrinsicCandidate public native boolean isArray();
From source file:com.astamuse.asta4d.data.DefaultContextDataFinder.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//from www . j a va 2 s.c om public ContextDataHolder findDataInContext(Context context, String scope, String name, Class<?> targetType) throws DataOperationException { ContextDataHolder dataHolder = findByType(context, scope, name, targetType); if (dataHolder != null) { return dataHolder; } if (StringUtils.isEmpty(scope)) { dataHolder = findDataByScopeOrder(context, 0, name); } else { dataHolder = context.getDataHolder(scope, name); } if (dataHolder == null) { return null; } Object foundData = dataHolder.getValue(); Object transformedData = null; UnsupportedValueException usve = null; Class<?> srcType = new TypeInfo(foundData.getClass()).getType(); if (targetType.isAssignableFrom(srcType)) { transformedData = foundData; } else if (srcType.isArray() && targetType.isAssignableFrom(srcType.getComponentType())) { transformedData = Array.get(foundData, 0); } else if (targetType.isArray() && targetType.getComponentType().isAssignableFrom(srcType)) { Object array = Array.newInstance(srcType, 1); Array.set(array, 0, foundData); transformedData = array; } else { try { transformedData = Configuration.getConfiguration().getDataTypeTransformer().transform(srcType, targetType, foundData); } catch (UnsupportedValueException ex) { usve = ex; } } if (usve == null) { dataHolder.setData(dataHolder.getName(), dataHolder.getScope(), foundData, transformedData); } else { dataHolder.setData(dataHolder.getName(), InjectUtil.ContextDataTypeUnMatchScope, foundData, transformedData); } return dataHolder; }
From source file:com.google.gdt.eclipse.designer.ie.util.ReflectionUtils.java
/** * @param clazz/*from ww w. j a v a 2s . c o m*/ * the class * @param runtime * flag <code>true</code> if we need name for class loading, <code>false</code> if we need name * for source generation. * * @return the fully qualified name of given {@link Class} */ public static String getFullyQualifiedName(Class<?> clazz, boolean runtime) { Assert.isNotNull(clazz); if (runtime) { // primitive if (clazz.isPrimitive()) { if (clazz == void.class) { return "V"; } else if (clazz == boolean.class) { return "Z"; } else if (clazz == byte.class) { return "B"; } else if (clazz == char.class) { return "C"; } else if (clazz == short.class) { return "S"; } else if (clazz == int.class) { return "I"; } else if (clazz == long.class) { return "J"; } else if (clazz == float.class) { return "F"; } else if (clazz == double.class) { return "D"; } } // array if (clazz.isArray()) { return "[" + getFullyQualifiedName(clazz.getComponentType(), runtime); } // object return "L" + clazz.getName() + ";"; } else { // primitive if (clazz.isPrimitive()) { return clazz.getName(); } // array if (clazz.isArray()) { return getFullyQualifiedName(clazz.getComponentType(), runtime) + "[]"; } // object return clazz.getName().replace('/', '.').replace('$', '.'); } }
From source file:cz.jirutka.validator.collection.CommonEachValidator.java
protected <T extends ConstraintValidator<?, ?>> Map<Class, Class<? extends T>> categorizeValidatorsByType( List<Class<? extends T>> validatorClasses) { Map<Class, Class<? extends T>> validators = new LinkedHashMap<>(10); for (Class<? extends T> validator : validatorClasses) { Class<?> type = determineTargetType(validator); if (type.isArray()) continue; LOG.trace("Found validator {} for type {}", validator.getName(), type.getName()); validators.put(type, validator); }//ww w .j a va 2 s. c o m return unmodifiableMap(validators); }
From source file:com.freetmp.common.util.ClassUtils.java
public static boolean matchesTypeName(Class<?> clazz, String typeName) { return (typeName != null && (typeName.equals(clazz.getName()) || typeName.equals(clazz.getSimpleName()) || (clazz.isArray() && typeName.equals(getQualifiedNameForArray(clazz))))); }
From source file:com.google.feedserver.util.BeanUtil.java
public boolean isBean(Class<?> valueClass) { if (valueClass.isArray()) { return isBean(valueClass.getComponentType()); } else if (valueClass.isPrimitive()) { return false; } else {/*from w w w . ja v a 2 s . c om*/ return !primitiveTypes.contains(valueClass); } }
From source file:io.servicecomb.swagger.invocation.converter.ConverterMgr.java
protected Converter findArrayToCollection(Type src, Type target) { if (src.getClass().equals(Class.class) && ParameterizedType.class.isAssignableFrom(target.getClass())) { Class<?> srcCls = (Class<?>) src; ParameterizedType targetType = (ParameterizedType) target; Class<?> targetCls = (Class<?>) targetType.getRawType(); if (srcCls.isArray() && srcCls.getComponentType().equals(targetType.getActualTypeArguments()[0])) { if (List.class.isAssignableFrom(targetCls)) { return arrayToList; }//w w w. j a v a2s.co m if (Set.class.isAssignableFrom(targetCls)) { return arrayToSet; } } } return null; }
From source file:com.github.hateoas.forms.spring.SpringActionDescriptor.java
/** * Renders input fields for bean properties of bean to add or update or patch. * * @param sirenFields to add to//from w w w. j a v a 2 s. c o m * @param beanType to render * @param annotatedParameters which describes the method * @param annotatedParameter which requires the bean * @param currentCallValue sample call value */ static void recurseBeanCreationParams(final Class<?> beanType, final SpringActionInputParameter annotatedParameter, final Object currentCallValue, final String parentParamName, final Set<String> knownFields, final ActionInputParameterVisitor methodHandler, final List<ActionInputParameter> bodyInputParameters) { // TODO collection, map and object node creation are only describable by an annotation, not via type reflection if (ObjectNode.class.isAssignableFrom(beanType) || Map.class.isAssignableFrom(beanType) || Collection.class.isAssignableFrom(beanType) || beanType.isArray()) { return; // use @Input(include) to list parameter names, at least? Or mix with form builder? } try { List<ActionParameterType> parameterInfo = getClassInfo(beanType); for (int i = 0; i < parameterInfo.size(); i++) { ActionParameterType info = parameterInfo.get(i); Object propertyValue = info.getValue(currentCallValue); String value = invokeHandlerOrFollowRecurse(annotatedParameter, parentParamName, knownFields, methodHandler, bodyInputParameters, propertyValue, info); knownFields.add(value); } } catch (Exception e) { throw new RuntimeException("Failed to write input fields for constructor", e); } }
From source file:info.magnolia.jcr.node2bean.impl.TypeMappingImpl.java
/** * Resolves transformer from bean class or setter. *//*w w w. j a v a2 s . c o m*/ private Node2BeanTransformer resolveTransformer(Class<?> beanClass, Method writeMethod) throws Node2BeanException { if (!beanClass.isArray() && !beanClass.isPrimitive()) { // don't bother looking for a transformer if the property is an array or a primitive type Class<Node2BeanTransformer> transformerClass = null; Node2BeanTransformer transformer = null; if (writeMethod != null) { TransformedBy transformerAnnotation = writeMethod.getAnnotation(TransformedBy.class); transformerClass = transformerAnnotation == null ? null : (Class<Node2BeanTransformer>) transformerAnnotation.value(); transformer = transformerClass == null ? null : Components.getComponentProvider().newInstance(transformerClass); } if (transformer == null) { try { transformerClass = (Class<Node2BeanTransformer>) Class .forName(beanClass.getName() + "Transformer"); transformer = Components.getComponent(transformerClass); } catch (ClassNotFoundException e) { log.debug("No transformer found for bean [{}]", beanClass); } } return transformer; } return null; }
From source file:com.stehno.sjdbcx.reflection.extractor.RowMapperExtractor.java
public RowMapper extract(final Method method) { final com.stehno.sjdbcx.annotation.RowMapper mapper = AnnotationUtils.getAnnotation(method, com.stehno.sjdbcx.annotation.RowMapper.class); if (mapper == null) { Class mappedType = method.getReturnType(); if (Collection.class.isAssignableFrom(mappedType)) { mappedType = (Class) ((ParameterizedType) method.getGenericReturnType()) .getActualTypeArguments()[0]; } else if (mappedType.isArray()) { throw new UnsupportedOperationException("Auto-mapping for array return types is not yet supported"); } else if (mappedType.isPrimitive()) { if (mappedType == int.class || mappedType == long.class) { return new SingleColumnRowMapper(); } else if (mappedType == boolean.class) { return new RowMapper<Boolean>() { @Override/*from w w w . j ava 2 s . com*/ public Boolean mapRow(final ResultSet resultSet, final int i) throws SQLException { return resultSet.getBoolean(1); } }; } } return new BeanPropertyRowMapper(mappedType); } else { final String extractKey = mapper.value(); if (StringUtils.isEmpty(extractKey)) { return resolve((Class<RowMapper>) mapper.type()); } else { return resolve(extractKey); } } }
From source file:com.laxser.blitz.web.paramresolver.ParameterNameDiscovererImpl.java
protected String getParameterRawName(Class<?> clz) { if (ClassUtils.isPrimitiveOrWrapper(clz) // || clz == String.class // || Map.class.isAssignableFrom(clz) // || Collection.class.isAssignableFrom(clz) // || clz.isArray() // || clz == MultipartFile.class) { return null; }// www.j a v a 2 s .c om if (clz == MultipartFile.class) { return null; } return ClassUtils.getShortNameAsProperty(clz); }