|
@@ -25,6 +25,22 @@ public interface Judge {
|
|
|
String PARAMETER_VERIFY_FAIL = "参数校验失败";
|
|
|
String PARAMETER_FILED_MISSING = "缺少参数属性值域";
|
|
|
|
|
|
+ static JudgeException judgeException(){
|
|
|
+ return new JudgeException(DATA_MISSING_INCORRECT);
|
|
|
+ }
|
|
|
+
|
|
|
+ static JudgeException judgeException(String message){
|
|
|
+ if(null == message || message.length() == 0){
|
|
|
+ return judgeException();
|
|
|
+ }
|
|
|
+ return new JudgeException(message);
|
|
|
+ }
|
|
|
+ static JudgeException judgeException(String message,Throwable cause){
|
|
|
+ if(null == message || message.length() == 0 || null == cause){
|
|
|
+ return new JudgeException(DATA_MISSING_INCORRECT, new IllegalArgumentException());
|
|
|
+ }
|
|
|
+ return new JudgeException(message, cause);
|
|
|
+ }
|
|
|
/**
|
|
|
* id == null || id <= 0 throw new JudgeException(message)
|
|
|
* @param id id值
|
|
@@ -32,8 +48,8 @@ public interface Judge {
|
|
|
*/
|
|
|
static void id(Long id, String message) {
|
|
|
notNull(id, message);
|
|
|
- if (id.longValue() <= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ if (id <= 0) {
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -45,8 +61,8 @@ public interface Judge {
|
|
|
static void id(Long... ids) {
|
|
|
notNull(ids, IDENTIFIER_INVALID);
|
|
|
for (Long id : ids) {
|
|
|
- if (null == id || id.longValue() <= 0) {
|
|
|
- throw new JudgeException(IDENTIFIER_INVALID);
|
|
|
+ if (null == id || id <= 0) {
|
|
|
+ throw judgeException(IDENTIFIER_INVALID);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -59,19 +75,19 @@ public interface Judge {
|
|
|
*/
|
|
|
static void gt0(Number value, String message) {
|
|
|
if (null == value) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Long && value.longValue() <= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Integer && value.intValue() <= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Float && value.floatValue() <= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Double && value.doubleValue() <= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -95,26 +111,26 @@ public interface Judge {
|
|
|
*/
|
|
|
static void lt0(Number value, String message) {
|
|
|
if (null == value) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Long && value.longValue() >= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Integer && value.intValue() >= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Float && value.floatValue() >= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Double && value.doubleValue() >= 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* value == null || value >= 0 throw new JudgeException(message);
|
|
|
*
|
|
|
- * @param values 不定个的数值
|
|
|
+ * @param values 一个或多个的数值
|
|
|
*/
|
|
|
static void lt0(Number... values) {
|
|
|
notNull(values, MUST_LT0);
|
|
@@ -131,25 +147,25 @@ public interface Judge {
|
|
|
*/
|
|
|
static void eq0(Number value, String message) {
|
|
|
if (null == value) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Long && value.longValue() != 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Integer && value.intValue() != 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Float && value.floatValue() != 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Double && value.doubleValue() != 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* value == null || value != 0 throw new JudgeException(message);
|
|
|
- * @param values 不定个数的数值
|
|
|
+ * @param values 一个或多个数的数值
|
|
|
*/
|
|
|
static void eq0(Number... values) {
|
|
|
notNull(values, MUST_EQ0);
|
|
@@ -166,26 +182,26 @@ public interface Judge {
|
|
|
*/
|
|
|
static void ngt0(Number value, String message) {
|
|
|
if (null == value) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Long && value.longValue() < 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Integer && value.intValue() < 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Float && value.floatValue() < 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Double && value.doubleValue() < 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* value == null || value < 0 throw new JudgeException(message);
|
|
|
*
|
|
|
- * @param values 不定个数的数值型的值
|
|
|
+ * @param values 一个或多个数的数值型的值
|
|
|
*/
|
|
|
static void ngt0(Number... values) {
|
|
|
notNull(values, MUST_NGT0);
|
|
@@ -202,26 +218,26 @@ public interface Judge {
|
|
|
*/
|
|
|
static void nlt0(Number value, String message) {
|
|
|
if (null == value) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Long && value.longValue() > 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Integer && value.intValue() > 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Float && value.floatValue() > 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Double && value.doubleValue() > 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* value == null || value > 0 throw new JudgeException(message);
|
|
|
*
|
|
|
- * @param values 不定个数的数值
|
|
|
+ * @param values 一个或多个数的数值
|
|
|
*/
|
|
|
static void nlt0(Number... values) {
|
|
|
notNull(values, MUST_NLT0);
|
|
@@ -238,26 +254,26 @@ public interface Judge {
|
|
|
*/
|
|
|
static void neq0(Number value, String message) {
|
|
|
if (null == value) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Long && value.longValue() == 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Integer && value.intValue() == 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Float && value.floatValue() == 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
if (value instanceof Double && value.doubleValue() == 0) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* value == null || value != 0 throw new JudgeException(message);
|
|
|
*
|
|
|
- * @param values 不定个数的数值
|
|
|
+ * @param values 一个或多个数的数值
|
|
|
*/
|
|
|
static void neq0(Number... values) {
|
|
|
notNull(values, MUST_NEQ0);
|
|
@@ -274,7 +290,7 @@ public interface Judge {
|
|
|
*/
|
|
|
static void isNull(Object object, String message) {
|
|
|
if (ObjectUtil.isNotEmpty(object)) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -295,7 +311,7 @@ public interface Judge {
|
|
|
*/
|
|
|
static void notNull(Object object, String message) {
|
|
|
if (ObjectUtil.isEmpty(object)) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -316,7 +332,7 @@ public interface Judge {
|
|
|
*/
|
|
|
static void isTrue(boolean expression, String message) {
|
|
|
if (!expression) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -337,7 +353,7 @@ public interface Judge {
|
|
|
*/
|
|
|
static void notTrue(boolean expression, String message) {
|
|
|
if (expression) {
|
|
|
- throw new JudgeException(message);
|
|
|
+ throw judgeException(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -376,11 +392,11 @@ public interface Judge {
|
|
|
}
|
|
|
}
|
|
|
} catch (JudgeException e) {
|
|
|
- throw new JudgeException(e.getMessage());
|
|
|
+ throw judgeException(e.getMessage());
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
- throw new JudgeException(PARAMETER_FILED_MISSING);
|
|
|
+ throw judgeException(PARAMETER_FILED_MISSING);
|
|
|
} catch (Exception e) {
|
|
|
- throw new JudgeException(PARAMETER_VERIFY_FAIL);
|
|
|
+ throw judgeException(PARAMETER_VERIFY_FAIL);
|
|
|
}
|
|
|
}
|
|
|
|