Skip to content

Commit b465f20

Browse files
committed
renamed internal *GenericConverters to *Converters
1 parent 0543a29 commit b465f20

17 files changed

+272
-99
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@
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

1819
import static org.springframework.core.convert.support.ConversionUtils.asList;
1920

2021
import org.springframework.core.convert.TypeDescriptor;
2122

22-
final class ArrayToMapGenericConverter implements GenericConverter {
23+
/**
24+
* Converts from a source array to a target array type.
25+
*
26+
* @author Keith Donald
27+
* @since 3.0
28+
*/
29+
final class ArrayToArrayConverter implements GenericConverter {
2330

2431
private final GenericConverter helperConverter;
2532

26-
public ArrayToMapGenericConverter(GenericConversionService conversionService) {
27-
this.helperConverter = new CollectionToMapGenericConverter(conversionService);
33+
public ArrayToArrayConverter(GenericConversionService conversionService) {
34+
this.helperConverter = new CollectionToArrayConverter(conversionService);
2835
}
2936

3037
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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

1819
import static org.springframework.core.convert.support.ConversionUtils.invokeConverter;
@@ -24,11 +25,17 @@
2425
import org.springframework.core.convert.ConverterNotFoundException;
2526
import org.springframework.core.convert.TypeDescriptor;
2627

27-
final class ArrayToCollectionGenericConverter implements GenericConverter {
28+
/**
29+
* Converts from an array to a collection.
30+
*
31+
* @author Keith Donald
32+
* @since 3.0
33+
*/
34+
final class ArrayToCollectionConverter implements GenericConverter {
2835

2936
private final GenericConversionService conversionService;
3037

31-
public ArrayToCollectionGenericConverter(GenericConversionService conversionService) {
38+
public ArrayToCollectionConverter(GenericConversionService conversionService) {
3239
this.conversionService = conversionService;
3340
}
3441

@@ -41,7 +48,8 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
4148
for (int i = 0; i < length; i++) {
4249
collection.add(Array.get(source, i));
4350
}
44-
} else {
51+
}
52+
else {
4553
GenericConverter converter = this.conversionService.getConverter(sourceElementType, targetElementType);
4654
if (converter == null) {
4755
throw new ConverterNotFoundException(sourceElementType, targetElementType);
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.core.convert.support;
1716

18-
import static org.springframework.core.convert.support.ConversionUtils.asList;
17+
package org.springframework.core.convert.support;
1918

2019
import org.springframework.core.convert.TypeDescriptor;
20+
import static org.springframework.core.convert.support.ConversionUtils.*;
2121

22-
final class ArrayToArrayGenericConverter implements GenericConverter {
22+
/**
23+
* Converts from an array to a Map.
24+
*
25+
* @author Keith Donald
26+
* @since 3.0
27+
*/
28+
final class ArrayToMapConverter implements GenericConverter {
2329

2430
private final GenericConverter helperConverter;
2531

26-
public ArrayToArrayGenericConverter(GenericConversionService conversionService) {
27-
this.helperConverter = new CollectionToArrayGenericConverter(conversionService);
32+
public ArrayToMapConverter(GenericConversionService conversionService) {
33+
this.helperConverter = new CollectionToMapConverter(conversionService);
2834
}
2935

3036
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@
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

1819
import static org.springframework.core.convert.support.ConversionUtils.asList;
1920

2021
import org.springframework.core.convert.TypeDescriptor;
2122

22-
final class ArrayToObjectGenericConverter implements GenericConverter {
23+
/**
24+
* Converts from an array to a single Object.
25+
*
26+
* @author Keith Donald
27+
* @since 3.0
28+
*/
29+
final class ArrayToObjectConverter implements GenericConverter {
2330

24-
private CollectionToObjectGenericConverter helperConverter;
31+
private final CollectionToObjectConverter helperConverter;
2532

26-
public ArrayToObjectGenericConverter(GenericConversionService conversionService) {
27-
this.helperConverter = new CollectionToObjectGenericConverter(conversionService);
33+
public ArrayToObjectConverter(GenericConversionService conversionService) {
34+
this.helperConverter = new CollectionToObjectConverter(conversionService);
2835
}
2936

3037
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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

1819
import static org.springframework.core.convert.support.ConversionUtils.getElementType;
@@ -25,11 +26,17 @@
2526
import org.springframework.core.convert.ConverterNotFoundException;
2627
import org.springframework.core.convert.TypeDescriptor;
2728

28-
final class CollectionToArrayGenericConverter implements GenericConverter {
29+
/**
30+
* Converts from a Collection to an array.
31+
*
32+
* @author Keith Donald
33+
* @since 3.0
34+
*/
35+
final class CollectionToArrayConverter implements GenericConverter {
2936

3037
private final GenericConversionService conversionService;
3138

32-
public CollectionToArrayGenericConverter(GenericConversionService conversionService) {
39+
public CollectionToArrayConverter(GenericConversionService conversionService) {
3340
this.conversionService = conversionService;
3441
}
3542

@@ -46,7 +53,8 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
4653
for (Iterator it = sourceCollection.iterator(); it.hasNext(); i++) {
4754
Array.set(array, i, it.next());
4855
}
49-
} else {
56+
}
57+
else {
5058
GenericConverter converter = this.conversionService.getConverter(sourceElementType, targetElementType);
5159
if (converter == null) {
5260
throw new ConverterNotFoundException(sourceElementType, targetElementType);
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,31 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.core.convert.support;
1716

18-
import static org.springframework.core.convert.support.ConversionUtils.getElementType;
19-
import static org.springframework.core.convert.support.ConversionUtils.invokeConverter;
17+
package org.springframework.core.convert.support;
2018

2119
import java.util.Collection;
2220

2321
import org.springframework.core.CollectionFactory;
2422
import org.springframework.core.convert.ConverterNotFoundException;
2523
import org.springframework.core.convert.TypeDescriptor;
24+
import static org.springframework.core.convert.support.ConversionUtils.*;
2625

27-
final class CollectionToCollectionGenericConverter implements GenericConverter {
26+
/**
27+
* Converts from a source Collection to target Collection type.
28+
*
29+
* @author Keith Donald
30+
* @since 3.0
31+
*/
32+
final class CollectionToCollectionConverter implements GenericConverter {
2833

2934
private final GenericConversionService conversionService;
3035

31-
public CollectionToCollectionGenericConverter(GenericConversionService conversionService) {
36+
public CollectionToCollectionConverter(GenericConversionService conversionService) {
3237
this.conversionService = conversionService;
3338
}
3439

40+
@SuppressWarnings("unchecked")
3541
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
3642
Collection sourceCollection = (Collection) source;
3743
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
@@ -42,7 +48,8 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
4248
if (sourceElementType == TypeDescriptor.NULL || sourceElementType.isAssignableTo(targetElementType)) {
4349
if (sourceType.isAssignableTo(targetType)) {
4450
return sourceCollection;
45-
} else {
51+
}
52+
else {
4653
Collection target = CollectionFactory.createCollection(targetType.getType(), sourceCollection.size());
4754
target.addAll(sourceCollection);
4855
return target;
@@ -59,4 +66,4 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
5966
return target;
6067
}
6168

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

18-
import static org.springframework.core.convert.support.ConversionUtils.getElementType;
17+
package org.springframework.core.convert.support;
1918

2019
import java.util.Collection;
2120
import java.util.Map;
2221

2322
import org.springframework.core.CollectionFactory;
2423
import org.springframework.core.convert.TypeDescriptor;
24+
import static org.springframework.core.convert.support.ConversionUtils.*;
2525

26-
final class CollectionToMapGenericConverter implements GenericConverter {
26+
/**
27+
* Converts from a Collection to a Map.
28+
*
29+
* @author Keith Donald
30+
* @since 3.0
31+
*/
32+
final class CollectionToMapConverter implements GenericConverter {
2733

2834
private final GenericConversionService conversionService;
2935

30-
public CollectionToMapGenericConverter(GenericConversionService conversionService) {
36+
public CollectionToMapConverter(GenericConversionService conversionService) {
3137
this.conversionService = conversionService;
3238
}
3339

40+
@SuppressWarnings("unchecked")
3441
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
3542
Collection sourceCollection = (Collection) source;
3643
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
@@ -56,13 +63,15 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
5663
String[] property = parseProperty((String) element);
5764
target.put(property[0], property[1]);
5865
}
59-
} else {
66+
}
67+
else {
6068
for (Object element : sourceCollection) {
6169
target.put(element, element);
6270
}
6371
}
6472
return target;
65-
} else {
73+
}
74+
else {
6675
Map target = CollectionFactory.createMap(targetType.getType(), sourceCollection.size());
6776
MapEntryConverter converter = new MapEntryConverter(sourceElementType, sourceElementType, targetKeyType,
6877
targetValueType, keysCompatible, valuesCompatible, conversionService);
@@ -73,7 +82,8 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
7382
Object targetValue = converter.convertValue(property[1]);
7483
target.put(targetKey, targetValue);
7584
}
76-
} else {
85+
}
86+
else {
7787
for (Object element : sourceCollection) {
7888
Object targetKey = converter.convertKey(element);
7989
Object targetValue = converter.convertValue(element);
@@ -87,10 +97,10 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
8797
private String[] parseProperty(String string) {
8898
String[] property = string.split("=");
8999
if (property.length < 2) {
90-
throw new IllegalArgumentException("Invalid String property '" + property
91-
+ "'; properties should be in the format name=value");
100+
throw new IllegalArgumentException("Invalid String property '" + string +
101+
"'; properties should be in the format name=value");
92102
}
93103
return property;
94104
}
95105

96-
}
106+
}
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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

1819
import static org.springframework.core.convert.support.ConversionUtils.getElementType;
@@ -23,13 +24,19 @@
2324
import org.springframework.core.convert.ConverterNotFoundException;
2425
import org.springframework.core.convert.TypeDescriptor;
2526

26-
final class CollectionToObjectGenericConverter implements GenericConverter {
27+
/**
28+
* Converts from a Collection to a single Object.
29+
*
30+
* @author Keith Donald
31+
* @since 3.0
32+
*/
33+
final class CollectionToObjectConverter implements GenericConverter {
2734

2835
private static final String DELIMITER = ",";
2936

3037
private final GenericConversionService conversionService;
3138

32-
public CollectionToObjectGenericConverter(GenericConversionService conversionService) {
39+
public CollectionToObjectConverter(GenericConversionService conversionService) {
3340
this.conversionService = conversionService;
3441
}
3542

@@ -38,10 +45,12 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
3845
if (sourceCollection.size() == 0) {
3946
if (targetType.typeEquals(String.class)) {
4047
return "";
41-
} else {
48+
}
49+
else {
4250
return null;
4351
}
44-
} else {
52+
}
53+
else {
4554
if (targetType.typeEquals(String.class)) {
4655
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
4756
if (sourceElementType == TypeDescriptor.NULL) {
@@ -58,7 +67,8 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
5867
i++;
5968
}
6069
return string.toString();
61-
} else {
70+
}
71+
else {
6272
GenericConverter converter = this.conversionService.getConverter(sourceElementType, targetType);
6373
if (converter == null) {
6474
throw new ConverterNotFoundException(sourceElementType, targetType);
@@ -75,15 +85,17 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
7585
}
7686
return string.toString();
7787
}
78-
} else {
88+
}
89+
else {
7990
Object firstElement = sourceCollection.iterator().next();
8091
TypeDescriptor sourceElementType = sourceType.getElementTypeDescriptor();
8192
if (sourceElementType == TypeDescriptor.NULL && firstElement != null) {
8293
sourceElementType = TypeDescriptor.valueOf(firstElement.getClass());
8394
}
8495
if (sourceElementType == TypeDescriptor.NULL || sourceElementType.isAssignableTo(targetType)) {
8596
return firstElement;
86-
} else {
97+
}
98+
else {
8799
GenericConverter converter = this.conversionService.getConverter(sourceElementType, targetType);
88100
if (converter == null) {
89101
throw new ConverterNotFoundException(sourceElementType, targetType);
@@ -93,4 +105,5 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
93105
}
94106
}
95107
}
108+
96109
}

0 commit comments

Comments
 (0)