Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c8c0e827
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c8c0e827
编写于
10月 12, 2012
作者:
P
Phillip Webb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish trailing whitespace
上级
29d60448
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
31 deletion
+31
-31
spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java
...mework/core/convert/support/DefaultConversionService.java
+11
-11
spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
...k/core/convert/support/GenericConversionServiceTests.java
+20
-20
未找到文件。
spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java
浏览文件 @
c8c0e827
...
...
@@ -43,7 +43,7 @@ public class DefaultConversionService extends GenericConversionService {
}
// static utility methods
/**
* Add converters appropriate for most environments.
* @param converterRegistry the registry of converters to add to (must also be castable to ConversionService)
...
...
@@ -54,9 +54,9 @@ public class DefaultConversionService extends GenericConversionService {
addCollectionConverters
(
converterRegistry
);
addFallbackConverters
(
converterRegistry
);
}
// internal helpers
private
static
void
addScalarConverters
(
ConverterRegistry
converterRegistry
)
{
converterRegistry
.
addConverter
(
new
StringToBooleanConverter
());
converterRegistry
.
addConverter
(
Boolean
.
class
,
String
.
class
,
new
ObjectToStringConverter
());
...
...
@@ -65,16 +65,16 @@ public class DefaultConversionService extends GenericConversionService {
converterRegistry
.
addConverter
(
Number
.
class
,
String
.
class
,
new
ObjectToStringConverter
());
converterRegistry
.
addConverterFactory
(
new
NumberToNumberConverterFactory
());
converterRegistry
.
addConverter
(
new
StringToCharacterConverter
());
converterRegistry
.
addConverter
(
Character
.
class
,
String
.
class
,
new
ObjectToStringConverter
());
converterRegistry
.
addConverter
(
new
NumberToCharacterConverter
());
converterRegistry
.
addConverterFactory
(
new
CharacterToNumberFactory
());
converterRegistry
.
addConverterFactory
(
new
StringToEnumConverterFactory
());
converterRegistry
.
addConverter
(
Enum
.
class
,
String
.
class
,
new
EnumToStringConverter
());
converterRegistry
.
addConverter
(
new
StringToLocaleConverter
());
converterRegistry
.
addConverter
(
Locale
.
class
,
String
.
class
,
new
ObjectToStringConverter
());
...
...
@@ -83,13 +83,13 @@ public class DefaultConversionService extends GenericConversionService {
}
private
static
void
addCollectionConverters
(
ConverterRegistry
converterRegistry
)
{
ConversionService
conversionService
=
(
ConversionService
)
converterRegistry
;
ConversionService
conversionService
=
(
ConversionService
)
converterRegistry
;
converterRegistry
.
addConverter
(
new
ArrayToCollectionConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
CollectionToArrayConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
ArrayToArrayConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
CollectionToCollectionConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
MapToMapConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
MapToMapConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
ArrayToStringConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
StringToArrayConverter
(
conversionService
));
...
...
@@ -103,12 +103,12 @@ public class DefaultConversionService extends GenericConversionService {
converterRegistry
.
addConverter
(
new
CollectionToObjectConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
ObjectToCollectionConverter
(
conversionService
));
}
private
static
void
addFallbackConverters
(
ConverterRegistry
converterRegistry
)
{
ConversionService
conversionService
=
(
ConversionService
)
converterRegistry
;
converterRegistry
.
addConverter
(
new
ObjectToObjectConverter
());
converterRegistry
.
addConverter
(
new
IdToEntityConverter
(
conversionService
));
converterRegistry
.
addConverter
(
new
FallbackObjectToStringConverter
());
converterRegistry
.
addConverter
(
new
FallbackObjectToStringConverter
());
}
}
\ No newline at end of file
}
spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
浏览文件 @
c8c0e827
...
...
@@ -61,9 +61,9 @@ public class GenericConversionServiceTests {
public
void
canConvert
()
{
assertFalse
(
conversionService
.
canConvert
(
String
.
class
,
Integer
.
class
));
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
assertTrue
(
conversionService
.
canConvert
(
String
.
class
,
Integer
.
class
));
assertTrue
(
conversionService
.
canConvert
(
String
.
class
,
Integer
.
class
));
}
@Test
public
void
canConvertAssignable
()
{
assertTrue
(
conversionService
.
canConvert
(
String
.
class
,
String
.
class
));
...
...
@@ -71,29 +71,29 @@ public class GenericConversionServiceTests {
assertTrue
(
conversionService
.
canConvert
(
boolean
.
class
,
boolean
.
class
));
assertTrue
(
conversionService
.
canConvert
(
boolean
.
class
,
Boolean
.
class
));
}
@Test
public
void
canConvertIllegalArgumentNullTargetType
()
{
try
{
assertFalse
(
conversionService
.
canConvert
(
String
.
class
,
null
));
fail
(
"Should have failed"
);
}
catch
(
IllegalArgumentException
e
)
{
}
try
{
assertFalse
(
conversionService
.
canConvert
(
TypeDescriptor
.
valueOf
(
String
.
class
),
null
));
fail
(
"Should have failed"
);
}
catch
(
IllegalArgumentException
e
)
{
}
}
@Test
public
void
canConvertNullSourceType
()
{
assertTrue
(
conversionService
.
canConvert
(
null
,
Integer
.
class
));
assertTrue
(
conversionService
.
canConvert
(
null
,
TypeDescriptor
.
valueOf
(
Integer
.
class
)));
}
@Test
public
void
convert
()
{
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
...
...
@@ -208,7 +208,7 @@ public class GenericConversionServiceTests {
}
// SPR-8718
@Test
(
expected
=
ConverterNotFoundException
.
class
)
public
void
convertSuperTarget
()
{
conversionService
.
addConverter
(
new
ColorConverter
());
...
...
@@ -235,11 +235,11 @@ public class GenericConversionServiceTests {
public
void
convertObjectToPrimitiveViaConverterFactory
()
{
assertFalse
(
conversionService
.
canConvert
(
String
.
class
,
int
.
class
));
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
assertTrue
(
conversionService
.
canConvert
(
String
.
class
,
int
.
class
));
assertTrue
(
conversionService
.
canConvert
(
String
.
class
,
int
.
class
));
Integer
three
=
conversionService
.
convert
(
"3"
,
int
.
class
);
assertEquals
(
3
,
three
.
intValue
());
}
@Test
public
void
genericConverterDelegatingBackToConversionServiceConverterNotFound
()
{
conversionService
.
addConverter
(
new
ObjectToArrayConverter
(
conversionService
));
...
...
@@ -398,7 +398,7 @@ public class GenericConversionServiceTests {
watch
.
stop
();
System
.
out
.
println
(
watch
.
prettyPrint
());
}
@Test
public
void
testPerformance2
()
throws
Exception
{
GenericConversionService
conversionService
=
new
DefaultConversionService
();
...
...
@@ -420,7 +420,7 @@ public class GenericConversionServiceTests {
target
.
add
(
Integer
.
valueOf
(
element
));
}
}
watch
.
stop
();
watch
.
stop
();
System
.
out
.
println
(
watch
.
prettyPrint
());
}
...
...
@@ -435,7 +435,7 @@ public class GenericConversionServiceTests {
source
.
put
(
"1"
,
"1"
);
source
.
put
(
"2"
,
"2"
);
source
.
put
(
"3"
,
"3"
);
TypeDescriptor
td
=
new
TypeDescriptor
(
getClass
().
getField
(
"map"
));
TypeDescriptor
td
=
new
TypeDescriptor
(
getClass
().
getField
(
"map"
));
for
(
int
i
=
0
;
i
<
1000000
;
i
++)
{
conversionService
.
convert
(
source
,
TypeDescriptor
.
forObject
(
source
),
td
);
}
...
...
@@ -447,10 +447,10 @@ public class GenericConversionServiceTests {
target
.
put
(
entry
.
getKey
(),
Integer
.
valueOf
(
entry
.
getValue
()));
}
}
watch
.
stop
();
watch
.
stop
();
System
.
out
.
println
(
watch
.
prettyPrint
());
}
public
static
Map
<
String
,
Integer
>
map
;
@Test
...
...
@@ -554,19 +554,19 @@ public class GenericConversionServiceTests {
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
assertTrue
(
conversionService
.
canConvert
(
String
.
class
,
Integer
[].
class
));
}
@Test
public
void
stringToCollectionCanConvert
()
throws
Exception
{
conversionService
.
addConverter
(
new
StringToCollectionConverter
(
conversionService
));
assertTrue
(
conversionService
.
canConvert
(
String
.
class
,
Collection
.
class
));
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"stringToCollection"
));
assertFalse
(
conversionService
.
canConvert
(
TypeDescriptor
.
valueOf
(
String
.
class
),
targetType
));
assertFalse
(
conversionService
.
canConvert
(
TypeDescriptor
.
valueOf
(
String
.
class
),
targetType
));
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
assertTrue
(
conversionService
.
canConvert
(
TypeDescriptor
.
valueOf
(
String
.
class
),
targetType
));
assertTrue
(
conversionService
.
canConvert
(
TypeDescriptor
.
valueOf
(
String
.
class
),
targetType
));
}
public
Collection
<
Integer
>
stringToCollection
;
@Test
public
void
testConvertiblePairsInSet
()
throws
Exception
{
Set
<
GenericConverter
.
ConvertiblePair
>
set
=
new
HashSet
<
GenericConverter
.
ConvertiblePair
>();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录