From f51ad17a86a8ae6b804c4b26e89ccd22cfa7e597 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 27 Nov 2009 01:35:45 +0000 Subject: [PATCH] replaced custom asList method with Arrays.asList(ObjectUtils.toObjectArray(...)) git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2520 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../support/ArrayToArrayConverter.java | 5 ++- .../convert/support/ArrayToMapConverter.java | 6 +-- .../support/ArrayToObjectConverter.java | 7 ++-- .../core/convert/support/ConversionUtils.java | 41 +++++-------------- 4 files changed, 20 insertions(+), 39 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java index 6be42c31bbd..6fc38e79fe2 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java @@ -16,10 +16,11 @@ package org.springframework.core.convert.support; -import static org.springframework.core.convert.support.ConversionUtils.asList; +import java.util.Arrays; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; +import org.springframework.util.ObjectUtils; /** * Converts from a source array to a target array type. @@ -40,7 +41,7 @@ final class ArrayToArrayConverter implements GenericConverter { } public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { - return this.helperConverter.convert(asList(source), sourceType, targetType); + return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType); } } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToMapConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToMapConverter.java index c296721eefa..5377c6facf0 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToMapConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToMapConverter.java @@ -16,12 +16,12 @@ package org.springframework.core.convert.support; -import static org.springframework.core.convert.support.ConversionUtils.asList; - +import java.util.Arrays; import java.util.Map; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; +import org.springframework.util.ObjectUtils; /** * Converts from an array to a Map. @@ -42,7 +42,7 @@ final class ArrayToMapConverter implements GenericConverter { } public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { - return this.helperConverter.convert(asList(source), sourceType, targetType); + return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType); } } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java index 663eb32e70e..25914ce3903 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java @@ -16,10 +16,11 @@ package org.springframework.core.convert.support; -import static org.springframework.core.convert.support.ConversionUtils.asList; +import java.util.Arrays; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; +import org.springframework.util.ObjectUtils; /** * Converts from an array to a single Object. @@ -36,11 +37,11 @@ final class ArrayToObjectConverter implements GenericConverter { } public Class[][] getConvertibleTypes() { - return new Class[][] { { Object[].class, Object.class } }; + return new Class[][] {{Object[].class, Object.class}}; } public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { - return this.helperConverter.convert(asList(source), sourceType, targetType); + return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType); } } diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java index 382d0f3d52d..b99dcf4c7bf 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java @@ -13,29 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.core.convert.support; -import java.lang.reflect.Array; -import java.util.AbstractList; import java.util.Collection; -import java.util.List; import java.util.Map; -import java.util.RandomAccess; import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; -final class ConversionUtils { +/** + * Internal utilities for the conversion package. + * + * @author Keith Donald + * @since 3.0 + */ +abstract class ConversionUtils { - private ConversionUtils() { - } - public static Object invokeConverter(GenericConverter converter, Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { try { return converter.convert(source, sourceType, targetType); - } catch (Exception ex) { + } + catch (Exception ex) { throw new ConversionFailedException(sourceType, targetType, source, ex); } } @@ -69,26 +70,4 @@ final class ConversionUtils { return new TypeDescriptor[] { TypeDescriptor.valueOf(keyType), TypeDescriptor.valueOf(valueType) }; } - public static List asList(Object array) { - return array != null ? new ArrayList(array) : null; - } - - @SuppressWarnings("serial") - private static class ArrayList extends AbstractList implements RandomAccess, java.io.Serializable { - - private Object array; - - ArrayList(Object array) { - this.array = array; - } - - public int size() { - return Array.getLength(array); - } - - public Object get(int index) { - return Array.get(array, index); - } - - } }