Polishing
Issue: SPR-12483
This commit is contained in:
@@ -27,8 +27,9 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an Array to another Array. First adapts the source array to a List, then
|
* Converts an array to another array. First adapts the source array to a List,
|
||||||
* delegates to {@link CollectionToArrayConverter} to perform the target array conversion.
|
* then delegates to {@link CollectionToArrayConverter} to perform the target
|
||||||
|
* array conversion.
|
||||||
*
|
*
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,7 +25,8 @@ import org.springframework.core.convert.TypeDescriptor;
|
|||||||
import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
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.
|
* Converts an array to an Object by returning the first array element
|
||||||
|
* after converting it to the desired target type.
|
||||||
*
|
*
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
@@ -34,10 +35,12 @@ final class ArrayToObjectConverter implements ConditionalGenericConverter {
|
|||||||
|
|
||||||
private final ConversionService conversionService;
|
private final ConversionService conversionService;
|
||||||
|
|
||||||
|
|
||||||
public ArrayToObjectConverter(ConversionService conversionService) {
|
public ArrayToObjectConverter(ConversionService conversionService) {
|
||||||
this.conversionService = conversionService;
|
this.conversionService = conversionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||||
return Collections.singleton(new ConvertiblePair(Object[].class, Object.class));
|
return Collections.singleton(new ConvertiblePair(Object[].class, Object.class));
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an Array to a comma-delimited String.
|
* Converts an array to a comma-delimited String. First adapts the source array
|
||||||
* This implementation first adapts the source Array to a List,
|
* to a List, then delegates to {@link CollectionToStringConverter} to perform
|
||||||
* then delegates to {@link CollectionToStringConverter} to perform the target String conversion.
|
* the target String conversion.
|
||||||
*
|
*
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,8 +25,8 @@ import org.springframework.core.convert.TypeDescriptor;
|
|||||||
import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an Object to a single-element Array containing the Object.
|
* Converts an Object to a single-element array containing the Object.
|
||||||
* Will convert the Object to the target Array's component type if necessary.
|
* Will convert the Object to the target array's component type if necessary.
|
||||||
*
|
*
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
@@ -35,10 +35,12 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter {
|
|||||||
|
|
||||||
private final ConversionService conversionService;
|
private final ConversionService conversionService;
|
||||||
|
|
||||||
|
|
||||||
public ObjectToArrayConverter(ConversionService conversionService) {
|
public ObjectToArrayConverter(ConversionService conversionService) {
|
||||||
this.conversionService = conversionService;
|
this.conversionService = conversionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||||
return Collections.singleton(new ConvertiblePair(Object.class, Object[].class));
|
return Collections.singleton(new ConvertiblePair(Object.class, Object[].class));
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ import org.springframework.core.convert.converter.Converter;
|
|||||||
import org.springframework.core.convert.converter.ConverterFactory;
|
import org.springframework.core.convert.converter.ConverterFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts from a String to a java.lang.Enum by calling {@link Enum#valueOf(Class, String)}.
|
* Converts from a String to a {@link java.lang.Enum} by calling {@link Enum#valueOf(Class, String)}.
|
||||||
*
|
*
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
final class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
|
final class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,7 +35,8 @@ final class StringToEnumConverterFactory implements ConverterFactory<String, Enu
|
|||||||
enumType = enumType.getSuperclass();
|
enumType = enumType.getSuperclass();
|
||||||
}
|
}
|
||||||
if (enumType == null) {
|
if (enumType == null) {
|
||||||
throw new IllegalArgumentException("The target type " + targetType.getName() + " does not refer to an enum");
|
throw new IllegalArgumentException(
|
||||||
|
"The target type " + targetType.getName() + " does not refer to an enum");
|
||||||
}
|
}
|
||||||
return new StringToEnum(enumType);
|
return new StringToEnum(enumType);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user