Browse Source

SPR-8718 Minor polish

pull/7/head
Rossen Stoyanchev 13 years ago
parent
commit
4199d772cc
  1. 6
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java
  2. 6
      org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java

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

@ -57,7 +57,7 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert @@ -57,7 +57,7 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
if (source == null) {
return null;
}
boolean isCopyRequired = !targetType.getType().isInstance(source);
boolean copyRequired = !targetType.getType().isInstance(source);
Collection<?> sourceCollection = (Collection<?>) source;
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), sourceCollection.size());
if (targetType.getElementTypeDescriptor() == null) {
@ -70,11 +70,11 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert @@ -70,11 +70,11 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
target.add(targetElement);
if (sourceElement != targetElement) {
isCopyRequired = true;
copyRequired = true;
}
}
}
return isCopyRequired ? target : source;
return copyRequired ? target : source;
}
}

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

@ -57,7 +57,7 @@ final class MapToMapConverter implements ConditionalGenericConverter { @@ -57,7 +57,7 @@ final class MapToMapConverter implements ConditionalGenericConverter {
if (source == null) {
return null;
}
boolean isCopyRequired = !targetType.getType().isInstance(source);
boolean copyRequired = !targetType.getType().isInstance(source);
Map<Object, Object> sourceMap = (Map<Object, Object>) source;
Map<Object, Object> targetMap = CollectionFactory.createMap(targetType.getType(), sourceMap.size());
for (Map.Entry<Object, Object> entry : sourceMap.entrySet()) {
@ -67,10 +67,10 @@ final class MapToMapConverter implements ConditionalGenericConverter { @@ -67,10 +67,10 @@ final class MapToMapConverter implements ConditionalGenericConverter {
Object targetValue = convertValue(sourceValue, sourceType, targetType.getMapValueTypeDescriptor());
targetMap.put(targetKey, targetValue);
if (sourceKey != targetKey || sourceValue != targetValue) {
isCopyRequired = true;
copyRequired = true;
}
}
return isCopyRequired ? targetMap : sourceMap;
return copyRequired ? targetMap : sourceMap;
}
// internal helpers

Loading…
Cancel
Save