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 0e534da4d..122362c22 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
@@ -32,264 +32,15 @@ import java.util.function.Predicate;
* @author looly
* @since 5.5.3
*/
-public class CharSequenceUtil {
+public class CharSequenceUtil extends StrChecker{
public static final int INDEX_NOT_FOUND = Finder.INDEX_NOT_FOUND;
- /**
- * 字符串常量:{@code "null"}
- * 注意:{@code "null" != null}
- */
- public static final String NULL = "null";
-
- /**
- * 字符串常量:空字符串 {@code ""}
- */
- public static final String EMPTY = "";
-
/**
* 字符串常量:空格符 {@code " "}
*/
public static final String SPACE = " ";
- /**
- *
字符串是否为空白,空白的定义如下:
- *
- * - {@code null}
- * - 空字符串:{@code ""}
- * - 空格、全角空格、制表符、换行符,等不可见字符
- *
- *
- * 例:
- *
- * - {@code StrUtil.isBlank(null) // true}
- * - {@code StrUtil.isBlank("") // true}
- * - {@code StrUtil.isBlank(" \t\n") // true}
- * - {@code StrUtil.isBlank("abc") // false}
- *
- *
- * 注意:该方法与 {@link #isEmpty(CharSequence)} 的区别是:
- * 该方法会校验空白字符,且性能相对于 {@link #isEmpty(CharSequence)} 略慢。
- *
- *
- * 建议:
- *
- * - 该方法建议仅对于客户端(或第三方接口)传入的参数使用该方法。
- * - 需要同时校验多个字符串时,建议采用 {@link #hasBlank(CharSequence...)} 或 {@link #isAllBlank(CharSequence...)}
- *
- *
- * @param str 被检测的字符串
- * @return 若为空白,则返回 true
- * @see #isEmpty(CharSequence)
- */
- public static boolean isBlank(final CharSequence str) {
- final int length;
-
- if ((str == null) || ((length = str.length()) == 0)) {
- return true;
- }
-
- for (int i = 0; i < length; i++) {
- // 只要有一个非空字符即为非空字符串
- if (false == CharUtil.isBlankChar(str.charAt(i))) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * 字符串是否为非空白,非空白的定义如下:
- *
- * - 不为 {@code null}
- * - 不为空字符串:{@code ""}
- * - 不为空格、全角空格、制表符、换行符,等不可见字符
- *
- *
- * 例:
- *
- * - {@code StrUtil.isNotBlank(null) // false}
- * - {@code StrUtil.isNotBlank("") // false}
- * - {@code StrUtil.isNotBlank(" \t\n") // false}
- * - {@code StrUtil.isNotBlank("abc") // true}
- *
- *
- * 注意:该方法与 {@link #isNotEmpty(CharSequence)} 的区别是:
- * 该方法会校验空白字符,且性能相对于 {@link #isNotEmpty(CharSequence)} 略慢。
- * 建议:仅对于客户端(或第三方接口)传入的参数使用该方法。
- *
- * @param str 被检测的字符串
- * @return 是否为非空
- * @see #isBlank(CharSequence)
- */
- public static boolean isNotBlank(final CharSequence str) {
- return false == isBlank(str);
- }
-
- /**
- * 指定字符串数组中,是否包含空字符串。
- * 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
- *
- *
- * 例:
- *
- * - {@code StrUtil.hasBlank() // true}
- * - {@code StrUtil.hasBlank("", null, " ") // true}
- * - {@code StrUtil.hasBlank("123", " ") // true}
- * - {@code StrUtil.hasBlank("123", "abc") // false}
- *
- *
- * 注意:该方法与 {@link #isAllBlank(CharSequence...)} 的区别在于:
- *
- * - hasBlank(CharSequence...) 等价于 {@code isBlank(...) || isBlank(...) || ...}
- * - {@link #isAllBlank(CharSequence...)} 等价于 {@code isBlank(...) && isBlank(...) && ...}
- *
- *
- * @param strs 字符串列表
- * @return 是否包含空字符串
- */
- public static boolean hasBlank(final CharSequence... strs) {
- if (ArrayUtil.isEmpty(strs)) {
- return true;
- }
-
- for (final CharSequence str : strs) {
- if (isBlank(str)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 指定字符串集合中,是否包含空字符串。
- *
- * @param strs 字符串列表
- * @return 批量判断字符串是否全部为空白
- * @see CharSequenceUtil#hasBlank(CharSequence...)
- * @since 6.0.0
- */
- public static boolean hasBlank(final Iterable extends CharSequence> strs) {
- if (CollUtil.isEmpty(strs)) {
- return true;
- }
- for (final CharSequence str : strs) {
- if (isBlank(str)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 指定字符串数组中的元素,是否全部为空字符串。
- * 如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
- *
- *
- * 例:
- *
- * - {@code StrUtil.isAllBlank() // true}
- * - {@code StrUtil.isAllBlank("", null, " ") // true}
- * - {@code StrUtil.isAllBlank("123", " ") // false}
- * - {@code StrUtil.isAllBlank("123", "abc") // false}
- *
- *
- * 注意:该方法与 {@link #hasBlank(CharSequence...)} 的区别在于:
- *
- * - {@link #hasBlank(CharSequence...)} 等价于 {@code isBlank(...) || isBlank(...) || ...}
- * - isAllBlank(CharSequence...) 等价于 {@code isBlank(...) && isBlank(...) && ...}
- *
- *
- * @param strs 字符串列表
- * @return 所有字符串是否为空白
- */
- public static boolean isAllBlank(final CharSequence... strs) {
- if (ArrayUtil.isEmpty(strs)) {
- return true;
- }
-
- for (final CharSequence str : strs) {
- if (isNotBlank(str)) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * @param strs 字符串列表
- * @return 批量判断字符串是否全部为空白
- * @see CharSequenceUtil#isAllBlank(CharSequence...)
- * @since 6.0.1
- */
- public static boolean isAllBlank(final Iterable extends CharSequence> strs) {
- if (CollUtil.isNotEmpty(strs)) {
- for (final CharSequence str : strs) {
- if (isNotBlank(str)) {
- return false;
- }
- }
- }
- return true;
- }
-
- /**
- * 字符串是否为空,空的定义如下:
- *
- * - {@code null}
- * - 空字符串:{@code ""}
- *
- *
- * 例:
- *
- * - {@code StrUtil.isEmpty(null) // true}
- * - {@code StrUtil.isEmpty("") // true}
- * - {@code StrUtil.isEmpty(" \t\n") // false}
- * - {@code StrUtil.isEmpty("abc") // false}
- *
- *
- * 注意:该方法与 {@link #isBlank(CharSequence)} 的区别是:该方法不校验空白字符。
- * 建议:
- *
- * - 该方法建议用于工具类或任何可以预期的方法参数的校验中。
- * - 需要同时校验多个字符串时,建议采用 {@link #hasEmpty(CharSequence...)} 或 {@link #isAllEmpty(CharSequence...)}
- *
- *
- * @param str 被检测的字符串
- * @return 是否为空
- * @see #isBlank(CharSequence)
- */
- public static boolean isEmpty(final CharSequence str) {
- return str == null || str.length() == 0;
- }
-
- /**
- * 字符串是否为非空白,非空白的定义如下:
- *
- * - 不为 {@code null}
- * - 不为空字符串:{@code ""}
- *
- *
- * 例:
- *
- * - {@code StrUtil.isNotEmpty(null) // false}
- * - {@code StrUtil.isNotEmpty("") // false}
- * - {@code StrUtil.isNotEmpty(" \t\n") // true}
- * - {@code StrUtil.isNotEmpty("abc") // true}
- *
- *
- * 注意:该方法与 {@link #isNotBlank(CharSequence)} 的区别是:该方法不校验空白字符。
- * 建议:该方法建议用于工具类或任何可以预期的方法参数的校验中。
- *
- * @param str 被检测的字符串
- * @return 是否为非空
- * @see #isEmpty(CharSequence)
- */
- public static boolean isNotEmpty(final CharSequence str) {
- return false == isEmpty(str);
- }
-
/**
* 当给定字符串为null时,转换为Empty
*
@@ -378,209 +129,6 @@ public class CharSequenceUtil {
return isEmpty(str) ? null : str.toString();
}
- /**
- * 是否包含空字符串。
- * 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
- *
- *
- * 例:
- *
- * - {@code StrUtil.hasEmpty() // true}
- * - {@code StrUtil.hasEmpty("", null) // true}
- * - {@code StrUtil.hasEmpty("123", "") // true}
- * - {@code StrUtil.hasEmpty("123", "abc") // false}
- * - {@code StrUtil.hasEmpty(" ", "\t", "\n") // false}
- *
- *
- * 注意:该方法与 {@link #isAllEmpty(CharSequence...)} 的区别在于:
- *
- * - hasEmpty(CharSequence...) 等价于 {@code isEmpty(...) || isEmpty(...) || ...}
- * - {@link #isAllEmpty(CharSequence...)} 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
- *
- *
- * @param strs 字符串列表
- * @return 是否包含空字符串
- */
- public static boolean hasEmpty(final CharSequence... strs) {
- if (ArrayUtil.isEmpty(strs)) {
- return true;
- }
-
- for (final CharSequence str : strs) {
- if (isEmpty(str)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 是否包含空字符串。
- * 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
- *
- * @param strs 字符串列表
- * @return 是否包含空字符串
- * @since 6.0.0
- */
- public static boolean hasEmpty(final Iterable extends CharSequence> strs) {
- if (CollUtil.isEmpty(strs)) {
- return true;
- }
-
- for (final CharSequence str : strs) {
- if (isEmpty(str)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 指定字符串数组中的元素,是否全部为空字符串。
- * 如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
- *
- *
- * 例:
- *
- * - {@code StrUtil.isAllEmpty() // true}
- * - {@code StrUtil.isAllEmpty("", null) // true}
- * - {@code StrUtil.isAllEmpty("123", "") // false}
- * - {@code StrUtil.isAllEmpty("123", "abc") // false}
- * - {@code StrUtil.isAllEmpty(" ", "\t", "\n") // false}
- *
- *
- * 注意:该方法与 {@link #hasEmpty(CharSequence...)} 的区别在于:
- *
- * - {@link #hasEmpty(CharSequence...)} 等价于 {@code isEmpty(...) || isEmpty(...) || ...}
- * - isAllEmpty(CharSequence...) 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
- *
- *
- * @param strs 字符串列表
- * @return 所有字符串是否为空白
- */
- public static boolean isAllEmpty(final CharSequence... strs) {
- 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 extends CharSequence> strs) {
- if (CollUtil.isNotEmpty(strs)) {
- for (final CharSequence str : strs) {
- if (isNotEmpty(str)) {
- return false;
- }
- }
- }
-
- return true;
- }
-
- /**
- * 指定字符串数组中的元素,是否都不为空字符串。
- * 如果指定的字符串数组的长度不为 0,或者所有元素都不是空字符串,则返回 true。
- *
- *
- * 例:
- *
- * - {@code StrUtil.isAllNotEmpty() // false}
- * - {@code StrUtil.isAllNotEmpty("", null) // false}
- * - {@code StrUtil.isAllNotEmpty("123", "") // false}
- * - {@code StrUtil.isAllNotEmpty("123", "abc") // true}
- * - {@code StrUtil.isAllNotEmpty(" ", "\t", "\n") // true}
- *
- *
- * 注意:该方法与 {@link #isAllEmpty(CharSequence...)} 的区别在于:
- *
- * - {@link #isAllEmpty(CharSequence...)} 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
- * - isAllNotEmpty(CharSequence...) 等价于 {@code !isEmpty(...) && !isEmpty(...) && ...}
- *
- *
- * @param args 字符串数组
- * @return 所有字符串是否都不为为空白
- * @since 5.3.6
- */
- public static boolean isAllNotEmpty(final CharSequence... args) {
- return false == hasEmpty(args);
- }
-
- /**
- * 是否存都不为{@code null}或空对象或空白符的对象,通过{@link #hasBlank(CharSequence...)} 判断元素
- *
- * @param args 被检查的对象,一个或者多个
- * @return 是否都不为空
- * @since 5.3.6
- */
- public static boolean isAllNotBlank(final CharSequence... args) {
- return false == hasBlank(args);
- }
-
- /**
- * 检查字符串是否为null、“null”、“undefined”
- *
- * @param str 被检查的字符串
- * @return 是否为null、“null”、“undefined”
- * @since 4.0.10
- */
- public static boolean isNullOrUndefined(final CharSequence str) {
- if (null == str) {
- return true;
- }
- return isNullOrUndefinedStr(str);
- }
-
- /**
- * 检查字符串是否为null、“”、“null”、“undefined”
- *
- * @param str 被检查的字符串
- * @return 是否为null、“”、“null”、“undefined”
- * @since 4.0.10
- */
- public static boolean isEmptyOrUndefined(final CharSequence str) {
- if (isEmpty(str)) {
- return true;
- }
- return isNullOrUndefinedStr(str);
- }
-
- /**
- * 检查字符串是否为null、空白串、“null”、“undefined”
- *
- * @param str 被检查的字符串
- * @return 是否为null、空白串、“null”、“undefined”
- * @since 4.0.10
- */
- public static boolean isBlankOrUndefined(final CharSequence str) {
- if (isBlank(str)) {
- return true;
- }
- return isNullOrUndefinedStr(str);
- }
-
- /**
- * 是否为“null”、“undefined”,不做空指针检查
- *
- * @param str 字符串
- * @return 是否为“null”、“undefined”
- */
- private static boolean isNullOrUndefinedStr(final CharSequence str) {
- final String strString = str.toString().trim();
- return NULL.equals(strString) || "undefined".equals(strString);
- }
-
// ------------------------------------------------------------------------ Trim
/**
@@ -4427,26 +3975,6 @@ public class CharSequenceUtil {
return CollUtil.join(iterable, conjunction);
}
- /**
- * 字符串的每一个字符是否都与定义的匹配器匹配
- *
- * @param value 字符串
- * @param matcher 匹配器
- * @return 是否全部匹配
- * @since 3.2.3
- */
- public static boolean isAllCharMatch(final CharSequence value, final Predicate matcher) {
- if (StrUtil.isBlank(value)) {
- return false;
- }
- for (int i = value.length(); --i >= 0; ) {
- if (false == matcher.test(value.charAt(i))) {
- return false;
- }
- }
- return true;
- }
-
/**
* 检查字符串是否都为数字组成
*
diff --git a/hutool-core/src/main/java/cn/hutool/core/text/StrChecker.java b/hutool-core/src/main/java/cn/hutool/core/text/StrChecker.java
new file mode 100644
index 000000000..a00d3da28
--- /dev/null
+++ b/hutool-core/src/main/java/cn/hutool/core/text/StrChecker.java
@@ -0,0 +1,489 @@
+package cn.hutool.core.text;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.CharUtil;
+
+import java.util.function.Predicate;
+
+/**
+ * 字符串检查工具类,提供字符串的blank和empty等检查
+ *
+ * - empty定义:{@code null} or 空字符串:{@code ""}
+ * - blank定义:{@code null} or 空字符串:{@code ""} or 空格、全角空格、制表符、换行符,等不可见字符
+ *
+ */
+public class StrChecker {
+
+ /**
+ * 字符串常量:{@code "null"}
+ * 注意:{@code "null" != null}
+ */
+ public static final String NULL = "null";
+
+ /**
+ * 字符串常量:空字符串 {@code ""}
+ */
+ public static final String EMPTY = "";
+
+ /**
+ * 字符串是否为空白,空白的定义如下:
+ *
+ * - {@code null}
+ * - 空字符串:{@code ""}
+ * - 空格、全角空格、制表符、换行符,等不可见字符
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isBlank(null) // true}
+ * - {@code StrUtil.isBlank("") // true}
+ * - {@code StrUtil.isBlank(" \t\n") // true}
+ * - {@code StrUtil.isBlank("abc") // false}
+ *
+ *
+ * 注意:该方法与 {@link #isEmpty(CharSequence)} 的区别是:
+ * 该方法会校验空白字符,且性能相对于 {@link #isEmpty(CharSequence)} 略慢。
+ *
+ *
+ * 建议:
+ *
+ * - 该方法建议仅对于客户端(或第三方接口)传入的参数使用该方法。
+ * - 需要同时校验多个字符串时,建议采用 {@link #hasBlank(CharSequence...)} 或 {@link #isAllBlank(CharSequence...)}
+ *
+ *
+ * @param str 被检测的字符串
+ * @return 若为空白,则返回 true
+ * @see #isEmpty(CharSequence)
+ */
+ public static boolean isBlank(final CharSequence str) {
+ final int length;
+
+ if ((str == null) || ((length = str.length()) == 0)) {
+ return true;
+ }
+
+ for (int i = 0; i < length; i++) {
+ // 只要有一个非空字符即为非空字符串
+ if (false == CharUtil.isBlankChar(str.charAt(i))) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * 字符串是否为非空白,非空白的定义如下:
+ *
+ * - 不为 {@code null}
+ * - 不为空字符串:{@code ""}
+ * - 不为空格、全角空格、制表符、换行符,等不可见字符
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isNotBlank(null) // false}
+ * - {@code StrUtil.isNotBlank("") // false}
+ * - {@code StrUtil.isNotBlank(" \t\n") // false}
+ * - {@code StrUtil.isNotBlank("abc") // true}
+ *
+ *
+ * 注意:该方法与 {@link #isNotEmpty(CharSequence)} 的区别是:
+ * 该方法会校验空白字符,且性能相对于 {@link #isNotEmpty(CharSequence)} 略慢。
+ * 建议:仅对于客户端(或第三方接口)传入的参数使用该方法。
+ *
+ * @param str 被检测的字符串
+ * @return 是否为非空
+ * @see #isBlank(CharSequence)
+ */
+ public static boolean isNotBlank(final CharSequence str) {
+ return false == isBlank(str);
+ }
+
+ /**
+ * 指定字符串数组中,是否包含空字符串。
+ * 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.hasBlank() // true}
+ * - {@code StrUtil.hasBlank("", null, " ") // true}
+ * - {@code StrUtil.hasBlank("123", " ") // true}
+ * - {@code StrUtil.hasBlank("123", "abc") // false}
+ *
+ *
+ * 注意:该方法与 {@link #isAllBlank(CharSequence...)} 的区别在于:
+ *
+ * - hasBlank(CharSequence...) 等价于 {@code isBlank(...) || isBlank(...) || ...}
+ * - {@link #isAllBlank(CharSequence...)} 等价于 {@code isBlank(...) && isBlank(...) && ...}
+ *
+ *
+ * @param strs 字符串列表
+ * @return 是否包含空字符串
+ */
+ public static boolean hasBlank(final CharSequence... strs) {
+ if (ArrayUtil.isEmpty(strs)) {
+ return true;
+ }
+
+ for (final CharSequence str : strs) {
+ if (isBlank(str)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 指定字符串集合中,是否包含空字符串。
+ *
+ * @param strs 字符串列表
+ * @return 批量判断字符串是否全部为空白
+ * @see CharSequenceUtil#hasBlank(CharSequence...)
+ * @since 6.0.0
+ */
+ public static boolean hasBlank(final Iterable extends CharSequence> strs) {
+ if (CollUtil.isEmpty(strs)) {
+ return true;
+ }
+ for (final CharSequence str : strs) {
+ if (isBlank(str)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 指定字符串数组中的元素,是否全部为空字符串。
+ * 如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isAllBlank() // true}
+ * - {@code StrUtil.isAllBlank("", null, " ") // true}
+ * - {@code StrUtil.isAllBlank("123", " ") // false}
+ * - {@code StrUtil.isAllBlank("123", "abc") // false}
+ *
+ *
+ * 注意:该方法与 {@link #hasBlank(CharSequence...)} 的区别在于:
+ *
+ * - {@link #hasBlank(CharSequence...)} 等价于 {@code isBlank(...) || isBlank(...) || ...}
+ * - isAllBlank(CharSequence...) 等价于 {@code isBlank(...) && isBlank(...) && ...}
+ *
+ *
+ * @param strs 字符串列表
+ * @return 所有字符串是否为空白
+ */
+ public static boolean isAllBlank(final CharSequence... strs) {
+ if (ArrayUtil.isEmpty(strs)) {
+ return true;
+ }
+
+ for (final CharSequence str : strs) {
+ if (isNotBlank(str)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @param strs 字符串列表
+ * @return 批量判断字符串是否全部为空白
+ * @see CharSequenceUtil#isAllBlank(CharSequence...)
+ * @since 6.0.1
+ */
+ public static boolean isAllBlank(final Iterable extends CharSequence> strs) {
+ if (CollUtil.isNotEmpty(strs)) {
+ for (final CharSequence str : strs) {
+ if (isNotBlank(str)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 字符串是否为空,空的定义如下:
+ *
+ * - {@code null}
+ * - 空字符串:{@code ""}
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isEmpty(null) // true}
+ * - {@code StrUtil.isEmpty("") // true}
+ * - {@code StrUtil.isEmpty(" \t\n") // false}
+ * - {@code StrUtil.isEmpty("abc") // false}
+ *
+ *
+ * 注意:该方法与 {@link #isBlank(CharSequence)} 的区别是:该方法不校验空白字符。
+ * 建议:
+ *
+ * - 该方法建议用于工具类或任何可以预期的方法参数的校验中。
+ * - 需要同时校验多个字符串时,建议采用 {@link #hasEmpty(CharSequence...)} 或 {@link #isAllEmpty(CharSequence...)}
+ *
+ *
+ * @param str 被检测的字符串
+ * @return 是否为空
+ * @see #isBlank(CharSequence)
+ */
+ public static boolean isEmpty(final CharSequence str) {
+ return str == null || str.length() == 0;
+ }
+
+ /**
+ * 字符串是否为非空白,非空白的定义如下:
+ *
+ * - 不为 {@code null}
+ * - 不为空字符串:{@code ""}
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isNotEmpty(null) // false}
+ * - {@code StrUtil.isNotEmpty("") // false}
+ * - {@code StrUtil.isNotEmpty(" \t\n") // true}
+ * - {@code StrUtil.isNotEmpty("abc") // true}
+ *
+ *
+ * 注意:该方法与 {@link #isNotBlank(CharSequence)} 的区别是:该方法不校验空白字符。
+ * 建议:该方法建议用于工具类或任何可以预期的方法参数的校验中。
+ *
+ * @param str 被检测的字符串
+ * @return 是否为非空
+ * @see #isEmpty(CharSequence)
+ */
+ public static boolean isNotEmpty(final CharSequence str) {
+ return false == isEmpty(str);
+ }
+
+ /**
+ * 是否包含空字符串。
+ * 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.hasEmpty() // true}
+ * - {@code StrUtil.hasEmpty("", null) // true}
+ * - {@code StrUtil.hasEmpty("123", "") // true}
+ * - {@code StrUtil.hasEmpty("123", "abc") // false}
+ * - {@code StrUtil.hasEmpty(" ", "\t", "\n") // false}
+ *
+ *
+ * 注意:该方法与 {@link #isAllEmpty(CharSequence...)} 的区别在于:
+ *
+ * - hasEmpty(CharSequence...) 等价于 {@code isEmpty(...) || isEmpty(...) || ...}
+ * - {@link #isAllEmpty(CharSequence...)} 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
+ *
+ *
+ * @param strs 字符串列表
+ * @return 是否包含空字符串
+ */
+ public static boolean hasEmpty(final CharSequence... strs) {
+ if (ArrayUtil.isEmpty(strs)) {
+ return true;
+ }
+
+ for (final CharSequence str : strs) {
+ if (isEmpty(str)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 是否包含空字符串。
+ * 如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。
+ *
+ * @param strs 字符串列表
+ * @return 是否包含空字符串
+ * @since 6.0.0
+ */
+ public static boolean hasEmpty(final Iterable extends CharSequence> strs) {
+ if (CollUtil.isEmpty(strs)) {
+ return true;
+ }
+
+ for (final CharSequence str : strs) {
+ if (isEmpty(str)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 指定字符串数组中的元素,是否全部为空字符串。
+ * 如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isAllEmpty() // true}
+ * - {@code StrUtil.isAllEmpty("", null) // true}
+ * - {@code StrUtil.isAllEmpty("123", "") // false}
+ * - {@code StrUtil.isAllEmpty("123", "abc") // false}
+ * - {@code StrUtil.isAllEmpty(" ", "\t", "\n") // false}
+ *
+ *
+ * 注意:该方法与 {@link #hasEmpty(CharSequence...)} 的区别在于:
+ *
+ * - {@link #hasEmpty(CharSequence...)} 等价于 {@code isEmpty(...) || isEmpty(...) || ...}
+ * - isAllEmpty(CharSequence...) 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
+ *
+ *
+ * @param strs 字符串列表
+ * @return 所有字符串是否为空白
+ */
+ public static boolean isAllEmpty(final CharSequence... strs) {
+ 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 extends CharSequence> strs) {
+ if (CollUtil.isNotEmpty(strs)) {
+ for (final CharSequence str : strs) {
+ if (isNotEmpty(str)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * 指定字符串数组中的元素,是否都不为空字符串。
+ * 如果指定的字符串数组的长度不为 0,或者所有元素都不是空字符串,则返回 true。
+ *
+ *
+ * 例:
+ *
+ * - {@code StrUtil.isAllNotEmpty() // false}
+ * - {@code StrUtil.isAllNotEmpty("", null) // false}
+ * - {@code StrUtil.isAllNotEmpty("123", "") // false}
+ * - {@code StrUtil.isAllNotEmpty("123", "abc") // true}
+ * - {@code StrUtil.isAllNotEmpty(" ", "\t", "\n") // true}
+ *
+ *
+ * 注意:该方法与 {@link #isAllEmpty(CharSequence...)} 的区别在于:
+ *
+ * - {@link #isAllEmpty(CharSequence...)} 等价于 {@code isEmpty(...) && isEmpty(...) && ...}
+ * - isAllNotEmpty(CharSequence...) 等价于 {@code !isEmpty(...) && !isEmpty(...) && ...}
+ *
+ *
+ * @param args 字符串数组
+ * @return 所有字符串是否都不为为空白
+ * @since 5.3.6
+ */
+ public static boolean isAllNotEmpty(final CharSequence... args) {
+ return false == hasEmpty(args);
+ }
+
+ /**
+ * 是否存都不为{@code null}或空对象或空白符的对象,通过{@link #hasBlank(CharSequence...)} 判断元素
+ *
+ * @param args 被检查的对象,一个或者多个
+ * @return 是否都不为空
+ * @since 5.3.6
+ */
+ public static boolean isAllNotBlank(final CharSequence... args) {
+ return false == hasBlank(args);
+ }
+
+ /**
+ * 检查字符串是否为null、“null”、“undefined”
+ *
+ * @param str 被检查的字符串
+ * @return 是否为null、“null”、“undefined”
+ * @since 4.0.10
+ */
+ public static boolean isNullOrUndefined(final CharSequence str) {
+ if (null == str) {
+ return true;
+ }
+ return isNullOrUndefinedStr(str);
+ }
+
+ /**
+ * 检查字符串是否为null、“”、“null”、“undefined”
+ *
+ * @param str 被检查的字符串
+ * @return 是否为null、“”、“null”、“undefined”
+ * @since 4.0.10
+ */
+ public static boolean isEmptyOrUndefined(final CharSequence str) {
+ if (isEmpty(str)) {
+ return true;
+ }
+ return isNullOrUndefinedStr(str);
+ }
+
+ /**
+ * 检查字符串是否为null、空白串、“null”、“undefined”
+ *
+ * @param str 被检查的字符串
+ * @return 是否为null、空白串、“null”、“undefined”
+ * @since 4.0.10
+ */
+ public static boolean isBlankOrUndefined(final CharSequence str) {
+ if (isBlank(str)) {
+ return true;
+ }
+ return isNullOrUndefinedStr(str);
+ }
+
+ /**
+ * 是否为“null”、“undefined”,不做空指针检查
+ *
+ * @param str 字符串
+ * @return 是否为“null”、“undefined”
+ */
+ private static boolean isNullOrUndefinedStr(final CharSequence str) {
+ final String strString = str.toString().trim();
+ return NULL.equals(strString) || "undefined".equals(strString);
+ }
+
+ /**
+ * 字符串的每一个字符是否都与定义的匹配器匹配
+ *
+ * @param value 字符串
+ * @param matcher 匹配器
+ * @return 是否全部匹配
+ * @since 3.2.3
+ */
+ public static boolean isAllCharMatch(final CharSequence value, final Predicate matcher) {
+ if (StrUtil.isBlank(value)) {
+ return false;
+ }
+ for (int i = value.length(); --i >= 0; ) {
+ if (false == matcher.test(value.charAt(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+}