add methods

This commit is contained in:
Looly 2022-06-29 18:58:53 +08:00
parent c56959fe7a
commit 56bc948d99
2 changed files with 50 additions and 12 deletions

View File

@ -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<? extends CharSequence> strs) {
if (ArrayUtil.isEmpty(strs)) {
public static boolean hasBlank(final Iterable<? extends CharSequence> 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<? extends CharSequence> strs) {
public static boolean isAllBlank(final Iterable<? extends CharSequence> strs) {
if (CollUtil.isNotEmpty(strs)) {
for (final CharSequence str : strs) {
if (isNotBlank(str)) {
@ -415,6 +414,27 @@ public class CharSequenceUtil {
return false;
}
/**
* <p>是否包含空字符串</p>
* <p>如果指定的字符串数组的长度为 0或者其中的任意一个元素是空字符串则返回 true</p>
*
* @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;
}
/**
* <p>指定字符串数组中的元素是否全部为空字符串</p>
* <p>如果指定的字符串数组的长度为 0或者所有元素都是空字符串则返回 true</p>
@ -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;
}
/**
* <p>指定字符串数组中的元素是否全部为空字符串</p>
* <p>如果指定的字符串数组的长度为 0或者所有元素都是空字符串则返回 true</p>
*
* @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;
}

View File

@ -46,7 +46,7 @@ public class StrUtilTest {
}
@Test
public void testIssAllBlank() {
public void testIsAllBlank() {
final List<String> queue = new LinkedList<>();
queue.add("apple");
queue.add("banana");