Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
后端镜像
java镜像
Springside4
提交
11ba795f
S
Springside4
项目概览
后端镜像
/
java镜像
/
Springside4
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Springside4
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
11ba795f
编写于
5月 19, 2012
作者:
C
Calvin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#21 整理基础类的使用并更新文档, 防御式编程校验参数的Validate类
上级
3e76c076
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
8 deletion
+26
-8
examples/showcase/src/main/java/org/springside/examples/showcase/utilities/validate/ValidateDemo.java
...de/examples/showcase/utilities/validate/ValidateDemo.java
+23
-7
examples/showcase/src/main/resources/email/applicationContext-email.xml
...ase/src/main/resources/email/applicationContext-email.xml
+1
-1
modules/core/src/main/java/org/springside/modules/utils/Collections3.java
.../main/java/org/springside/modules/utils/Collections3.java
+2
-0
未找到文件。
examples/showcase/src/main/java/org/springside/examples/showcase/utilities/validate/ValidateDemo.java
浏览文件 @
11ba795f
...
...
@@ -2,10 +2,14 @@ package org.springside.examples.showcase.utilities.validate;
import
static
org
.
junit
.
Assert
.*;
import
java.util.List
;
import
org.apache.commons.lang3.Validate
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
com.google.common.collect.Lists
;
/**
* 演示用Apache Commons3的Validate,在代码中进行防御性校验.
*
...
...
@@ -17,7 +21,7 @@ public class ValidateDemo {
@Test
public
void
asserts
()
{
//not null
//not null
Object
try
{
String
parameter
=
"abc"
;
...
...
@@ -25,31 +29,43 @@ public class ValidateDemo {
String
result
=
Validate
.
notNull
(
parameter
);
assertEquals
(
"abc"
,
result
);
//检验not null,用默认出错信息.
Validate
.
notNull
(
null
);
Assert
.
fail
();
}
catch
(
NullPointerException
e
)
{
assertEquals
(
"The validated object is null"
,
e
.
getMessage
());
}
//notBlank
blank
//notBlank
String
try
{
String
parameter
=
"abc"
;
String
result
=
Validate
.
notBlank
(
parameter
);
assertEquals
(
"abc"
,
result
);
Validate
.
notBlank
(
""
);
//检验not null,用自定义出错信息.
Validate
.
notBlank
(
""
,
"The name must not be blank"
);
Assert
.
fail
();
}
catch
(
IllegalArgumentException
e
)
{
assertEquals
(
"The name must not be blank"
,
e
.
getMessage
());
}
//notEmpty Collection
try
{
List
parameter
=
Lists
.
newArrayList
();
List
result
=
Validate
.
notEmpty
(
parameter
);
Assert
.
fail
();
}
catch
(
IllegalArgumentException
e
)
{
assertEquals
(
"The validated collection is empty"
,
e
.
getMessage
());
}
//is true
try
{
Validate
.
isTrue
(
false
);
//出錯信息可格式化參數
Validate
.
isTrue
(
1
==
3
,
"Message %s"
,
"foo"
);
Assert
.
fail
();
}
catch
(
IllegalArgumentException
e
)
{
assertEquals
(
"Message foo"
,
e
.
getMessage
());
}
}
}
examples/showcase/src/main/resources/email/applicationContext-email.xml
浏览文件 @
11ba795f
...
...
@@ -10,7 +10,7 @@
<property
name=
"mailSender"
ref=
"mailSender"
/>
<property
name=
"textTemplate"
>
<value>
<![CDATA[
用戶%
1$s在%2$
tF被修改.
用戶%
s在%
tF被修改.
System Administrator.
]]>
</value>
</property>
...
...
modules/core/src/main/java/org/springside/modules/utils/Collections3.java
浏览文件 @
11ba795f
...
...
@@ -122,11 +122,13 @@ public class Collections3 {
return
null
;
}
//当类型为List时,直接取得最后一个元素 。
if
(
collection
instanceof
List
)
{
List
<
T
>
list
=
(
List
<
T
>)
collection
;
return
list
.
get
(
list
.
size
()
-
1
);
}
//其他类型通过iterator滚动到最后一个元素.
Iterator
<
T
>
iterator
=
collection
.
iterator
();
while
(
true
)
{
T
current
=
iterator
.
next
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录