polish
This commit is contained in:
parent
374ea05028
commit
53f3d0b755
|
|
@ -24,6 +24,7 @@ import org.springframework.core.NestedRuntimeException;
|
|||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class ConversionException extends NestedRuntimeException {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.springframework.core.convert;
|
|||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class ConversionFailedException extends ConversionException {
|
||||
|
||||
private final TypeDescriptor sourceType;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.springframework.core.convert;
|
|||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class ConverterNotFoundException extends ConversionException {
|
||||
|
||||
private final TypeDescriptor sourceType;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ final class ArrayToCollectionConverter implements GenericConverter {
|
|||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ final class CollectionToArrayConverter implements GenericConverter {
|
|||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
}
|
||||
Collection sourceCollection = (Collection) source;
|
||||
Collection<?> sourceCollection = (Collection<?>) source;
|
||||
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
|
||||
if (sourceElementType == TypeDescriptor.NULL) {
|
||||
sourceElementType = getElementType(sourceCollection);
|
||||
|
|
@ -53,7 +53,7 @@ final class CollectionToArrayConverter implements GenericConverter {
|
|||
Object array = Array.newInstance(targetElementType.getType(), sourceCollection.size());
|
||||
int i = 0;
|
||||
if (sourceElementType == TypeDescriptor.NULL || sourceElementType.isAssignableTo(targetElementType)) {
|
||||
for (Iterator it = sourceCollection.iterator(); it.hasNext(); i++) {
|
||||
for (Iterator<?> it = sourceCollection.iterator(); it.hasNext(); i++) {
|
||||
Array.set(array, i, it.next());
|
||||
}
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ final class CollectionToArrayConverter implements GenericConverter {
|
|||
if (converter == null) {
|
||||
throw new ConverterNotFoundException(sourceElementType, targetElementType);
|
||||
}
|
||||
for (Iterator it = sourceCollection.iterator(); it.hasNext(); i++) {
|
||||
for (Iterator<?> it = sourceCollection.iterator(); it.hasNext(); i++) {
|
||||
Object sourceElement = it.next();
|
||||
Object targetElement = invokeConverter(converter, sourceElement, sourceElementType, targetElementType);
|
||||
Array.set(array, i, targetElement);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ final class CollectionToCollectionConverter implements GenericConverter {
|
|||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
}
|
||||
Collection sourceCollection = (Collection) source;
|
||||
Collection<?> sourceCollection = (Collection<?>) source;
|
||||
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
|
||||
if (sourceElementType == TypeDescriptor.NULL) {
|
||||
sourceElementType = getElementType(sourceCollection);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ final class CollectionToMapConverter implements GenericConverter {
|
|||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
}
|
||||
Collection sourceCollection = (Collection) source;
|
||||
Collection<?> sourceCollection = (Collection<?>) source;
|
||||
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
|
||||
if (sourceElementType == TypeDescriptor.NULL) {
|
||||
sourceElementType = getElementType(sourceCollection);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ final class CollectionToObjectConverter implements GenericConverter {
|
|||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
}
|
||||
Collection sourceCollection = (Collection) source;
|
||||
Collection<?> sourceCollection = (Collection<?>) source;
|
||||
if (sourceCollection.size() == 0) {
|
||||
if (targetType.typeEquals(String.class)) {
|
||||
return "";
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ final class ConversionUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static TypeDescriptor getElementType(Collection collection) {
|
||||
public static TypeDescriptor getElementType(Collection<?> collection) {
|
||||
for (Object element : collection) {
|
||||
if (element != null) {
|
||||
return TypeDescriptor.valueOf(element.getClass());
|
||||
|
|
@ -45,11 +45,12 @@ final class ConversionUtils {
|
|||
}
|
||||
|
||||
|
||||
public static List asList(Object array) {
|
||||
public static List<?> asList(Object array) {
|
||||
return array != null ? new ArrayList(array) : null;
|
||||
}
|
||||
|
||||
private static class ArrayList extends AbstractList implements RandomAccess, java.io.Serializable {
|
||||
@SuppressWarnings("serial")
|
||||
private static class ArrayList extends AbstractList<Object> implements RandomAccess, java.io.Serializable {
|
||||
|
||||
private Object array;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ final class MapToCollectionConverter implements GenericConverter {
|
|||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
}
|
||||
Map sourceMap = (Map) source;
|
||||
Map<?, ?> sourceMap = (Map<?, ?>) source;
|
||||
TypeDescriptor sourceKeyType = sourceType.getMapKeyTypeDescriptor();
|
||||
TypeDescriptor sourceValueType = sourceType.getMapValueTypeDescriptor();
|
||||
TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
|
||||
|
|
@ -58,7 +58,7 @@ final class MapToCollectionConverter implements GenericConverter {
|
|||
targetElementType, keysCompatible, valuesCompatible, this.conversionService);
|
||||
if (targetElementType.getType().equals(String.class)) {
|
||||
for (Object entry : sourceMap.entrySet()) {
|
||||
Map.Entry mapEntry = (Map.Entry) entry;
|
||||
Map.Entry<?, ?> mapEntry = (Map.Entry<?, ?>) entry;
|
||||
String property = converter.convertKey(mapEntry.getKey()) + "="
|
||||
+ converter.convertValue(mapEntry.getValue());
|
||||
target.add(property);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ final class MapToMapConverter implements GenericConverter {
|
|||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
}
|
||||
Map sourceMap = (Map) source;
|
||||
Map<?, ?> sourceMap = (Map<?, ?>) source;
|
||||
TypeDescriptor targetKeyType = targetType.getMapKeyTypeDescriptor();
|
||||
TypeDescriptor targetValueType = targetType.getMapValueTypeDescriptor();
|
||||
if (targetKeyType == TypeDescriptor.NULL && targetValueType == TypeDescriptor.NULL) {
|
||||
|
|
@ -77,11 +77,11 @@ final class MapToMapConverter implements GenericConverter {
|
|||
return targetMap;
|
||||
}
|
||||
|
||||
private TypeDescriptor[] getMapEntryTypes(Map sourceMap) {
|
||||
Class keyType = null;
|
||||
Class valueType = null;
|
||||
private TypeDescriptor[] getMapEntryTypes(Map<?, ?> sourceMap) {
|
||||
Class<?> keyType = null;
|
||||
Class<?> valueType = null;
|
||||
for (Object entry : sourceMap.entrySet()) {
|
||||
Map.Entry mapEntry = (Map.Entry) entry;
|
||||
Map.Entry<?, ?> mapEntry = (Map.Entry<?, ?>) entry;
|
||||
Object key = mapEntry.getKey();
|
||||
if (keyType == null && key != null) {
|
||||
keyType = key.getClass();
|
||||
|
|
@ -98,7 +98,7 @@ final class MapToMapConverter implements GenericConverter {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map compatibleMapWithoutEntryConversion(Map source, TypeDescriptor targetType) {
|
||||
private Map<?, ?> compatibleMapWithoutEntryConversion(Map<?, ?> source, TypeDescriptor targetType) {
|
||||
if (targetType.getType().isAssignableFrom(source.getClass())) {
|
||||
return source;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ final class MapToObjectConverter implements GenericConverter {
|
|||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
}
|
||||
Map sourceMap = (Map) source;
|
||||
Map<?, ?> sourceMap = (Map<?, ?>) source;
|
||||
if (sourceMap.size() == 0) {
|
||||
if (targetType.typeEquals(String.class)) {
|
||||
return "";
|
||||
|
|
@ -63,7 +63,7 @@ final class MapToObjectConverter implements GenericConverter {
|
|||
StringBuilder string = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Object entry : sourceMap.entrySet()) {
|
||||
Map.Entry mapEntry = (Map.Entry) entry;
|
||||
Map.Entry<?, ?> mapEntry = (Map.Entry<?, ?>) entry;
|
||||
if (i > 0) {
|
||||
string.append(DELIMITER);
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ final class MapToObjectConverter implements GenericConverter {
|
|||
StringBuilder string = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Object entry : sourceMap.entrySet()) {
|
||||
Map.Entry mapEntry = (Map.Entry) entry;
|
||||
Map.Entry<?, ?> mapEntry = (Map.Entry<?, ?>) entry;
|
||||
if (i > 0) {
|
||||
string.append(DELIMITER);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ final class ObjectToCollectionConverter implements GenericConverter {
|
|||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (source == null) {
|
||||
return this.conversionService.convertNullSource(sourceType, targetType);
|
||||
|
|
|
|||
Loading…
Reference in New Issue