diff --git a/commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java b/commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java index ca4939ed79ac4db303171ff9d1b25b0765ccc8c5..2ac7054e3749f2b6439effc6a1dead71434ffc50 100644 --- a/commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java +++ b/commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java @@ -1,8 +1,11 @@ package com.schbrain.common.util; +import com.schbrain.common.exception.BaseException; import com.schbrain.common.exception.ParamInvalidException; -import java.util.*; +import java.util.Collection; +import java.util.Map; +import java.util.function.Supplier; public class ValidateUtils { @@ -12,181 +15,123 @@ public class ValidateUtils { private ValidateUtils() { } - public static void isTrue(boolean expression) { - isTrue(expression, "操作有误"); + public static void isTrue(boolean expression, String message) { + isTrue(expression, () -> new ParamInvalidException(message)); } - public static void isTrue(boolean expression, String message) { + public static void isTrue(boolean expression, Supplier errorSupplier) { if (!expression) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void isFalse(boolean expression) { - isFalse(expression, "操作有误"); + public static void isFalse(boolean expression, String message) { + isFalse(expression, () -> new ParamInvalidException(message)); } - public static void isFalse(boolean expression, String message) { + public static void isFalse(boolean expression, Supplier errorSupplier) { if (expression) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void notNull(Object object) { - notNull(object, "The validated object is null"); + public static void notNull(Object object, String message) { + notNull(object, () -> new ParamInvalidException(message)); } - public static void notNull(Object object, String message) { + public static void notNull(Object object, Supplier errorSupplier) { if (object == null) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void isNull(Object object) { - isNull(object, "The validated object is not null"); + public static void isNull(Object object, String message) { + isNull(object, () -> new ParamInvalidException(message)); } - public static void isNull(Object object, String message) { + public static void isNull(Object object, Supplier errorSupplier) { if (object != null) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void notEmpty(String value) { - notEmpty(value, "The validated string is empty"); + public static void notEmpty(String value, String message) { + notEmpty(value, () -> new ParamInvalidException(message)); } - public static void notEmpty(String value, String message) { - if (null == value || value.isBlank()) { - throw new ParamInvalidException(message); + public static void notEmpty(String value, Supplier errorSupplier) { + if (value == null || value.isBlank()) { + throw errorSupplier.get(); } } - public static void isEmpty(String value) { - isEmpty(value, "The validated string is not empty"); + public static void isEmpty(String value, String message) { + isEmpty(value, () -> new ParamInvalidException(message)); } - public static void isEmpty(String value, String message) { + public static void isEmpty(String value, Supplier errorSupplier) { if (value != null && !value.isEmpty()) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void notEmpty(Object[] array) { - notEmpty(array, "The validated array is empty"); + public static void notEmpty(Object[] array, String message) { + notEmpty(array, () -> new ParamInvalidException(message)); } - public static void notEmpty(Object[] array, String message) { + public static void notEmpty(Object[] array, Supplier errorSupplier) { if (array == null || array.length == 0) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void isEmpty(Object[] array) { - isEmpty(array, "The validated array is not empty"); + public static void isEmpty(Object[] array, String message) { + isEmpty(array, () -> new ParamInvalidException(message)); } - public static void isEmpty(Object[] array, String message) { + public static void isEmpty(Object[] array, Supplier errorSupplier) { if (array != null && array.length != 0) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void notEmpty(Collection collection) { - notEmpty(collection, "The validated collection is empty"); + public static void notEmpty(Collection collection, String message) { + notEmpty(collection, () -> new ParamInvalidException(message)); } - public static void notEmpty(Collection collection, String message) { + public static void notEmpty(Collection collection, Supplier errorSupplier) { if (collection == null || collection.isEmpty()) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void isEmpty(Collection collection) { - isEmpty(collection, "The validated collection is not empty"); + public static void isEmpty(Collection collection, String message) { + isEmpty(collection, () -> new ParamInvalidException(message)); } - public static void isEmpty(Collection collection, String message) { + public static void isEmpty(Collection collection, Supplier errorSupplier) { if (collection != null && !collection.isEmpty()) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void notEmpty(Map map) { - notEmpty(map, "The validated map is empty"); + public static void notEmpty(Map map, String message) { + notEmpty(map, () -> new ParamInvalidException(message)); } - public static void notEmpty(Map map, String message) { + public static void notEmpty(Map map, Supplier errorSupplier) { if (map == null || map.isEmpty()) { - throw new ParamInvalidException(message); + throw errorSupplier.get(); } } - public static void isEmpty(Map map) { - isEmpty(map, "The validated map is not empty"); - } - public static void isEmpty(Map map, String message) { - if (map != null && !map.isEmpty()) { - throw new ParamInvalidException(message); - } - } - - public static void noNullElements(Object[] array) { - notNull(array); - for (int i = 0; i < array.length; i++) { - if (array[i] == null) { - throw new ParamInvalidException("The validated array contains null element at index: " + i); - } - } - } - - public static void noNullElements(Object[] array, String message) { - notNull(array); - for (Object item : array) { - if (item == null) { - throw new ParamInvalidException(message); - } - } + isEmpty(map, () -> new ParamInvalidException(message)); } - public static void noNullElements(Collection collection, String message) { - notNull(collection); - for (Object item : collection) { - if (item == null) { - throw new ParamInvalidException(message); - } - } - } - - public static void noNullElements(Collection collection) { - notNull(collection); - int i = 0; - for (Iterator it = collection.iterator(); it.hasNext(); i++) { - if (it.next() == null) { - throw new ParamInvalidException("The validated collection contains null element at index: " + i); - } - } - } - - public static void allElementsOfType(Collection collection, Class clazz, String message) { - notNull(collection); - notNull(clazz); - for (Object item : collection) { - if (!clazz.isInstance(item)) { - throw new ParamInvalidException(message); - } - } - } - - public static void allElementsOfType(Collection collection, Class clazz) { - notNull(collection); - notNull(clazz); - int i = 0; - for (Iterator it = collection.iterator(); it.hasNext(); i++) { - if (!clazz.isInstance(it.next())) { - throw new ParamInvalidException("The validated collection contains an element not of type " + clazz.getName() + " at index: " + i); - } + public static void isEmpty(Map map, Supplier errorSupplier) { + if (map != null && !map.isEmpty()) { + throw errorSupplier.get(); } } diff --git a/integration/integration-jenkins-plugin/pom.xml b/integration/integration-jenkins-plugin/pom.xml index 07632244378004f59a902fb4ea978748477f60a1..3675fb4cdc315808f2164dc8f4b3520a133190a6 100644 --- a/integration/integration-jenkins-plugin/pom.xml +++ b/integration/integration-jenkins-plugin/pom.xml @@ -35,6 +35,11 @@ velocity-engine-core 2.3 + + org.slf4j + slf4j-api + 1.7.36 + org.apache.commons commons-lang3 @@ -57,20 +62,6 @@ - - - - maven-enforcer-plugin - - - display-info - none - - - - - - repo.jenkins-ci.org