Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
b16fd61a
Commit
b16fd61a
authored
Apr 10, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
检测函数增加
parent
dd6723ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
CheckerHelper.java
.../main/java/com/yanzuoguang/util/helper/CheckerHelper.java
+72
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/CheckerHelper.java
View file @
b16fd61a
...
...
@@ -25,6 +25,9 @@ public final class CheckerHelper {
public
static
final
String
PARAM_NOT_PHONE
=
"param [%s] must be phone no"
;
public
static
final
String
PARAM_NOT_ID_CARD
=
"param [%s] must be id card"
;
public
static
final
String
PARAM_NOT_MIN
=
"param [%s] must be big %d"
;
public
static
final
String
PARAM_NOT_MAX
=
"param [%s] must be max %d"
;
public
static
final
String
PARAM_NOT_RANGE
=
"param [%s] must be range %d and %d"
;
private
boolean
isValid
=
true
;
private
String
checkResult
;
...
...
@@ -278,6 +281,75 @@ public final class CheckerHelper {
return
this
;
}
/**
* 检测最小值是否大于等于0,默认为0
*
* @param paramName 参数名称
* @param paramVal 参数值
* @return
*/
public
CheckerHelper
checkMin
(
String
paramName
,
int
paramVal
)
{
return
checkMin
(
paramName
,
0
,
paramVal
);
}
/**
* 检测最小值是否大于等于0,默认为0
*
* @param paramName 参数名称
* @param paramVal 参数值
* @param min 最小值
* @return
*/
public
CheckerHelper
checkMin
(
String
paramName
,
int
min
,
int
paramVal
)
{
if
(!
isValid
())
{
return
this
;
}
if
(
paramVal
<
min
)
{
this
.
checkResult
=
String
.
format
(
PARAM_NOT_MIN
,
min
,
paramName
);
this
.
setValid
(
false
);
}
return
this
;
}
/**
* 检测最大值
*
* @param paramName 参数名称
* @param paramVal 参数值
* @param max 最大值
* @return
*/
public
CheckerHelper
checkMax
(
String
paramName
,
int
max
,
int
paramVal
)
{
if
(!
isValid
())
{
return
this
;
}
if
(
paramVal
>
max
)
{
this
.
checkResult
=
String
.
format
(
PARAM_NOT_MAX
,
max
,
paramName
);
this
.
setValid
(
false
);
}
return
this
;
}
/**
* 检测最大值
*
* @param paramName 参数名称
* @param paramVal 参数值
* @param min 最小值
* @param max 最大值
* @return
*/
public
CheckerHelper
checkRange
(
String
paramName
,
int
min
,
int
max
,
int
paramVal
)
{
if
(!
isValid
())
{
return
this
;
}
if
(
paramVal
>
max
||
paramVal
<
min
)
{
this
.
checkResult
=
String
.
format
(
PARAM_NOT_RANGE
,
min
,
max
,
paramName
);
this
.
setValid
(
false
);
}
return
this
;
}
/**
* 检测结果是否异常
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment