Polishing

This commit is contained in:
Juergen Hoeller
2014-07-15 15:13:35 +02:00
parent a4968b9015
commit 2665d56209
6 changed files with 85 additions and 65 deletions

View File

@@ -129,19 +129,21 @@ public class TypeDescriptor implements Serializable {
}
/**
* Variation of {@link #getType()} that accounts for a primitive type by returning its object wrapper type.
* <p>This is useful for conversion service implementations that wish to normalize to object-based types
* and not work with primitive types directly.
* Variation of {@link #getType()} that accounts for a primitive type by
* returning its object wrapper type.
* <p>This is useful for conversion service implementations that wish to
* normalize to object-based types and not work with primitive types directly.
*/
public Class<?> getObjectType() {
return ClassUtils.resolvePrimitiveIfNecessary(getType());
}
/**
* The type of the backing class, method parameter, field, or property described by this TypeDescriptor.
* The type of the backing class, method parameter, field, or property
* described by this TypeDescriptor.
* <p>Returns primitive types as-is.
* <p>See {@link #getObjectType()} for a variation of this operation that resolves primitive types
* to their corresponding Object types if necessary.
* <p>See {@link #getObjectType()} for a variation of this operation that
* resolves primitive types to their corresponding Object types if necessary.
* @return the type, or {@code null}
* @see #getObjectType()
*/
@@ -234,7 +236,7 @@ public class TypeDescriptor implements Serializable {
* @return <tt>true</tt> if the annotation is present
*/
public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
return getAnnotation(annotationType) != null;
return (getAnnotation(annotationType) != null);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,11 +40,13 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter {
private final ConversionService conversionService;
public ArrayToArrayConverter(ConversionService conversionService) {
this.helperConverter = new CollectionToArrayConverter(conversionService);
this.conversionService = conversionService;
}
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object[].class, Object[].class));
@@ -56,12 +58,10 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
if ((conversionService instanceof GenericConversionService)
&& ((GenericConversionService) conversionService).canBypassConvert(
sourceType.getElementTypeDescriptor(),
targetType.getElementTypeDescriptor())) {
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (this.conversionService instanceof GenericConversionService &&
((GenericConversionService) this.conversionService).canBypassConvert(
sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor())) {
return source;
}
List<Object> sourceList = Arrays.asList(ObjectUtils.toObjectArray(source));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,8 @@ import org.springframework.util.ObjectUtils;
/**
* Converts an Array to a comma-delimited String.
* This implementation first adapts the source Array to a List, then delegates to {@link CollectionToStringConverter} to perform the target String conversion.
* This implementation first adapts the source Array to a List,
* then delegates to {@link CollectionToStringConverter} to perform the target String conversion.
*
* @author Keith Donald
* @since 3.0
@@ -36,10 +37,12 @@ final class ArrayToStringConverter implements ConditionalGenericConverter {
private final CollectionToStringConverter helperConverter;
public ArrayToStringConverter(ConversionService conversionService) {
this.helperConverter = new CollectionToStringConverter(conversionService);
}
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object[].class, String.class));