diff --git a/hutool-core/src/main/java/cn/hutool/core/text/CharSequenceUtil.java b/hutool-core/src/main/java/cn/hutool/core/text/CharSequenceUtil.java index 01f1be4b3..0e534da4d 100755 --- a/hutool-core/src/main/java/cn/hutool/core/text/CharSequenceUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/text/CharSequenceUtil.java @@ -19,7 +19,6 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.text.MessageFormat; import java.text.Normalizer; -import java.util.Collection; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -171,8 +170,8 @@ public class CharSequenceUtil { * @see CharSequenceUtil#hasBlank(CharSequence...) * @since 6.0.0 */ - public static boolean hasBlank(final Collection strs) { - if (ArrayUtil.isEmpty(strs)) { + public static boolean hasBlank(final Iterable strs) { + if (CollUtil.isEmpty(strs)) { return true; } for (final CharSequence str : strs) { @@ -224,7 +223,7 @@ public class CharSequenceUtil { * @see CharSequenceUtil#isAllBlank(CharSequence...) * @since 6.0.1 */ - public static boolean isAllBlank(final Collection strs) { + public static boolean isAllBlank(final Iterable strs) { if (CollUtil.isNotEmpty(strs)) { for (final CharSequence str : strs) { if (isNotBlank(str)) { @@ -415,6 +414,27 @@ public class CharSequenceUtil { return false; } + /** + *

是否包含空字符串。

+ *

如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。

+ * + * @param strs 字符串列表 + * @return 是否包含空字符串 + * @since 6.0.0 + */ + public static boolean hasEmpty(final Iterable strs) { + if (CollUtil.isEmpty(strs)) { + return true; + } + + for (final CharSequence str : strs) { + if (isEmpty(str)) { + return true; + } + } + return false; + } + /** *

指定字符串数组中的元素,是否全部为空字符串。

*

如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。

@@ -439,15 +459,33 @@ public class CharSequenceUtil { * @return 所有字符串是否为空白 */ public static boolean isAllEmpty(final CharSequence... strs) { - if (ArrayUtil.isEmpty(strs)) { - return true; - } - - for (final CharSequence str : strs) { - if (isNotEmpty(str)) { - return false; + if (ArrayUtil.isNotEmpty(strs)) { + for (final CharSequence str : strs) { + if (isNotEmpty(str)) { + return false; + } } } + + return true; + } + + /** + *

指定字符串数组中的元素,是否全部为空字符串。

+ *

如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。

+ * + * @param strs 字符串列表 + * @return 所有字符串是否为空白 + */ + public static boolean isAllEmpty(final Iterable strs) { + if (CollUtil.isNotEmpty(strs)) { + for (final CharSequence str : strs) { + if (isNotEmpty(str)) { + return false; + } + } + } + return true; } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/StrUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/text/StrUtilTest.java index 2e9a3282a..47aea4ad5 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/StrUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/StrUtilTest.java @@ -46,7 +46,7 @@ public class StrUtilTest { } @Test - public void testIssAllBlank() { + public void testIsAllBlank() { final List queue = new LinkedList<>(); queue.add("apple"); queue.add("banana");