From d39437ab7c6e9b6d9c570a9ccc6fc4f97454ae5e Mon Sep 17 00:00:00 2001 From: liaozan <378024053@qq.com> Date: Thu, 11 May 2023 12:28:32 +0800 Subject: [PATCH] Update ValidateSupport --- .../common/util/support/ValidateSupport.java | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/commons/common-util/src/main/java/com/schbrain/common/util/support/ValidateSupport.java b/commons/common-util/src/main/java/com/schbrain/common/util/support/ValidateSupport.java index 08d98dc..dade63c 100644 --- a/commons/common-util/src/main/java/com/schbrain/common/util/support/ValidateSupport.java +++ b/commons/common-util/src/main/java/com/schbrain/common/util/support/ValidateSupport.java @@ -5,6 +5,7 @@ import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import java.util.*; +import java.util.function.Supplier; /** * @author liaozan @@ -12,20 +13,28 @@ import java.util.*; */ public interface ValidateSupport { - default boolean hasText(String text) { - return StringUtils.isNotBlank(text); + default boolean isEmpty(String text) { + return StringUtils.isEmpty(text); + } + + default boolean isNotEmpty(String text) { + return StringUtils.isNotEmpty(text); } default boolean isBlank(String text) { - return !hasText(text); + return StringUtils.isBlank(text); + } + + default boolean isNotBlank(String text) { + return StringUtils.isNotBlank(text); } default boolean isNull(Object object) { - return object == null; + return Objects.isNull(object); } default boolean isNotNull(Object object) { - return !isNull(object); + return Objects.nonNull(object); } default boolean isEmpty(Collection collection) { @@ -33,7 +42,7 @@ public interface ValidateSupport { } default boolean isNotEmpty(Collection collection) { - return !isEmpty(collection); + return CollectionUtils.isNotEmpty(collection); } default boolean isEmpty(Map map) { @@ -41,7 +50,7 @@ public interface ValidateSupport { } default boolean isNotEmpty(Map map) { - return !isEmpty(map); + return MapUtils.isNotEmpty(map); } default String fixNull(String value) { @@ -49,15 +58,23 @@ public interface ValidateSupport { } default List fixNull(List value) { - return fixNull(value, new ArrayList<>()); + return fixNull(value, ArrayList::new); } default Set fixNull(Set value) { - return fixNull(value, new HashSet<>()); + return fixNull(value, HashSet::new); + } + + default Map fixNull(Map value) { + return fixNull(value, HashMap::new); } default T fixNull(T value, T defaultValue) { return value != null ? value : defaultValue; } + default T fixNull(T value, Supplier defaultValueSupplier) { + return value != null ? value : defaultValueSupplier.get(); + } + } \ No newline at end of file -- GitLab