|
@@ -29,17 +29,8 @@ import static java.util.regex.Pattern.CASE_INSENSITIVE;
|
|
|
public class Judgement {
|
|
|
|
|
|
private ThreadLocal<String> message = new ThreadLocal<>();
|
|
|
+ private ThreadLocal<Integer> code = new ThreadLocal<>();
|
|
|
|
|
|
- public String message() {
|
|
|
- return message.get();
|
|
|
- }
|
|
|
-
|
|
|
- public void set(String message) {
|
|
|
- this.message.set(message);
|
|
|
- }
|
|
|
-
|
|
|
- //实例
|
|
|
- public static final Judgement INSTANCE = new Judgement();
|
|
|
private static final int MAX_LOCAL_PART_LENGTH = 64;
|
|
|
private static final String LOCAL_PART_ATOM = "[a-z0-9!#$%&'*+/=?^_`{|}~\u0080-\uFFFF-]";
|
|
|
private static final String LOCAL_PART_INSIDE_QUOTES_ATOM = "([a-z0-9!#$%&'*.(),<>\\[\\]:; @+/=?^_`{|}~\u0080-\uFFFF-]|\\\\\\\\|\\\\\\\")";
|
|
@@ -91,6 +82,28 @@ public class Judgement {
|
|
|
|
|
|
private static final byte BYTE_ZERO = (byte) 0;
|
|
|
|
|
|
+ public String message() {
|
|
|
+ String m = message.get();
|
|
|
+ message.remove();
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer code(){
|
|
|
+ Integer c = code.get();
|
|
|
+ code.remove();
|
|
|
+ return c;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setVerify(String message) {
|
|
|
+ this.code.set(1);
|
|
|
+ this.message.set(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setIllegalArg(String message){
|
|
|
+ this.code.set(2);
|
|
|
+ this.message.set(message);
|
|
|
+ }
|
|
|
+
|
|
|
private Clock getClock() {
|
|
|
return Clock.systemDefaultZone();
|
|
|
}
|
|
@@ -316,7 +329,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
return notNull(value);
|
|
|
}
|
|
|
|
|
@@ -325,7 +338,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
return isNull(value);
|
|
|
}
|
|
|
|
|
@@ -334,7 +347,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
return notNull(value) && isBoolean(value) && ((Boolean) value);
|
|
|
}
|
|
|
|
|
@@ -343,7 +356,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
return notNull(value) && isBoolean(value) && !((Boolean) value);
|
|
|
}
|
|
|
|
|
@@ -352,7 +365,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
@@ -360,18 +373,18 @@ public class Judgement {
|
|
|
final boolean isNumber = isNumber(value);
|
|
|
final boolean isCharSequence = isCharSequence(value);
|
|
|
if (!isNumber && !isCharSequence) {
|
|
|
- set("The DecimalMax only for Number & CharSequence.");
|
|
|
+ setIllegalArg("The DecimalMax only for Number & CharSequence.");
|
|
|
return false;
|
|
|
}
|
|
|
String maxValue = annotation.value();
|
|
|
if (isNull(maxValue)) {
|
|
|
- set("The value of DecimalMax is null, a invalid BigDecimal format.");
|
|
|
+ setIllegalArg("The value of DecimalMax is null, a invalid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
BigDecimal max = newBigDecimal(maxValue);
|
|
|
|
|
|
if (isNull(max)) {
|
|
|
- set(maxValue + " does not represent a valid BigDecimal format.");
|
|
|
+ setIllegalArg(maxValue + " does not represent a valid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
BigDecimal val;
|
|
@@ -381,7 +394,7 @@ public class Judgement {
|
|
|
val = newBigDecimal((CharSequence) value);
|
|
|
}
|
|
|
if (isNull(val)) {
|
|
|
- set(value + " does not represent a valid BigDecimal format.");
|
|
|
+ setIllegalArg(value + " does not represent a valid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
int compare = decimalComparator(value, val, max, GREATER_THAN);
|
|
@@ -399,7 +412,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
@@ -407,17 +420,17 @@ public class Judgement {
|
|
|
final boolean isNumber = isNumber(value);
|
|
|
final boolean isCharSequence = isCharSequence(value);
|
|
|
if (!isNumber && !isCharSequence) {
|
|
|
- set("The DecimalMin only for Number & CharSequence.");
|
|
|
+ setIllegalArg("The DecimalMin only for Number & CharSequence.");
|
|
|
return false;
|
|
|
}
|
|
|
String minValue = annotation.value();
|
|
|
if (isNull(minValue)) {
|
|
|
- set("The value of DecimalMin is null, a invalid BigDecimal format.");
|
|
|
+ setIllegalArg("The value of DecimalMin is null, a invalid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
BigDecimal min = newBigDecimal(minValue);
|
|
|
if (isNull(min)) {
|
|
|
- set(minValue + " does not represent a valid BigDecimal format.");
|
|
|
+ setIllegalArg(minValue + " does not represent a valid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
BigDecimal val;
|
|
@@ -427,7 +440,7 @@ public class Judgement {
|
|
|
val = newBigDecimal((CharSequence) value);
|
|
|
}
|
|
|
if (isNull(val)) {
|
|
|
- set(value + " does not represent a valid BigDecimal format.");
|
|
|
+ setIllegalArg(value + " does not represent a valid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
int compare = decimalComparator(value, val, min, LESS_THAN);
|
|
@@ -471,7 +484,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -523,22 +536,22 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
|
int min = annotation.min();
|
|
|
int max = annotation.max();
|
|
|
if (lt0(min)) {
|
|
|
- set("The min parameter cannot be negative.");
|
|
|
+ setIllegalArg("The min parameter cannot be negative.");
|
|
|
return false;
|
|
|
}
|
|
|
if (lt0(max)) {
|
|
|
- set("The max parameter cannot be negative.");
|
|
|
+ setIllegalArg("The max parameter cannot be negative.");
|
|
|
return false;
|
|
|
}
|
|
|
if (min > max) {
|
|
|
- set("The min and max length cannot be negative.");
|
|
|
+ setIllegalArg("The min and max length cannot be negative.");
|
|
|
return false;
|
|
|
}
|
|
|
int length = length(value);
|
|
@@ -551,24 +564,24 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
|
final boolean isNumber = isNumber(value);
|
|
|
final boolean isCharSequence = isCharSequence(value);
|
|
|
if (!isNumber && !isCharSequence) {
|
|
|
- set("The Digits only for Number & CharSequence.");
|
|
|
+ setIllegalArg("The Digits only for Number & CharSequence.");
|
|
|
return false;
|
|
|
}
|
|
|
int maxInteger = annotation.integer();
|
|
|
int maxFraction = annotation.fraction();
|
|
|
if (lt0(maxInteger)) {
|
|
|
- set("The length of the integer part cannot be negative.");
|
|
|
+ setIllegalArg("The length of the integer part cannot be negative.");
|
|
|
return false;
|
|
|
}
|
|
|
if (lt0(maxFraction)) {
|
|
|
- set("The length of the fraction part cannot be negative.");
|
|
|
+ setIllegalArg("The length of the fraction part cannot be negative.");
|
|
|
return false;
|
|
|
}
|
|
|
BigDecimal val;
|
|
@@ -578,7 +591,7 @@ public class Judgement {
|
|
|
} else {
|
|
|
val = newBigDecimal(value.toString());
|
|
|
if (isNull(val)) {
|
|
|
- set(value + " does not represent a valid BigDecimal format.");
|
|
|
+ setIllegalArg(value + " does not represent a valid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
val = val.stripTrailingZeros();
|
|
@@ -587,7 +600,7 @@ public class Judgement {
|
|
|
val = newBigDecimal((CharSequence) value);
|
|
|
}
|
|
|
if (isNull(val)) {
|
|
|
- set(value + " does not represent a valid BigDecimal format.");
|
|
|
+ setIllegalArg(value + " does not represent a valid BigDecimal format.");
|
|
|
return false;
|
|
|
}
|
|
|
int integerPart = val.precision() - val.scale();
|
|
@@ -601,7 +614,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setIllegalArg(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -616,7 +629,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value) || !isCharSequence(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -656,7 +669,7 @@ public class Judgement {
|
|
|
try {
|
|
|
pattern = java.util.regex.Pattern.compile(regexp, intFlag);
|
|
|
} catch (PatternSyntaxException e) {
|
|
|
- set("The regexp for Email is Invalid regular expression.");
|
|
|
+ setIllegalArg("The regexp for Email is Invalid regular expression.");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -669,7 +682,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value) || !isCharSequence(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -688,7 +701,7 @@ public class Judgement {
|
|
|
try {
|
|
|
pattern = java.util.regex.Pattern.compile(regexp, intFlag);
|
|
|
} catch (PatternSyntaxException e) {
|
|
|
- set("The regexp for Email is Invalid regular expression.");
|
|
|
+ setIllegalArg("The regexp for Email is Invalid regular expression.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -700,14 +713,14 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
|
final boolean isNumber = isNumber(value);
|
|
|
final boolean isCharSequence = isCharSequence(value);
|
|
|
if (!isCharSequence && !isNumber) {
|
|
|
- set("The Max is only valid for CharSequence & Number.");
|
|
|
+ setIllegalArg("The Max is only valid for CharSequence & Number.");
|
|
|
return false;
|
|
|
}
|
|
|
long max = annotation.value();
|
|
@@ -734,14 +747,14 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
|
final boolean isNumber = isNumber(value);
|
|
|
final boolean isCharSequence = isCharSequence(value);
|
|
|
if (!isCharSequence && !isNumber) {
|
|
|
- set("The Min is only valid for CharSequence & Number.");
|
|
|
+ setIllegalArg("The Min is only valid for CharSequence & Number.");
|
|
|
return false;
|
|
|
}
|
|
|
long min = annotation.value();
|
|
@@ -833,7 +846,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -849,7 +862,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -865,7 +878,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -881,7 +894,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -943,7 +956,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -951,12 +964,12 @@ public class Judgement {
|
|
|
final boolean isDate = isDate(value);
|
|
|
final boolean isCalendar = isCalendar(value);
|
|
|
if (!isTemporalAccessor && !isDate && !isCalendar) {
|
|
|
- set("Future is only for TemporalAccessor & Date & Calendar");
|
|
|
+ setIllegalArg("Future is only for TemporalAccessor & Date & Calendar");
|
|
|
return false;
|
|
|
}
|
|
|
int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
if (-2 == compare) {
|
|
|
- set(value.getClass().toString() + " is not a supported date class temporarily.");
|
|
|
+ setIllegalArg(value.getClass().toString() + " is not a supported date class temporarily.");
|
|
|
return false;
|
|
|
}
|
|
|
//compare > 0
|
|
@@ -968,7 +981,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -976,12 +989,12 @@ public class Judgement {
|
|
|
final boolean isDate = isDate(value);
|
|
|
final boolean isCalendar = isCalendar(value);
|
|
|
if (!isTemporalAccessor && !isDate && !isCalendar) {
|
|
|
- set("FutureOrPresent is only for TemporalAccessor & Date & Calendar");
|
|
|
+ setIllegalArg("FutureOrPresent is only for TemporalAccessor & Date & Calendar");
|
|
|
return false;
|
|
|
}
|
|
|
int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
if (-2 == compare) {
|
|
|
- set(value.getClass().toString() + " is not a supported date class temporarily.");
|
|
|
+ setIllegalArg(value.getClass().toString() + " is not a supported date class temporarily.");
|
|
|
return false;
|
|
|
}
|
|
|
//compare >= 0
|
|
@@ -993,7 +1006,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1001,12 +1014,12 @@ public class Judgement {
|
|
|
final boolean isDate = isDate(value);
|
|
|
final boolean isCalendar = isCalendar(value);
|
|
|
if (!isTemporalAccessor && !isDate && !isCalendar) {
|
|
|
- set("Past is only for TemporalAccessor & Date & Calendar");
|
|
|
+ setIllegalArg("Past is only for TemporalAccessor & Date & Calendar");
|
|
|
return false;
|
|
|
}
|
|
|
int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
if (-2 == compare) {
|
|
|
- set(value.getClass().toString() + " is not a supported date class temporarily.");
|
|
|
+ setIllegalArg(value.getClass().toString() + " is not a supported date class temporarily.");
|
|
|
return false;
|
|
|
}
|
|
|
//compare < 0
|
|
@@ -1018,7 +1031,7 @@ public class Judgement {
|
|
|
if (isNull(annotation)) {
|
|
|
return true;
|
|
|
}
|
|
|
- set(annotation.message());
|
|
|
+ setVerify(annotation.message());
|
|
|
if (isNull(value)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1026,12 +1039,12 @@ public class Judgement {
|
|
|
final boolean isDate = isDate(value);
|
|
|
final boolean isCalendar = isCalendar(value);
|
|
|
if (!isTemporalAccessor && !isDate && !isCalendar) {
|
|
|
- set("PastOrPresent is only for TemporalAccessor & Date & Calendar");
|
|
|
+ setIllegalArg("PastOrPresent is only for TemporalAccessor & Date & Calendar");
|
|
|
return false;
|
|
|
}
|
|
|
int compare = dateComparator(value, isTemporalAccessor, isDate);
|
|
|
if (-2 == compare) {
|
|
|
- set(value.getClass().toString() + " is not a supported date class temporarily.");
|
|
|
+ setIllegalArg(value.getClass().toString() + " is not a supported date class temporarily.");
|
|
|
return false;
|
|
|
}
|
|
|
//compare <= 0
|