Browse Source

polish

pull/23217/head
Keith Donald 17 years ago
parent
commit
25854bd764
  1. 16
      org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
  2. 2
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionGenericConverter.java
  3. 4
      org.springframework.core/src/main/java/org/springframework/core/convert/support/MapGenericConverter.java

16
org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

@ -38,7 +38,7 @@ import org.springframework.util.ClassUtils;
public class TypeDescriptor { public class TypeDescriptor {
/** /**
* Constant defining an 'empty' TypeDescriptor. * Constant defining an 'unknown' TypeDescriptor.
*/ */
public static final TypeDescriptor NULL = new TypeDescriptor(); public static final TypeDescriptor NULL = new TypeDescriptor();
@ -231,10 +231,16 @@ public class TypeDescriptor {
} }
} }
/**
* Returns map key type as a type descriptor.
*/
public TypeDescriptor getMapKeyTypeDescriptor() { public TypeDescriptor getMapKeyTypeDescriptor() {
return TypeDescriptor.valueOf(getMapKeyType()); return TypeDescriptor.valueOf(getMapKeyType());
} }
/**
* Returns map value type as a type descriptor.
*/
public TypeDescriptor getMapValueTypeDescriptor() { public TypeDescriptor getMapValueTypeDescriptor() {
return TypeDescriptor.valueOf(getMapValueType()); return TypeDescriptor.valueOf(getMapValueType());
} }
@ -270,7 +276,7 @@ public class TypeDescriptor {
*/ */
public boolean isAssignableValue(Object obj) { public boolean isAssignableValue(Object obj) {
Class<?> type = getType(); Class<?> type = getType();
return (type != null && ClassUtils.isAssignableValue(getType(), obj)); return type != null && ClassUtils.isAssignableValue(getType(), obj);
} }
/** /**
@ -279,7 +285,11 @@ public class TypeDescriptor {
* @return true if this type is assignable to the target * @return true if this type is assignable to the target
*/ */
public boolean isAssignableTo(TypeDescriptor targetType) { public boolean isAssignableTo(TypeDescriptor targetType) {
return ClassUtils.isAssignable(targetType.getType(), getType()); if (targetType == TypeDescriptor.NULL) {
return false;
}
Class<?> type = getType();
return type != null && ClassUtils.isAssignable(targetType.getType(), type);
} }
/** /**

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

@ -67,7 +67,7 @@ class CollectionGenericConverter implements GenericConverter {
return TypeDescriptor.valueOf(element.getClass()); return TypeDescriptor.valueOf(element.getClass());
} }
} }
return null; return TypeDescriptor.NULL;
} }
private Collection compatibleCollectionWithoutElementConversion(Collection source, TypeDescriptor targetType) { private Collection compatibleCollectionWithoutElementConversion(Collection source, TypeDescriptor targetType) {

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

@ -31,11 +31,11 @@ class MapGenericConverter implements GenericConverter {
return compatibleMapWithoutEntryConversion(sourceMap, targetType); return compatibleMapWithoutEntryConversion(sourceMap, targetType);
} }
boolean keysCompatible = false; boolean keysCompatible = false;
if (sourceKeyType != null && targetKeyType != null && sourceKeyType.isAssignableTo(targetKeyType)) { if (sourceKeyType != TypeDescriptor.NULL && targetKeyType != TypeDescriptor.NULL && sourceKeyType.isAssignableTo(targetKeyType)) {
keysCompatible = true; keysCompatible = true;
} }
boolean valuesCompatible = false; boolean valuesCompatible = false;
if (sourceValueType != null && targetValueType != null && sourceValueType.isAssignableTo(targetValueType)) { if (sourceValueType != TypeDescriptor.NULL && targetValueType != TypeDescriptor.NULL && sourceValueType.isAssignableTo(targetValueType)) {
valuesCompatible = true; valuesCompatible = true;
} }
if (keysCompatible && valuesCompatible) { if (keysCompatible && valuesCompatible) {

Loading…
Cancel
Save