diff --git a/spring-core/src/main/java/org/springframework/core/convert/AbstractDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/AbstractDescriptor.java index 99e7494dba..86995f3262 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/AbstractDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/AbstractDescriptor.java @@ -35,7 +35,7 @@ abstract class AbstractDescriptor { Assert.notNull(type, "Type must not be null"); this.type = type; } - + public Class getType() { return this.type; @@ -48,13 +48,13 @@ abstract class AbstractDescriptor { } else if (isArray()) { Class elementType = getType().getComponentType(); - return new TypeDescriptor(nested(elementType, 0)); + return new TypeDescriptor(nested(elementType, 0)); } else { return null; } } - + public TypeDescriptor getMapKeyTypeDescriptor() { if (isMap()) { Class keyType = resolveMapKeyType(); @@ -64,7 +64,7 @@ abstract class AbstractDescriptor { return null; } } - + public TypeDescriptor getMapValueTypeDescriptor() { if (isMap()) { Class valueType = resolveMapValueType(); @@ -96,33 +96,33 @@ abstract class AbstractDescriptor { throw new IllegalStateException("Not a collection, array, or map: cannot resolve nested value types"); } } - + // subclassing hooks - + public abstract Annotation[] getAnnotations(); protected abstract Class resolveCollectionElementType(); - + protected abstract Class resolveMapKeyType(); - + protected abstract Class resolveMapValueType(); - + protected abstract AbstractDescriptor nested(Class type, int typeIndex); - + // internal helpers - + private boolean isCollection() { return Collection.class.isAssignableFrom(getType()); } - + private boolean isArray() { return getType().isArray(); } - + private boolean isMap() { return Map.class.isAssignableFrom(getType()); } - + } diff --git a/spring-core/src/main/java/org/springframework/core/convert/BeanPropertyDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/BeanPropertyDescriptor.java index de2ff2fd92..8be6b0e2c6 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/BeanPropertyDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/BeanPropertyDescriptor.java @@ -29,9 +29,9 @@ class BeanPropertyDescriptor extends AbstractDescriptor { private final Property property; private final MethodParameter methodParameter; - + private final Annotation[] annotations; - + public BeanPropertyDescriptor(Property property) { super(property.getType()); @@ -45,7 +45,7 @@ class BeanPropertyDescriptor extends AbstractDescriptor { public Annotation[] getAnnotations() { return this.annotations; } - + @Override protected Class resolveCollectionElementType() { return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter); @@ -65,10 +65,10 @@ class BeanPropertyDescriptor extends AbstractDescriptor { protected AbstractDescriptor nested(Class type, int typeIndex) { MethodParameter methodParameter = new MethodParameter(this.methodParameter); methodParameter.increaseNestingLevel(); - methodParameter.setTypeIndexForCurrentLevel(typeIndex); + methodParameter.setTypeIndexForCurrentLevel(typeIndex); return new BeanPropertyDescriptor(type, this.property, methodParameter, this.annotations); } - + // internal @@ -78,5 +78,5 @@ class BeanPropertyDescriptor extends AbstractDescriptor { this.methodParameter = methodParameter; this.annotations = annotations; } - + } diff --git a/spring-core/src/main/java/org/springframework/core/convert/ClassDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/ClassDescriptor.java index 527fced98b..b73d477018 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ClassDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ClassDescriptor.java @@ -52,5 +52,5 @@ class ClassDescriptor extends AbstractDescriptor { protected AbstractDescriptor nested(Class type, int typeIndex) { return new ClassDescriptor(type); } - + } diff --git a/spring-core/src/main/java/org/springframework/core/convert/ConversionException.java b/spring-core/src/main/java/org/springframework/core/convert/ConversionException.java index 90d4780397..f93e2e6746 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ConversionException.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ConversionException.java @@ -22,7 +22,7 @@ import org.springframework.core.NestedRuntimeException; * Base class for exceptions thrown by the conversion system. * * @author Keith Donald - * @since 3.0 + * @since 3.0 */ @SuppressWarnings("serial") public abstract class ConversionException extends NestedRuntimeException { diff --git a/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java index abd323cdd9..378016c30b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ConversionService.java @@ -63,7 +63,7 @@ public interface ConversionService { * @throws IllegalArgumentException if targetType is null */ T convert(Object source, Class targetType); - + /** * Convert the source to targetType. * The TypeDescriptors provide additional context about the source and target locations where conversion will occur, often object fields or property locations. @@ -77,4 +77,4 @@ public interface ConversionService { */ Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType); -} \ No newline at end of file +} diff --git a/spring-core/src/main/java/org/springframework/core/convert/FieldDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/FieldDescriptor.java index 75c5ce82a4..9d951bb312 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/FieldDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/FieldDescriptor.java @@ -55,7 +55,7 @@ class FieldDescriptor extends AbstractDescriptor { public Annotation[] getAnnotations() { return TypeDescriptor.nullSafeAnnotations(this.field.getAnnotations()); } - + @Override protected Class resolveCollectionElementType() { return GenericCollectionTypeResolver.getCollectionFieldType(this.field, this.nestingLevel, this.typeIndexesPerLevel); diff --git a/spring-core/src/main/java/org/springframework/core/convert/ParameterDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/ParameterDescriptor.java index 5f0fa28174..773464c8a1 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ParameterDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ParameterDescriptor.java @@ -34,7 +34,7 @@ class ParameterDescriptor extends AbstractDescriptor { super(methodParameter.getParameterType()); if (methodParameter.getNestingLevel() != 1) { throw new IllegalArgumentException("MethodParameter argument must have its nestingLevel set to 1"); - } + } this.methodParameter = methodParameter; } @@ -53,7 +53,7 @@ class ParameterDescriptor extends AbstractDescriptor { return TypeDescriptor.nullSafeAnnotations(this.methodParameter.getParameterAnnotations()); } } - + @Override protected Class resolveCollectionElementType() { return GenericCollectionTypeResolver.getCollectionParameterType(this.methodParameter); diff --git a/spring-core/src/main/java/org/springframework/core/convert/Property.java b/spring-core/src/main/java/org/springframework/core/convert/Property.java index 2fa51345cd..d1e9ed19f7 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/Property.java +++ b/spring-core/src/main/java/org/springframework/core/convert/Property.java @@ -50,7 +50,7 @@ public final class Property { private final Method writeMethod; private final String name; - + private final MethodParameter methodParameter; private final Annotation[] annotations; @@ -112,7 +112,7 @@ public final class Property { // package private - + MethodParameter getMethodParameter() { return this.methodParameter; } @@ -123,7 +123,7 @@ public final class Property { // internal helpers - + private String resolveName() { if (this.readMethod != null) { int index = this.readMethod.getName().indexOf("get"); @@ -166,27 +166,27 @@ public final class Property { } return write; } - + private MethodParameter resolveReadMethodParameter() { if (getReadMethod() == null) { return null; } - return resolveParameterType(new MethodParameter(getReadMethod(), -1)); + return resolveParameterType(new MethodParameter(getReadMethod(), -1)); } private MethodParameter resolveWriteMethodParameter() { if (getWriteMethod() == null) { return null; } - return resolveParameterType(new MethodParameter(getWriteMethod(), 0)); + return resolveParameterType(new MethodParameter(getWriteMethod(), 0)); } private MethodParameter resolveParameterType(MethodParameter parameter) { // needed to resolve generic property types that parameterized by sub-classes e.g. T getFoo(); GenericTypeResolver.resolveParameterType(parameter, getObjectType()); - return parameter; + return parameter; } - + private Annotation[] resolveAnnotations() { Map, Annotation> annMap = new LinkedHashMap, Annotation>(); Method readMethod = getReadMethod(); @@ -238,4 +238,4 @@ public final class Property { } } -} \ No newline at end of file +} diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalGenericConverter.java b/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalGenericConverter.java index 7fbf43f2e1..fd52ca7d87 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalGenericConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/ConditionalGenericConverter.java @@ -47,5 +47,5 @@ public interface ConditionalGenericConverter extends GenericConverter { * @return true if conversion should be performed, false otherwise */ boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType); - + } diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java b/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java index f936b08b53..8417f581bc 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java @@ -21,6 +21,8 @@ package org.springframework.core.convert.converter; * Implementations of this interface are thread-safe and can be shared. * * @author Keith Donald + * @param The source type + * @param The target type * @since 3.0 */ public interface Converter { diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterFactory.java b/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterFactory.java index eecf9800dc..fd4e5909dc 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterFactory.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterFactory.java @@ -20,7 +20,7 @@ package org.springframework.core.convert.converter; * A factory for "ranged" converters that can convert objects from S to subtypes of R. * * @author Keith Donald - * @since 3.0 + * @since 3.0 * @param The source type converters created by this factory can convert from * @param The target range (or base) type converters created by this factory can convert to; * for example {@link Number} for a set of number subtypes. diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java b/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java index a2e0da852c..9280c4eac3 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/ConverterRegistry.java @@ -24,7 +24,7 @@ package org.springframework.core.convert.converter; * @since 3.0 */ public interface ConverterRegistry { - + /** * Add a plain converter to this registry. * The convertible sourceType/targetType pair is derived from the Converter's parameterized types. @@ -44,11 +44,11 @@ public interface ConverterRegistry { * Add a generic converter to this registry. */ void addConverter(GenericConverter converter); - + /** * Add a ranged converter factory to this registry. * The convertible sourceType/rangeType pair is derived from the ConverterFactory's parameterized types. - * @throws IllegalArgumentException if the parameterized types could not be resolved. + * @throws IllegalArgumentException if the parameterized types could not be resolved. */ void addConverterFactory(ConverterFactory converterFactory); diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java index e487afd035..288072f90b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java @@ -27,8 +27,8 @@ import org.springframework.util.ObjectUtils; /** * Converts an Array to another Array. - * First adapts the source array to a List, then delegates to {@link CollectionToArrayConverter} to perform the target array conversion. - * + * First adapts the source array to a List, then delegates to {@link CollectionToArrayConverter} to perform the target array conversion. + * * @author Keith Donald * @since 3.0 */ @@ -48,7 +48,7 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter { return this.helperConverter.matches(sourceType, targetType); } - public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java index 301c563655..4e028b49a9 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java @@ -32,7 +32,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter; *

First, creates a new Collection of the requested targetType. * Then adds each array element to the target collection. * Will perform an element conversion from the source component type to the collection's parameterized type if necessary. - * + * * @author Keith Donald * @since 3.0 */ @@ -57,7 +57,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter { public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; - } + } int length = Array.getLength(source); Collection target = CollectionFactory.createCollection(targetType.getType(), length); if (targetType.getElementTypeDescriptor() == null) { @@ -73,7 +73,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter { sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor()); target.add(targetElement); } - } + } return target; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java index 6d66a5ddf7..1db3b2ec7f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java @@ -26,7 +26,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter; /** * Converts an Array to an Object by returning the first array element after converting it to the desired targetType. - * + * * @author Keith Donald * @since 3.0 */ diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java index a8e6bfea28..15e9e608ed 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java @@ -28,7 +28,7 @@ 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. - * + * * @author Keith Donald * @since 3.0 */ diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/CharacterToNumberFactory.java b/spring-core/src/main/java/org/springframework/core/convert/support/CharacterToNumberFactory.java index 896ad148f9..8f9642b0fb 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/CharacterToNumberFactory.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/CharacterToNumberFactory.java @@ -36,7 +36,7 @@ import org.springframework.util.NumberUtils; * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal - * @see NumberUtils + * @see NumberUtils */ final class CharacterToNumberFactory implements ConverterFactory { @@ -47,11 +47,11 @@ final class CharacterToNumberFactory implements ConverterFactory implements Converter { private final Class targetType; - + public CharacterToNumber(Class targetType) { this.targetType = targetType; } - + public T convert(Character source) { return NumberUtils.convertNumberToTargetClass((short) source.charValue(), this.targetType); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java index e053dddbb3..b9913ef6b4 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java @@ -61,4 +61,4 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter { return this.conversionService.convert(firstElement, sourceType.elementTypeDescriptor(firstElement), targetType); } -} \ No newline at end of file +} diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/FallbackObjectToStringConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/FallbackObjectToStringConverter.java index ce7741bc57..204a912b0c 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/FallbackObjectToStringConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/FallbackObjectToStringConverter.java @@ -49,4 +49,4 @@ final class FallbackObjectToStringConverter implements ConditionalGenericConvert return (source != null ? source.toString() : null); } -} \ No newline at end of file +} diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index 95a2ef772c..5856489988 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -102,7 +102,7 @@ public class GenericConversionService implements ConfigurableConversionService { GenericConverter.ConvertiblePair typeInfo = new GenericConverter.ConvertiblePair(sourceType, targetType); addConverter(new ConverterAdapter(typeInfo, converter)); } - + public void addConverter(GenericConverter converter) { Set convertibleTypes = converter.getConvertibleTypes(); for (GenericConverter.ConvertiblePair convertibleType : convertibleTypes) { @@ -119,7 +119,7 @@ public class GenericConversionService implements ConfigurableConversionService { } addConverter(new ConverterFactoryAdapter(typeInfo, converterFactory)); } - + public void removeConvertible(Class sourceType, Class targetType) { getSourceConverterMap(sourceType).remove(targetType); invalidateCache(); @@ -131,7 +131,7 @@ public class GenericConversionService implements ConfigurableConversionService { public boolean canConvert(Class sourceType, Class targetType) { if (targetType == null) { throw new IllegalArgumentException("The targetType to convert to cannot be null"); - } + } return canConvert(sourceType != null ? TypeDescriptor.valueOf(sourceType) : null, TypeDescriptor.valueOf(targetType)); } @@ -150,7 +150,7 @@ public class GenericConversionService implements ConfigurableConversionService { public T convert(Object source, Class targetType) { if (targetType == null) { throw new IllegalArgumentException("The targetType to convert to cannot be null"); - } + } return (T) convert(source, TypeDescriptor.forObject(source), TypeDescriptor.valueOf(targetType)); } @@ -172,7 +172,7 @@ public class GenericConversionService implements ConfigurableConversionService { return handleResult(sourceType, targetType, result); } else { - return handleConverterNotFound(source, sourceType, targetType); + return handleConverterNotFound(source, sourceType, targetType); } } @@ -189,7 +189,7 @@ public class GenericConversionService implements ConfigurableConversionService { public Object convert(Object source, TypeDescriptor targetType) { return convert(source, TypeDescriptor.forObject(source), targetType); } - + public String toString() { List converterStrings = new ArrayList(); for (Map, MatchableConverters> targetConverters : this.converters.values()) { @@ -203,7 +203,7 @@ public class GenericConversionService implements ConfigurableConversionService { for (String converterString : converterStrings) { builder.append("\t"); builder.append(converterString); - builder.append("\n"); + builder.append("\n"); } return builder.toString(); } @@ -243,7 +243,7 @@ public class GenericConversionService implements ConfigurableConversionService { else { converter = findConverterForClassPair(sourceType, targetType); if (converter == null) { - converter = getDefaultConverter(sourceType, targetType); + converter = getDefaultConverter(sourceType, targetType); } if (converter != null) { this.converterCache.put(key, converter); @@ -285,7 +285,7 @@ public class GenericConversionService implements ConfigurableConversionService { } return matchable; } - + private void invalidateCache() { this.converterCache.clear(); } @@ -366,7 +366,7 @@ public class GenericConversionService implements ConfigurableConversionService { } } Map, MatchableConverters> objectConverters = getTargetConvertersForSource(Object.class); - return getMatchingConverterForTarget(sourceType, targetType, objectConverters); + return getMatchingConverterForTarget(sourceType, targetType, objectConverters); } } @@ -473,9 +473,9 @@ public class GenericConversionService implements ConfigurableConversionService { } else { throw new ConverterNotFoundException(sourceType, targetType); - } + } } - + private Object handleResult(TypeDescriptor sourceType, TypeDescriptor targetType, Object result) { if (result == null) { assertNotPrimitiveTargetType(sourceType, targetType); @@ -486,9 +486,9 @@ public class GenericConversionService implements ConfigurableConversionService { if (targetType.isPrimitive()) { throw new ConversionFailedException(sourceType, targetType, null, new IllegalArgumentException("A null value cannot be assigned to a primitive type")); - } + } } - + @SuppressWarnings("unchecked") private final class ConverterAdapter implements GenericConverter { @@ -516,7 +516,7 @@ public class GenericConversionService implements ConfigurableConversionService { } return this.converter.convert(source); } - + public String toString() { return this.typeInfo.getSourceType().getName() + " -> " + this.typeInfo.getTargetType().getName() + " : " + this.converter.toString(); @@ -613,14 +613,14 @@ public class GenericConversionService implements ConfigurableConversionService { private static final class ConverterCacheKey { private final TypeDescriptor sourceType; - + private final TypeDescriptor targetType; - + public ConverterCacheKey(TypeDescriptor sourceType, TypeDescriptor targetType) { this.sourceType = sourceType; this.targetType = targetType; } - + public boolean equals(Object other) { if (this == other) { return true; @@ -631,11 +631,11 @@ public class GenericConversionService implements ConfigurableConversionService { ConverterCacheKey otherKey = (ConverterCacheKey) other; return this.sourceType.equals(otherKey.sourceType) && this.targetType.equals(otherKey.targetType); } - + public int hashCode() { return this.sourceType.hashCode() * 29 + this.targetType.hashCode(); } - + public String toString() { return "ConverterCacheKey [sourceType = " + this.sourceType + ", targetType = " + this.targetType + "]"; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java index 865ac12b05..59921bbe35 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java @@ -84,7 +84,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter { private static Method getValueOfMethodOn(Class clazz, Class sourceParameterType) { return ClassUtils.getStaticMethod(clazz, "valueOf", sourceParameterType); } - + private static Constructor getConstructor(Class clazz, Class sourceParameterType) { return ClassUtils.getConstructorIfAvailable(clazz, sourceParameterType); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java index 21d03febb2..4bf32af3e8 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java @@ -28,7 +28,7 @@ import org.springframework.util.StringUtils; /** * Converts a comma-delimited String to an Array. * Only matches if String.class can be converted to the target array element type. - * + * * @author Keith Donald * @since 3.0 */ @@ -47,11 +47,11 @@ final class StringToArrayConverter implements ConditionalGenericConverter { public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { return this.conversionService.canConvert(sourceType, targetType.getElementTypeDescriptor()); } - + public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; - } + } String string = (String) source; String[] fields = StringUtils.commaDelimitedListToStringArray(string); Object target = Array.newInstance(targetType.getElementTypeDescriptor().getType(), fields.length); @@ -63,4 +63,4 @@ final class StringToArrayConverter implements ConditionalGenericConverter { return target; } -} \ No newline at end of file +} diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java index 7708a91e52..1e23ee61bb 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java @@ -45,7 +45,7 @@ final class StringToBooleanConverter implements Converter { falseValues.add("no"); falseValues.add("0"); } - + public Boolean convert(String source) { String value = source.trim(); if ("".equals(value)) { diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java index ad6ebf71bc..553425f377 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java @@ -54,7 +54,7 @@ final class StringToCollectionConverter implements ConditionalGenericConverter { } @SuppressWarnings("unchecked") - public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } @@ -64,14 +64,14 @@ final class StringToCollectionConverter implements ConditionalGenericConverter { if (targetType.getElementTypeDescriptor() == null) { for (String field : fields) { target.add(field.trim()); - } + } } else { for (String field : fields) { Object targetElement = this.conversionService.convert(field.trim(), sourceType, targetType.getElementTypeDescriptor()); target.add(targetElement); - } + } } return target; } -} \ No newline at end of file +} diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToPropertiesConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToPropertiesConverter.java index 77740bc828..e97cae67ef 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToPropertiesConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToPropertiesConverter.java @@ -24,7 +24,7 @@ import org.springframework.core.convert.converter.Converter; /** * Converts a String to a Properties by calling Properties#load(java.io.InputStream). * Uses ISO-8559-1 encoding required by Properties. - * + * * @author Keith Donald * @since 3.0 */ diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java index 20e6a5f9d7..67f5bcf616 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java @@ -68,13 +68,13 @@ public class CollectionToCollectionConverterTests { } conversionService.addConverterFactory(new StringToNumberConverterFactory()); assertTrue(conversionService.canConvert(sourceType, targetType)); - @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") List result = (List) conversionService.convert(list, sourceType, targetType); assertFalse(list.equals(result)); assertEquals((Integer) 9, result.get(0)); assertEquals((Integer) 37, result.get(1)); } - + public ArrayList scalarListTarget; @Test @@ -148,7 +148,7 @@ public class CollectionToCollectionConverterTests { } public List>> objectToCollection; - + @Test @SuppressWarnings("unchecked") public void stringToCollection() throws Exception { @@ -157,7 +157,7 @@ public class CollectionToCollectionConverterTests { list.add(Arrays.asList("37,23")); conversionService.addConverterFactory(new StringToNumberConverterFactory()); conversionService.addConverter(new StringToCollectionConverter(conversionService)); - conversionService.addConverter(new ObjectToCollectionConverter(conversionService)); + conversionService.addConverter(new ObjectToCollectionConverter(conversionService)); conversionService.addConverter(new CollectionToObjectConverter(conversionService)); TypeDescriptor sourceType = TypeDescriptor.forObject(list); TypeDescriptor targetType = new TypeDescriptor(getClass().getField("objectToCollection")); @@ -204,10 +204,10 @@ public class CollectionToCollectionConverterTests { List resources = new ArrayList(); resources.add(null); resources.add(null); - TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("strings")); + TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("strings")); assertEquals(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources")))); } - + public List strings; @Test(expected=ConversionFailedException.class) @@ -271,9 +271,9 @@ public class CollectionToCollectionConverterTests { return null; } } - + public static class TestResource extends BaseResource { - + } @Test diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java index 0a26c9a26f..e5d7e27d3a 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionTests.java @@ -60,7 +60,7 @@ public class DefaultConversionTests { public void testStringToCharacter() { assertEquals(Character.valueOf('1'), conversionService.convert("1", Character.class)); } - + @Test public void testStringToCharacterEmptyString() { assertEquals(null, conversionService.convert("", Character.class)); @@ -208,7 +208,7 @@ public class DefaultConversionTests { public void testStringToEnum() throws Exception { assertEquals(Foo.BAR, conversionService.convert("BAR", Foo.class)); } - + @Test public void testStringToEnumEmptyString() { assertEquals(null, conversionService.convert("", Foo.class)); @@ -233,12 +233,12 @@ public class DefaultConversionTests { String str = "test"; assertSame(str, conversionService.convert(str, String.class)); } - + @Test public void testNumberToNumber() { assertEquals(Long.valueOf(1), conversionService.convert(Integer.valueOf(1), Long.class)); } - + @Test(expected=ConversionFailedException.class) public void testNumberToNumberNotSupportedNumber() { conversionService.convert(Integer.valueOf(1), CustomNumber.class); @@ -265,9 +265,9 @@ public class DefaultConversionTests { public long longValue() { return 0; } - + } - + @Test public void testNumberToCharacter() { assertEquals(Character.valueOf('A'), conversionService.convert(Integer.valueOf(65), Character.class)); @@ -312,11 +312,11 @@ public class DefaultConversionTests { public class ColorConverter implements Converter { public Color convert(String source) { if (!source.startsWith("#")) source = "#" + source; return Color.decode(source); } } - + public void handlerMethod(List color) { - + } - + @Test public void convertArrayToCollectionImpl() { LinkedList result = conversionService.convert(new String[] { "1", "2", "3" }, LinkedList.class); @@ -333,7 +333,7 @@ public class DefaultConversionTests { public static enum FooEnum { BAR, BAZ } - + @Test public void convertArrayToString() { String result = conversionService.convert(new String[] { "1", "2", "3" }, String.class); @@ -505,7 +505,7 @@ public class DefaultConversionTests { Object result = conversionService.convert(source, new TypeDescriptor(getClass().getField("assignableTarget"))); assertEquals(source, result); } - + @Test public void convertObjectToCollection() { List result = (List) conversionService.convert(3L, List.class); @@ -592,7 +592,7 @@ public class DefaultConversionTests { assertEquals(new Integer(2), bar.get(1)); assertEquals(new Integer(3), bar.get(2)); } - + @Test public void collection() { List strings = new ArrayList(); @@ -652,7 +652,7 @@ public class DefaultConversionTests { assertEquals("baz", result.get("bar")); assertEquals("boop", result.get("baz")); } - + // generic object conversion @Test @@ -664,7 +664,7 @@ public class DefaultConversionTests { public void convertObjectToStringStringConstructorPresent() { assertEquals("123456789", conversionService.convert(new SSN("123456789"), String.class)); } - + @Test public void convertObjectToStringNotSupported() { assertFalse(conversionService.canConvert(TestEntity.class, String.class)); @@ -685,17 +685,17 @@ public class DefaultConversionTests { public void convertObjectToObjectNoValueOFMethodOrConstructor() { conversionService.convert(new Long(3), SSN.class); } - + public Object assignableTarget; - + private static class SSN { - + private String value; - + public SSN(String value) { this.value = value; } - + public boolean equals(Object o) { if (!(o instanceof SSN)) { return false; @@ -703,24 +703,24 @@ public class DefaultConversionTests { SSN ssn = (SSN) o; return this.value.equals(ssn.value); } - + public int hashCode() { return value.hashCode(); } - + public String toString() { return value; } } - + private static class ISBN { private String value; - + private ISBN(String value) { this.value = value; } - + public boolean equals(Object o) { if (!(o instanceof ISBN)) { return false; @@ -728,20 +728,20 @@ public class DefaultConversionTests { ISBN isbn = (ISBN) o; return this.value.equals(isbn.value); } - + public int hashCode() { return value.hashCode(); } - + public String toString() { return value; } - + public static ISBN valueOf(String value) { return new ISBN(value); } } - + @Test public void convertObjectToObjectFinderMethod() { TestEntity e = conversionService.convert(1L, TestEntity.class); @@ -763,18 +763,18 @@ public class DefaultConversionTests { public static class TestEntity { private Long id; - + public TestEntity(Long id) { this.id = id; } - + public Long getId() { return id; } - + public static TestEntity findTestEntity(Long id) { return new TestEntity(id); } } - + }