|
@@ -1,10 +1,13 @@
|
|
|
package com.zd.common.core.utils;
|
|
package com.zd.common.core.utils;
|
|
|
|
|
|
|
|
import com.zd.common.core.exception.ParamException;
|
|
import com.zd.common.core.exception.ParamException;
|
|
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -18,21 +21,21 @@ import java.util.regex.Pattern;
|
|
|
public class ParamCheckUtils {
|
|
public class ParamCheckUtils {
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ParamCheckUtils.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ParamCheckUtils.class);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private static class LoadParamCheck{
|
|
private static class LoadParamCheck{
|
|
|
private static final ParamCheckUtils PARAM_CHECK_UTILS = new ParamCheckUtils();
|
|
private static final ParamCheckUtils PARAM_CHECK_UTILS = new ParamCheckUtils();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private ParamCheckUtils() {}
|
|
private ParamCheckUtils() {}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public static ParamCheck build() {
|
|
public static ParamCheck build() {
|
|
|
return LoadParamCheck.PARAM_CHECK_UTILS.new ParamCheck();
|
|
return LoadParamCheck.PARAM_CHECK_UTILS.new ParamCheck();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public static ParamCheck build(String msg) {
|
|
public static ParamCheck build(String msg) {
|
|
|
return LoadParamCheck.PARAM_CHECK_UTILS.new ParamCheck(msg);
|
|
return LoadParamCheck.PARAM_CHECK_UTILS.new ParamCheck(msg);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private static void throwParamException(String message) {
|
|
private static void throwParamException(String message) {
|
|
|
throw new ParamException(message);
|
|
throw new ParamException(message);
|
|
|
}
|
|
}
|
|
@@ -47,17 +50,17 @@ public class ParamCheckUtils {
|
|
|
if(null == obj)
|
|
if(null == obj)
|
|
|
throwParamException(message);
|
|
throwParamException(message);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public class ParamCheck{
|
|
public class ParamCheck{
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private String msg;
|
|
private String msg;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public ParamCheck() {}
|
|
public ParamCheck() {}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public ParamCheck(String msg) {
|
|
public ParamCheck(String msg) {
|
|
|
this.msg = msg;
|
|
this.msg = msg;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public void throwException(String message) {
|
|
public void throwException(String message) {
|
|
|
throwParamException(message);
|
|
throwParamException(message);
|
|
|
}
|
|
}
|
|
@@ -84,7 +87,20 @@ public class ParamCheckUtils {
|
|
|
public ParamCheck notNull(Object obj) {
|
|
public ParamCheck notNull(Object obj) {
|
|
|
return notNull(obj,msg);
|
|
return notNull(obj,msg);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 检查objList不为null
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param objList
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public ParamCheck notNull(List <? extends Object> objList) {
|
|
|
|
|
+ Predicate<List <?>> predicate = a->a.size()>0;
|
|
|
|
|
+ if(!predicate.test(objList)){
|
|
|
|
|
+ throwParamException(msg);
|
|
|
|
|
+ }
|
|
|
|
|
+ return this;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 检查字符串不为空,指定提示msg
|
|
* 检查字符串不为空,指定提示msg
|
|
@@ -335,7 +351,7 @@ public class ParamCheckUtils {
|
|
|
public ParamCheck isNotNumber(String number) {
|
|
public ParamCheck isNotNumber(String number) {
|
|
|
return isNotNumber(number, this.msg);
|
|
return isNotNumber(number, this.msg);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 检查参数是否为数字,指定提示msg
|
|
* 检查参数是否为数字,指定提示msg
|