Browse Source

polish

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2251 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Keith Donald 16 years ago
parent
commit
bb84ab261a
  1. 1
      org.springframework.core/src/main/java/org/springframework/core/convert/ConversionException.java
  2. 1
      org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java
  3. 1
      org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java
  4. 1
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java
  5. 6
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java
  6. 2
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java
  7. 2
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToMapConverter.java
  8. 2
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java
  9. 7
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java
  10. 4
      org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToCollectionConverter.java
  11. 12
      org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java
  12. 6
      org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToObjectConverter.java
  13. 1
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java

1
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionException.java

@ -24,6 +24,7 @@ import org.springframework.core.NestedRuntimeException; @@ -24,6 +24,7 @@ import org.springframework.core.NestedRuntimeException;
* @author Keith Donald
* @since 3.0
*/
@SuppressWarnings("serial")
public abstract class ConversionException extends NestedRuntimeException {
/**

1
org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java

@ -22,6 +22,7 @@ package org.springframework.core.convert; @@ -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;

1
org.springframework.core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java

@ -22,6 +22,7 @@ package org.springframework.core.convert; @@ -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;

1
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java

@ -39,6 +39,7 @@ final class ArrayToCollectionConverter implements GenericConverter { @@ -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);

6
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java

@ -44,7 +44,7 @@ final class CollectionToArrayConverter implements GenericConverter { @@ -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 { @@ -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 { @@ -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);

2
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java

@ -44,7 +44,7 @@ final class CollectionToCollectionConverter implements GenericConverter { @@ -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);

2
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToMapConverter.java

@ -42,7 +42,7 @@ final class CollectionToMapConverter implements GenericConverter { @@ -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);

2
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java

@ -44,7 +44,7 @@ final class CollectionToObjectConverter implements GenericConverter { @@ -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 "";

7
org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java

@ -35,7 +35,7 @@ final class ConversionUtils { @@ -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 { @@ -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;

4
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToCollectionConverter.java

@ -41,7 +41,7 @@ final class MapToCollectionConverter implements GenericConverter { @@ -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 { @@ -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);

12
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java

@ -40,7 +40,7 @@ final class MapToMapConverter implements GenericConverter { @@ -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 { @@ -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 { @@ -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 {

6
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToObjectConverter.java

@ -40,7 +40,7 @@ final class MapToObjectConverter implements GenericConverter { @@ -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 { @@ -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 { @@ -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);
}

1
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java

@ -39,6 +39,7 @@ final class ObjectToCollectionConverter implements GenericConverter { @@ -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…
Cancel
Save