Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
8ee03637
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,体验更适合开发者的 AI 搜索 >>
提交
8ee03637
编写于
4月 17, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mergePropertiesIntoMap copies non-String values as well (SPR-5669)
上级
c225b44f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
7 deletion
+27
-7
org.springframework.core/src/main/java/org/springframework/util/CollectionUtils.java
...c/main/java/org/springframework/util/CollectionUtils.java
+7
-2
org.springframework.core/src/test/java/org/springframework/util/CollectionUtilsTests.java
...t/java/org/springframework/util/CollectionUtilsTests.java
+20
-5
未找到文件。
org.springframework.core/src/main/java/org/springframework/util/CollectionUtils.java
浏览文件 @
8ee03637
/*
* Copyright 2002-200
8
the original author or authors.
* Copyright 2002-200
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -99,7 +99,12 @@ public abstract class CollectionUtils {
if
(
props
!=
null
)
{
for
(
Enumeration
en
=
props
.
propertyNames
();
en
.
hasMoreElements
();)
{
String
key
=
(
String
)
en
.
nextElement
();
map
.
put
(
key
,
props
.
getProperty
(
key
));
Object
value
=
props
.
getProperty
(
key
);
if
(
value
==
null
)
{
// Potentially a non-String value...
value
=
props
.
get
(
key
);
}
map
.
put
(
key
,
value
);
}
}
}
...
...
org.springframework.core/src/test/java/org/springframework/util/CollectionUtilsTests.java
浏览文件 @
8ee03637
/*
* Copyright 2002-200
7
the original author or authors.
* Copyright 2002-200
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -28,15 +28,17 @@ import java.util.Map;
import
java.util.Properties
;
import
java.util.Set
;
import
junit.framework.TestCase
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Rick Evans
*/
public
class
CollectionUtilsTests
extends
TestCase
{
public
class
CollectionUtilsTests
{
@Test
public
void
testIsEmpty
()
{
assertTrue
(
CollectionUtils
.
isEmpty
((
Set
)
null
));
assertTrue
(
CollectionUtils
.
isEmpty
((
Map
)
null
));
...
...
@@ -52,6 +54,7 @@ public class CollectionUtilsTests extends TestCase {
assertFalse
(
CollectionUtils
.
isEmpty
(
map
));
}
@Test
public
void
testMergeArrayIntoCollection
()
{
Object
[]
arr
=
new
Object
[]
{
"value1"
,
"value2"
};
List
list
=
new
LinkedList
();
...
...
@@ -63,6 +66,7 @@ public class CollectionUtilsTests extends TestCase {
assertEquals
(
"value2"
,
list
.
get
(
2
));
}
@Test
public
void
testMergePrimitiveArrayIntoCollection
()
{
int
[]
arr
=
new
int
[]
{
1
,
2
};
List
list
=
new
LinkedList
();
...
...
@@ -74,21 +78,25 @@ public class CollectionUtilsTests extends TestCase {
assertEquals
(
new
Integer
(
2
),
list
.
get
(
2
));
}
@Test
public
void
testMergePropertiesIntoMap
()
{
Properties
defaults
=
new
Properties
();
defaults
.
setProperty
(
"prop1"
,
"value1"
);
Properties
props
=
new
Properties
(
defaults
);
props
.
setProperty
(
"prop2"
,
"value2"
);
props
.
put
(
"prop3"
,
new
Integer
(
3
));
Map
map
=
new
HashMap
();
map
.
put
(
"prop
3"
,
"value3
"
);
map
.
put
(
"prop
4"
,
"value4
"
);
CollectionUtils
.
mergePropertiesIntoMap
(
props
,
map
);
assertEquals
(
"value1"
,
map
.
get
(
"prop1"
));
assertEquals
(
"value2"
,
map
.
get
(
"prop2"
));
assertEquals
(
"value3"
,
map
.
get
(
"prop3"
));
assertEquals
(
new
Integer
(
3
),
map
.
get
(
"prop3"
));
assertEquals
(
"value4"
,
map
.
get
(
"prop4"
));
}
@Test
public
void
testContains
()
{
assertFalse
(
CollectionUtils
.
contains
((
Iterator
)
null
,
"myElement"
));
assertFalse
(
CollectionUtils
.
contains
((
Enumeration
)
null
,
"myElement"
));
...
...
@@ -104,6 +112,7 @@ public class CollectionUtilsTests extends TestCase {
assertTrue
(
CollectionUtils
.
contains
(
ht
.
keys
(),
"myElement"
));
}
@Test
public
void
testContainsAny
()
throws
Exception
{
List
source
=
new
ArrayList
();
source
.
add
(
"abc"
);
...
...
@@ -122,11 +131,13 @@ public class CollectionUtilsTests extends TestCase {
assertFalse
(
CollectionUtils
.
containsAny
(
source
,
candidates
));
}
@Test
public
void
testContainsInstanceWithNullCollection
()
throws
Exception
{
assertFalse
(
"Must return false if supplied Collection argument is null"
,
CollectionUtils
.
containsInstance
(
null
,
this
));
}
@Test
public
void
testContainsInstanceWithInstancesThatAreEqualButDistinct
()
throws
Exception
{
List
list
=
new
ArrayList
();
list
.
add
(
new
Instance
(
"fiona"
));
...
...
@@ -134,6 +145,7 @@ public class CollectionUtilsTests extends TestCase {
CollectionUtils
.
containsInstance
(
list
,
new
Instance
(
"fiona"
)));
}
@Test
public
void
testContainsInstanceWithSameInstance
()
throws
Exception
{
List
list
=
new
ArrayList
();
list
.
add
(
new
Instance
(
"apple"
));
...
...
@@ -143,6 +155,7 @@ public class CollectionUtilsTests extends TestCase {
CollectionUtils
.
containsInstance
(
list
,
instance
));
}
@Test
public
void
testContainsInstanceWithNullInstance
()
throws
Exception
{
List
list
=
new
ArrayList
();
list
.
add
(
new
Instance
(
"apple"
));
...
...
@@ -151,6 +164,7 @@ public class CollectionUtilsTests extends TestCase {
CollectionUtils
.
containsInstance
(
list
,
null
));
}
@Test
public
void
testFindFirstMatch
()
throws
Exception
{
List
source
=
new
ArrayList
();
source
.
add
(
"abc"
);
...
...
@@ -165,6 +179,7 @@ public class CollectionUtilsTests extends TestCase {
assertEquals
(
"def"
,
CollectionUtils
.
findFirstMatch
(
source
,
candidates
));
}
@Test
public
void
testHasUniqueObject
()
{
List
list
=
new
LinkedList
();
list
.
add
(
"myElement"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录