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 08d98dc651f83f60995bee6f4c1b325ca6e6f703..dade63c75d273d628c5ce8412ce26fa3887cd8a2 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