Commit b16fd61a authored by yanzg's avatar yanzg

检测函数增加

parent dd6723ac
......@@ -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;
}
/**
* 检测结果是否异常
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment