Skip to content

Commit 9400fb3

Browse files
committed
replaced custom asList method with Arrays.asList(ObjectUtils.toObjectArray(...))
1 parent cc0bd73 commit 9400fb3

File tree

4 files changed

+20
-39
lines changed

4 files changed

+20
-39
lines changed

org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
package org.springframework.core.convert.support;
1818

19-
import static org.springframework.core.convert.support.ConversionUtils.asList;
19+
import java.util.Arrays;
2020

2121
import org.springframework.core.convert.TypeDescriptor;
2222
import org.springframework.core.convert.converter.GenericConverter;
23+
import org.springframework.util.ObjectUtils;
2324

2425
/**
2526
* Converts from a source array to a target array type.
@@ -40,7 +41,7 @@ public Class<?>[][] getConvertibleTypes() {
4041
}
4142

4243
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
43-
return this.helperConverter.convert(asList(source), sourceType, targetType);
44+
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
4445
}
4546

4647
}

org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToMapConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package org.springframework.core.convert.support;
1818

19-
import static org.springframework.core.convert.support.ConversionUtils.asList;
20-
19+
import java.util.Arrays;
2120
import java.util.Map;
2221

2322
import org.springframework.core.convert.TypeDescriptor;
2423
import org.springframework.core.convert.converter.GenericConverter;
24+
import org.springframework.util.ObjectUtils;
2525

2626
/**
2727
* Converts from an array to a Map.
@@ -42,7 +42,7 @@ public Class<?>[][] getConvertibleTypes() {
4242
}
4343

4444
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
45-
return this.helperConverter.convert(asList(source), sourceType, targetType);
45+
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
4646
}
4747

4848
}

org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
package org.springframework.core.convert.support;
1818

19-
import static org.springframework.core.convert.support.ConversionUtils.asList;
19+
import java.util.Arrays;
2020

2121
import org.springframework.core.convert.TypeDescriptor;
2222
import org.springframework.core.convert.converter.GenericConverter;
23+
import org.springframework.util.ObjectUtils;
2324

2425
/**
2526
* Converts from an array to a single Object.
@@ -36,11 +37,11 @@ public ArrayToObjectConverter(GenericConversionService conversionService) {
3637
}
3738

3839
public Class<?>[][] getConvertibleTypes() {
39-
return new Class<?>[][] { { Object[].class, Object.class } };
40+
return new Class<?>[][] {{Object[].class, Object.class}};
4041
}
4142

4243
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
43-
return this.helperConverter.convert(asList(source), sourceType, targetType);
44+
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
4445
}
4546

4647
}

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

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,30 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.core.convert.support;
1718

18-
import java.lang.reflect.Array;
19-
import java.util.AbstractList;
2019
import java.util.Collection;
21-
import java.util.List;
2220
import java.util.Map;
23-
import java.util.RandomAccess;
2421

2522
import org.springframework.core.convert.ConversionFailedException;
2623
import org.springframework.core.convert.TypeDescriptor;
2724
import org.springframework.core.convert.converter.GenericConverter;
2825

29-
final class ConversionUtils {
26+
/**
27+
* Internal utilities for the conversion package.
28+
*
29+
* @author Keith Donald
30+
* @since 3.0
31+
*/
32+
abstract class ConversionUtils {
3033

31-
private ConversionUtils() {
32-
}
33-
3434
public static Object invokeConverter(GenericConverter converter, Object source, TypeDescriptor sourceType,
3535
TypeDescriptor targetType) {
3636
try {
3737
return converter.convert(source, sourceType, targetType);
38-
} catch (Exception ex) {
38+
}
39+
catch (Exception ex) {
3940
throw new ConversionFailedException(sourceType, targetType, source, ex);
4041
}
4142
}
@@ -69,26 +70,4 @@ public static TypeDescriptor[] getMapEntryTypes(Map<?, ?> sourceMap) {
6970
return new TypeDescriptor[] { TypeDescriptor.valueOf(keyType), TypeDescriptor.valueOf(valueType) };
7071
}
7172

72-
public static List<?> asList(Object array) {
73-
return array != null ? new ArrayList(array) : null;
74-
}
75-
76-
@SuppressWarnings("serial")
77-
private static class ArrayList extends AbstractList<Object> implements RandomAccess, java.io.Serializable {
78-
79-
private Object array;
80-
81-
ArrayList(Object array) {
82-
this.array = array;
83-
}
84-
85-
public int size() {
86-
return Array.getLength(array);
87-
}
88-
89-
public Object get(int index) {
90-
return Array.get(array, index);
91-
}
92-
93-
}
9473
}

0 commit comments

Comments
 (0)