From 25854bd7643f00a4ddbad85e5aee8afd3a215f02 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Fri, 18 Sep 2009 21:07:53 +0000 Subject: [PATCH] polish --- .../core/convert/TypeDescriptor.java | 16 +++++++++++++--- .../support/CollectionGenericConverter.java | 2 +- .../convert/support/MapGenericConverter.java | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 4a41eae0f87..42b2cb3b428 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -38,7 +38,7 @@ import org.springframework.util.ClassUtils; public class TypeDescriptor { /** - * Constant defining an 'empty' TypeDescriptor. + * Constant defining an 'unknown' 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() { return TypeDescriptor.valueOf(getMapKeyType()); } + /** + * Returns map value type as a type descriptor. + */ public TypeDescriptor getMapValueTypeDescriptor() { return TypeDescriptor.valueOf(getMapValueType()); } @@ -270,7 +276,7 @@ public class TypeDescriptor { */ public boolean isAssignableValue(Object obj) { 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 */ 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); } /** diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionGenericConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionGenericConverter.java index aa9ffb4ff73..597a55e6817 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionGenericConverter.java +++ b/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 null; + return TypeDescriptor.NULL; } private Collection compatibleCollectionWithoutElementConversion(Collection source, TypeDescriptor targetType) { diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapGenericConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapGenericConverter.java index 1141ddf884d..d72d22c3b57 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/MapGenericConverter.java +++ b/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); } boolean keysCompatible = false; - if (sourceKeyType != null && targetKeyType != null && sourceKeyType.isAssignableTo(targetKeyType)) { + if (sourceKeyType != TypeDescriptor.NULL && targetKeyType != TypeDescriptor.NULL && sourceKeyType.isAssignableTo(targetKeyType)) { keysCompatible = true; } boolean valuesCompatible = false; - if (sourceValueType != null && targetValueType != null && sourceValueType.isAssignableTo(targetValueType)) { + if (sourceValueType != TypeDescriptor.NULL && targetValueType != TypeDescriptor.NULL && sourceValueType.isAssignableTo(targetValueType)) { valuesCompatible = true; } if (keysCompatible && valuesCompatible) {