|
@@ -1,7 +1,5 @@
|
|
|
package cn.com.ty.lift.common.verify;
|
|
|
|
|
|
-import cn.hutool.core.collection.IterUtil;
|
|
|
-import cn.hutool.core.util.ArrayUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import javax.validation.constraints.*;
|
|
@@ -10,7 +8,10 @@ import java.lang.annotation.Annotation;
|
|
|
import java.lang.invoke.MethodHandle;
|
|
|
import java.lang.invoke.MethodHandles;
|
|
|
import java.lang.invoke.MethodType;
|
|
|
-import java.lang.reflect.*;
|
|
|
+import java.lang.reflect.Array;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.net.IDN;
|
|
@@ -29,7 +30,7 @@ import java.util.stream.Collectors;
|
|
|
import static java.util.regex.Pattern.CASE_INSENSITIVE;
|
|
|
|
|
|
/**
|
|
|
- * the validation for parameter implements javax.validation.constraints.*,
|
|
|
+ * the validation for parameter implements {@linkplain javax.validation.constraints},
|
|
|
* reform from hibernate validator (v6.0.16.Final)
|
|
|
*
|
|
|
* @author wcz
|
|
@@ -40,35 +41,35 @@ public class VerifyProcessor {
|
|
|
/**
|
|
|
* the name of the verify method.
|
|
|
*/
|
|
|
- private final String verifyMethod = "verify";
|
|
|
+ private final String verifyMethod = "verify";
|
|
|
/**
|
|
|
* the list of validation annotation & method can be work in {@code javax.validation.constraints.*}
|
|
|
*/
|
|
|
- private final Map<Class<?>, Method> verifyMethodMap = new ConcurrentHashMap<>();
|
|
|
+ private final Map<Class<?>, Method> verifyMethodMap = new ConcurrentHashMap<>();
|
|
|
/**
|
|
|
* whether write log to file. it's {@code true} by default.
|
|
|
*/
|
|
|
- private boolean logWrite = true;
|
|
|
+ private boolean logWrite = true;
|
|
|
/**
|
|
|
* the message to complete verify.
|
|
|
*/
|
|
|
- private final ThreadLocal<String> message = new ThreadLocal<>();
|
|
|
+ private final ThreadLocal<String> message = new ThreadLocal<>();
|
|
|
/**
|
|
|
* the type of message ,1: verify ,2: illegal argument
|
|
|
*/
|
|
|
- private final ThreadLocal<Integer> code = new ThreadLocal<>();
|
|
|
+ private final ThreadLocal<Integer> code = new ThreadLocal<>();
|
|
|
/**
|
|
|
* the max length for a valid email address local part.
|
|
|
*/
|
|
|
- private final int MAX_LOCAL_PART_LENGTH = 64;
|
|
|
+ private final int MAX_LOCAL_PART_LENGTH = 64;
|
|
|
/**
|
|
|
* the regular expression for local part of a valid email address.
|
|
|
*/
|
|
|
- private final String LOCAL_PART_ATOM = "[a-z0-9!#$%&'*+/=?^_`{|}~\u0080-\uFFFF-]";
|
|
|
+ private final String LOCAL_PART_ATOM = "[a-z0-9!#$%&'*+/=?^_`{|}~\u0080-\uFFFF-]";
|
|
|
/**
|
|
|
* the regular expression for the local part of an email address.
|
|
|
*/
|
|
|
- private final String LOCAL_PART_INSIDE_QUOTES_ATOM = "([a-z0-9!#$%&'*.(),<>\\[\\]:; @+/=?^_`{|}~\u0080-\uFFFF-]|\\\\\\\\|\\\\\\\")";
|
|
|
+ private final String LOCAL_PART_INSIDE_QUOTES_ATOM = "([a-z0-9!#$%&'*.(),<>\\[\\]:; @+/=?^_`{|}~\u0080-\uFFFF-]|\\\\\\\\|\\\\\\\")";
|
|
|
/**
|
|
|
* Regular expression for the local part of an email address (everything before '@')
|
|
|
*/
|
|
@@ -107,40 +108,40 @@ public class VerifyProcessor {
|
|
|
private final java.util.regex.Pattern EMAIL_DOMAIN_PATTERN = java.util.regex.Pattern.compile(
|
|
|
DOMAIN + "|\\[" + IP_DOMAIN + "\\]|" + "\\[IPv6:" + IP_V6_DOMAIN + "\\]", CASE_INSENSITIVE
|
|
|
);
|
|
|
-
|
|
|
/**
|
|
|
* the minimum value of compare two number for the infinity check when double or float.
|
|
|
*/
|
|
|
- private final OptionalInt LESS_THAN = OptionalInt.of(-1);
|
|
|
+ private final OptionalInt LESS_THAN = OptionalInt.of(-1);
|
|
|
/**
|
|
|
* the empty OptionalInt(value = 0) of compare two number for the infinity check when double or float.
|
|
|
*/
|
|
|
- private final OptionalInt FINITE_VALUE = OptionalInt.empty();
|
|
|
+ private final OptionalInt FINITE_VALUE = OptionalInt.empty();
|
|
|
/**
|
|
|
* the maximun value of compare two number for the infinity check when double or float.
|
|
|
*/
|
|
|
- private final OptionalInt GREATER_THAN = OptionalInt.of(1);
|
|
|
+ private final OptionalInt GREATER_THAN = OptionalInt.of(1);
|
|
|
/**
|
|
|
* short 0
|
|
|
*/
|
|
|
- private final short SHORT_ZERO = (short) 0;
|
|
|
+ private final short SHORT_ZERO = (short) 0;
|
|
|
/**
|
|
|
* byte 0
|
|
|
*/
|
|
|
- private final byte BYTE_ZERO = (byte) 0;
|
|
|
+ private final byte BYTE_ZERO = (byte) 0;
|
|
|
/**
|
|
|
* to private the constrctor.
|
|
|
*/
|
|
|
private VerifyProcessor() {
|
|
|
- collectVerifyAnnotation();
|
|
|
+ collectVerifyClassMethod();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* collect all vaild validation annotation from the methods.
|
|
|
*/
|
|
|
- private void collectVerifyAnnotation() {
|
|
|
+ private void collectVerifyClassMethod() {
|
|
|
Method[] declaredMethods = this.getClass().getDeclaredMethods();
|
|
|
List<Method> verifyMethods = Arrays.stream(declaredMethods).filter(method -> verifyMethod.equals(method.getName())).collect(Collectors.toList());
|
|
|
- isTrue(verifyMethods.isEmpty(), "There is no method named 'verify' in VerifyProcessor.");
|
|
|
+ isTrue(verifyMethods.isEmpty(), "No any method named 'verify' in VerifyProcessor.");
|
|
|
for (Method method : verifyMethods) {
|
|
|
Optional<Class<?>> classOptional = Arrays.stream(method.getParameterTypes()).filter(type -> Annotation.class.isAssignableFrom(type)).findFirst();
|
|
|
classOptional.ifPresent(verifyClass -> {
|
|
@@ -163,12 +164,27 @@ public class VerifyProcessor {
|
|
|
/**
|
|
|
* get the singleton instance of this
|
|
|
*/
|
|
|
- private static VerifyProcessor getInstance() {
|
|
|
+ private static VerifyProcessor processor() {
|
|
|
return Builder.INSTANCE;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * to do verify by using the singleton instance.
|
|
|
+ *
|
|
|
+ * @param logWrite {@code true} log information, otherwise no log to file.
|
|
|
+ * @param object the target object to verify.
|
|
|
+ * @param fields the list of fields to verify.
|
|
|
+ */
|
|
|
public static void perform(final boolean logWrite, final Object object, final String... fields) {
|
|
|
Builder.INSTANCE.logWrite(logWrite).action(object, fields);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * to do verify by using the singleton instance.
|
|
|
+ *
|
|
|
+ * @param object the target object to verify.
|
|
|
+ * @param fields the list of fields to verify.
|
|
|
+ */
|
|
|
public static void perform(final Object object, final String... fields) {
|
|
|
Builder.INSTANCE.action(object, fields);
|
|
|
}
|
|
@@ -562,7 +578,6 @@ public class VerifyProcessor {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* Checks the validity of the domain name used in an email. To be valid it should be either a valid host name, or an
|
|
|
* IP address wrapped in [].
|
|
@@ -714,11 +729,11 @@ public class VerifyProcessor {
|
|
|
setIllegalArg("The value of @DecimalMax is null, a invalid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
- BigDecimal max = newBigDecimal(maxValue);
|
|
|
+ final BigDecimal max = newBigDecimal(maxValue);
|
|
|
if (isNull(max)) {
|
|
|
return false;
|
|
|
}
|
|
|
- BigDecimal val;
|
|
|
+ final BigDecimal val;
|
|
|
if (isNumber) {
|
|
|
val = newBigDecimal((Number) value);
|
|
|
} else {
|
|
@@ -727,8 +742,8 @@ public class VerifyProcessor {
|
|
|
if (isNull(val)) {
|
|
|
return false;
|
|
|
}
|
|
|
- int compare = decimalComparator(value, val, max, GREATER_THAN);
|
|
|
- boolean inclusive = annotation.inclusive();
|
|
|
+ final int compare = decimalComparator(value, val, max, GREATER_THAN);
|
|
|
+ final boolean inclusive = annotation.inclusive();
|
|
|
//inclusive ? comparisonResult <= 0 : comparisonResult < 0;
|
|
|
if (inclusive) {
|
|
|
return lte0(compare);
|
|
@@ -763,11 +778,11 @@ public class VerifyProcessor {
|
|
|
setIllegalArg("The value of @DecimalMin is null, a invalid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
- BigDecimal min = newBigDecimal(minValue);
|
|
|
+ final BigDecimal min = newBigDecimal(minValue);
|
|
|
if (isNull(min)) {
|
|
|
return false;
|
|
|
}
|
|
|
- BigDecimal val;
|
|
|
+ final BigDecimal val;
|
|
|
if (isNumber) {
|
|
|
val = newBigDecimal((Number) value);
|
|
|
} else {
|
|
@@ -776,8 +791,8 @@ public class VerifyProcessor {
|
|
|
if (isNull(val)) {
|
|
|
return false;
|
|
|
}
|
|
|
- int compare = decimalComparator(value, val, min, LESS_THAN);
|
|
|
- boolean inclusive = annotation.inclusive();
|
|
|
+ final int compare = decimalComparator(value, val, min, LESS_THAN);
|
|
|
+ final boolean inclusive = annotation.inclusive();
|
|
|
//inclusive ? comparisonResult >= 0 : comparisonResult > 0;
|
|
|
if (inclusive) {
|
|
|
return gte0(compare);
|
|
@@ -836,7 +851,7 @@ public class VerifyProcessor {
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
|
- int length = length(value);
|
|
|
+ final int length = length(value);
|
|
|
if(-1 == length){
|
|
|
setIllegalArg("The @NotEmpty only supports CharSequence & Collection & Map & Array & Iterator & Enumeration.");
|
|
|
return false;
|
|
@@ -903,7 +918,7 @@ public class VerifyProcessor {
|
|
|
final int min = annotation.min();
|
|
|
final int max = annotation.max();
|
|
|
String message = annotation.message();
|
|
|
- if(null != message && !message.trim().isEmpty()){
|
|
|
+ if (notBlank(message)) {
|
|
|
if(message.contains("{min}")){
|
|
|
message = message.replace("{min}", String.valueOf(min));
|
|
|
}
|
|
@@ -927,7 +942,7 @@ public class VerifyProcessor {
|
|
|
setIllegalArg("The min (%s) and max (%s) length of @Size cannot be negative.", min, max);
|
|
|
return false;
|
|
|
}
|
|
|
- int length = length(value);
|
|
|
+ final int length = length(value);
|
|
|
if(-1 == length){
|
|
|
setIllegalArg("The @Size only supports CharSequence & Collection & Map & Array & Iterator & Enumeration.");
|
|
|
return false;
|
|
@@ -950,7 +965,7 @@ public class VerifyProcessor {
|
|
|
final int maxInteger = annotation.integer();
|
|
|
final int maxFraction = annotation.fraction();
|
|
|
String message = annotation.message();
|
|
|
- if(null != message && !message.trim().isEmpty()){
|
|
|
+ if (notBlank(message)) {
|
|
|
if(message.contains("{integer}")){
|
|
|
message = message.replace("{integer}", String.valueOf(maxInteger));
|
|
|
}
|
|
@@ -1154,7 +1169,7 @@ public class VerifyProcessor {
|
|
|
return false;
|
|
|
}
|
|
|
final long max = annotation.value();
|
|
|
- int compare;
|
|
|
+ final int compare;
|
|
|
if (isNumber) {
|
|
|
compare = numberComparator((Number) value, max, GREATER_THAN);
|
|
|
} else {
|
|
@@ -1194,7 +1209,7 @@ public class VerifyProcessor {
|
|
|
return false;
|
|
|
}
|
|
|
final long min = annotation.value();
|
|
|
- int compare;
|
|
|
+ final int compare;
|
|
|
if (isNumber) {
|
|
|
compare = numberComparator((Number) value, min, LESS_THAN);
|
|
|
} else {
|
|
@@ -1217,7 +1232,7 @@ public class VerifyProcessor {
|
|
|
*
|
|
|
* @param value any number value
|
|
|
* @param bounds the other value
|
|
|
- * @param treatNanAs return when the value equal the infinity.
|
|
|
+ * @param treatNanAs return when the value is {@code NaN}.
|
|
|
* @return {@code -1} value less than limit, {@code 0} value equal limit, {@code 1} value greater than limit.
|
|
|
*/
|
|
|
private int numberComparator(Number value, long bounds, OptionalInt treatNanAs) {
|
|
@@ -1455,7 +1470,7 @@ public class VerifyProcessor {
|
|
|
setIllegalArg("The @Future only supports TemporalAccessor & Calendar & Date.");
|
|
|
return false;
|
|
|
}
|
|
|
- int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
+ final int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
if (Integer.MAX_VALUE == compare) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1485,7 +1500,7 @@ public class VerifyProcessor {
|
|
|
setIllegalArg("The @FutureOrPresent only supports TemporalAccessor & Calendar & Date.");
|
|
|
return false;
|
|
|
}
|
|
|
- int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
+ final int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
if (Integer.MAX_VALUE == compare) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1515,7 +1530,7 @@ public class VerifyProcessor {
|
|
|
setIllegalArg("The @Past only supports TemporalAccessor & Calendar & Date.");
|
|
|
return false;
|
|
|
}
|
|
|
- int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
+ final int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
if (Integer.MAX_VALUE == compare) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1545,7 +1560,7 @@ public class VerifyProcessor {
|
|
|
setIllegalArg("The @PastOrPresent only supports TemporalAccessor & Calendar & Date.");
|
|
|
return false;
|
|
|
}
|
|
|
- int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
+ final int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
if (Integer.MAX_VALUE == compare) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1562,30 +1577,21 @@ public class VerifyProcessor {
|
|
|
private List<Field> fieldFilter(final Object object, final String... fields) {
|
|
|
Class<?> objectClass = object.getClass();
|
|
|
// get fields, if has specify fields, otherwise get all fields on the object.
|
|
|
- if(ArrayUtil.isEmpty(fields)){
|
|
|
+ if (isEmpty(fields)) {
|
|
|
return Collections.unmodifiableList(Arrays.asList(objectClass.getDeclaredFields()));
|
|
|
}
|
|
|
List<Field> verifyFields = new ArrayList<>();
|
|
|
for (String field : fields) {
|
|
|
- Field verifyField = null;
|
|
|
- //1 get the declared field on this class.
|
|
|
try {
|
|
|
- verifyField = objectClass.getDeclaredField(field);
|
|
|
+ Field verifyField = objectClass.getDeclaredField(field);
|
|
|
+ verifyFields.add(verifyField);
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
+ throw newIllegalArgException("No such field '%s' in : %s.", field, objectClass.getCanonicalName());
|
|
|
}
|
|
|
- // 2 get from the private field on the superclass.
|
|
|
- if (isNull(verifyField)) {
|
|
|
- try {
|
|
|
- verifyField = objectClass.getSuperclass().getDeclaredField(field);
|
|
|
- } catch (NoSuchFieldException e) {
|
|
|
- throw illegalArgException("No such field [%s] in : %s.", field, objectClass.getCanonicalName());
|
|
|
- }
|
|
|
- }
|
|
|
- verifyFields.add(verifyField);
|
|
|
}
|
|
|
//if vaild fields is empty
|
|
|
if (verifyFields.isEmpty()) {
|
|
|
- throw illegalArgException("No field specify to verify.");
|
|
|
+ throw newIllegalArgException("No field specify to verify.");
|
|
|
}
|
|
|
return Collections.unmodifiableList(verifyFields);
|
|
|
}
|
|
@@ -1602,12 +1608,12 @@ public class VerifyProcessor {
|
|
|
}
|
|
|
//get all annotation of the field
|
|
|
Annotation[] annotations = field.getDeclaredAnnotations();
|
|
|
- if(ArrayUtil.isEmpty(annotations)){
|
|
|
+ if (isEmpty(annotations)) {
|
|
|
return null;
|
|
|
}
|
|
|
//filter the validation annotation
|
|
|
List<Annotation> verifyAnnos = Arrays.stream(annotations).filter(anno -> verifyMethodMap.keySet().contains(anno.annotationType())).collect(Collectors.toList());
|
|
|
- if(IterUtil.isEmpty(verifyAnnos)){
|
|
|
+ if (verifyAnnos.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
return Collections.unmodifiableList(verifyAnnos);
|
|
@@ -1621,56 +1627,43 @@ public class VerifyProcessor {
|
|
|
* @return the value
|
|
|
*/
|
|
|
private Object getFieldValue(final Object object, final Field field) {
|
|
|
- Object value;
|
|
|
+ final Object value;
|
|
|
try {
|
|
|
value = field.get(object);
|
|
|
} catch (IllegalAccessException e) {
|
|
|
- throw illegalArgException("Illegal Access [%s] in : %s.", field.getName(), object.getClass().getCanonicalName());
|
|
|
+ throw newIllegalArgException("Illegal Access '%s' in : %s.", field.getName(), object.getClass().getCanonicalName());
|
|
|
}
|
|
|
return value;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * find the method for the verify
|
|
|
- *
|
|
|
- * @param lookup method handle of lookup {@link java.lang.invoke.MethodHandles.Lookup}
|
|
|
- * @param methodName the name of the method
|
|
|
- * @param methodType the return and the args class for the method
|
|
|
- * @return method handle
|
|
|
- */
|
|
|
private MethodHandle methodFilter(final MethodHandles.Lookup lookup, final String methodName, final MethodType methodType) {
|
|
|
- MethodHandle methodHandle;
|
|
|
+ final MethodHandle methodHandle;
|
|
|
try {
|
|
|
methodHandle = lookup.findVirtual(lookup.lookupClass(), methodName, methodType);
|
|
|
} catch (NoSuchMethodException | IllegalAccessException e) {
|
|
|
- throw illegalArgException("No such method [%s(%s)] in VerifyProcessor.", methodName, methodType);
|
|
|
+ throw newIllegalArgException("No such method %s%s in VerifyProcessor.", methodName, methodType);
|
|
|
}
|
|
|
return methodHandle;
|
|
|
}
|
|
|
- /**
|
|
|
- * invoke the method bind with the target object
|
|
|
- *
|
|
|
- * @param methodHandle method handle{@link MethodHandle}
|
|
|
- * @param target the target object
|
|
|
- * @param args the list of args
|
|
|
- * @return result
|
|
|
- */
|
|
|
- private boolean invokeMethod(final MethodHandle methodHandle, final Object target, final Object... args) {
|
|
|
- boolean invoke;
|
|
|
+
|
|
|
+ private boolean invokeMethod(final Object target, final MethodHandle methodHandle, final Object... args) {
|
|
|
+ final boolean invoke;
|
|
|
try {
|
|
|
invoke = (boolean) methodHandle.bindTo(target).invokeWithArguments(args);
|
|
|
} catch (Throwable throwable) {
|
|
|
- throw illegalArgException("Invoke the target method [%s] failed.", methodHandle);
|
|
|
+ throw newIllegalArgException("Invoke the target method [%s] failed.", methodHandle);
|
|
|
}
|
|
|
return invoke;
|
|
|
}
|
|
|
-
|
|
|
- private boolean invokeMethod(final Method method, final Object target, final Object value, final Annotation verifyAnno) {
|
|
|
- boolean invoke = true;
|
|
|
+ /**
|
|
|
+ * invoke the target method to verify.
|
|
|
+ */
|
|
|
+ private boolean invokeMethod(final Object target, final Method method, final Object value, final Annotation annotation) {
|
|
|
+ final boolean invoke;
|
|
|
try {
|
|
|
- invoke = (boolean) method.invoke(target, value, verifyAnno);
|
|
|
+ invoke = (boolean) method.invoke(target, value, annotation);
|
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
|
- throw illegalArgException("Invoke the target method [%s(Object,%s)] failed.", method.getName(), verifyAnno.annotationType().getName());
|
|
|
+ throw newIllegalArgException("Invoke the target method [%s(Object,%s)] failed.", method.getName(), annotation.annotationType().getName());
|
|
|
}
|
|
|
return invoke;
|
|
|
}
|
|
@@ -1688,7 +1681,7 @@ public class VerifyProcessor {
|
|
|
for (Field verifyField : verifyFields) {
|
|
|
//filter the validation annotation
|
|
|
List<Annotation> verifyAnnos = annotationFilter(verifyField);
|
|
|
- if (IterUtil.isEmpty(verifyAnnos)) continue;
|
|
|
+ if (isEmpty(verifyAnnos)) continue;
|
|
|
//get value.
|
|
|
Object value = getFieldValue(object, verifyField);
|
|
|
for (Annotation verifyAnno : verifyAnnos) {
|
|
@@ -1696,15 +1689,15 @@ public class VerifyProcessor {
|
|
|
//get method
|
|
|
Method method = verifyMethodMap.get(annotationType);
|
|
|
// result.
|
|
|
- boolean invoke = invokeMethod(method, this, value, verifyAnno);
|
|
|
+ boolean invoke = invokeMethod(this, method, value, verifyAnno);
|
|
|
if (invoke) continue;
|
|
|
if (logWrite) {
|
|
|
info(verifyField, value, method, verifyAnno);
|
|
|
}
|
|
|
if(1 == code.get()){
|
|
|
- throw verifyException(message.get());
|
|
|
+ throw newVerifyException(message.get());
|
|
|
}else{
|
|
|
- throw illegalArgException(message.get());
|
|
|
+ throw newIllegalArgException(message.get());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1714,16 +1707,9 @@ public class VerifyProcessor {
|
|
|
*
|
|
|
* @param validField the field to valid.
|
|
|
* @param value the value of the field.
|
|
|
- * @param verifyAnno the validation annotation of the field.
|
|
|
* @param method the method to action
|
|
|
- * @param result the result of invoke the method.
|
|
|
+ * @param verifyAnno the validation annotation of the field.
|
|
|
*/
|
|
|
- private void info(Field verifyField, Object value, MethodHandle methodHandle) {
|
|
|
- log.info("###| FIELD : {}", verifyField);
|
|
|
- log.info("###| FIELD_VALUE : {}", value);
|
|
|
- log.info("###| METHOD : (false) {}", methodHandle);
|
|
|
- }
|
|
|
-
|
|
|
private void info(Field verifyField, Object value, Method method, Annotation verifyAnno) {
|
|
|
log.info("###| FIELD : {}", verifyField);
|
|
|
log.info("###| FIELD_VALUE : {}", value);
|
|
@@ -1735,7 +1721,7 @@ public class VerifyProcessor {
|
|
|
* @param message the message of exception.
|
|
|
* @return a {@link IllegalArgumentException}
|
|
|
*/
|
|
|
- private IllegalArgumentException illegalArgException(String message, Object... values) {
|
|
|
+ private IllegalArgumentException newIllegalArgException(String message, Object... values) {
|
|
|
return new IllegalArgumentException(format(message, values));
|
|
|
}
|
|
|
|
|
@@ -1745,7 +1731,7 @@ public class VerifyProcessor {
|
|
|
* @param message the message of exception.
|
|
|
* @return a {@link VerifyException}
|
|
|
*/
|
|
|
- private VerifyException verifyException(String message, Object... values) {
|
|
|
+ private VerifyException newVerifyException(String message, Object... values) {
|
|
|
return new VerifyException(format(message, values));
|
|
|
}
|
|
|
|
|
@@ -1770,12 +1756,28 @@ public class VerifyProcessor {
|
|
|
*/
|
|
|
private void isNull(Object object, String message) {
|
|
|
if (null == object) {
|
|
|
- throw illegalArgException(message);
|
|
|
+ throw newIllegalArgException(message);
|
|
|
}
|
|
|
}
|
|
|
private void isTrue(boolean expression, String message) {
|
|
|
if (expression) {
|
|
|
- throw illegalArgException(message);
|
|
|
+ throw newIllegalArgException(message);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public <T> boolean isEmpty(T[] array) {
|
|
|
+ return array == null || array.length == 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isEmpty(Iterable<?> iterable) {
|
|
|
+ return null == iterable || isEmpty(iterable.iterator());
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isEmpty(Iterator<?> Iterator) {
|
|
|
+ return null == Iterator || !Iterator.hasNext();
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean notBlank(String value) {
|
|
|
+ return null != value && !value.trim().isEmpty();
|
|
|
+ }
|
|
|
}
|