mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
add methods
This commit is contained in:
parent
576860f878
commit
c56959fe7a
@ -19,6 +19,7 @@ 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;
|
||||
@ -162,6 +163,26 @@ public class CharSequenceUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定字符串集合中,是否包含空字符串。
|
||||
*
|
||||
* @param strs 字符串列表
|
||||
* @return 批量判断字符串是否全部为空白
|
||||
* @see CharSequenceUtil#hasBlank(CharSequence...)
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static boolean hasBlank(final Collection<? extends CharSequence> strs) {
|
||||
if (ArrayUtil.isEmpty(strs)) {
|
||||
return true;
|
||||
}
|
||||
for (final CharSequence str : strs) {
|
||||
if (isBlank(str)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>指定字符串数组中的元素,是否全部为空字符串。</p>
|
||||
* <p>如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。</p>
|
||||
@ -197,6 +218,23 @@ public class CharSequenceUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strs 字符串列表
|
||||
* @return 批量判断字符串是否全部为空白
|
||||
* @see CharSequenceUtil#isAllBlank(CharSequence...)
|
||||
* @since 6.0.1
|
||||
*/
|
||||
public static boolean isAllBlank(final Collection<? extends CharSequence> strs) {
|
||||
if (CollUtil.isNotEmpty(strs)) {
|
||||
for (final CharSequence str : strs) {
|
||||
if (isNotBlank(str)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>字符串是否为空,空的定义如下:</p>
|
||||
* <ol>
|
||||
@ -3991,7 +4029,7 @@ public class CharSequenceUtil {
|
||||
/**
|
||||
* 过滤字符串
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param str 字符串
|
||||
* @param predicate 过滤器,{@link Predicate#test(Object)}为{@code true}保留字符
|
||||
* @return 过滤后的字符串
|
||||
* @since 5.4.0
|
||||
|
@ -7,7 +7,6 @@ import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -416,22 +415,4 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
|
||||
public static String format(final CharSequence template, final Map<?, ?> map, final boolean ignoreNull) {
|
||||
return StrFormatter.format(template, map, ignoreNull);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CharSequenceUtil#isAllBlank(CharSequence...)
|
||||
* @param strs 字符串列表
|
||||
* @return 批量判断字符串是否全部为空白
|
||||
* @since 6.0.1
|
||||
*/
|
||||
public static boolean isAllBlank(final Collection<? extends CharSequence> strs) {
|
||||
if (ArrayUtil.isEmpty(strs)) {
|
||||
return true;
|
||||
}
|
||||
for (final CharSequence str : strs) {
|
||||
if (isNotBlank(str)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class StrUtilTest {
|
||||
|
||||
@Test
|
||||
public void testIssAllBlank() {
|
||||
List<String> queue = new LinkedList<>();
|
||||
final List<String> queue = new LinkedList<>();
|
||||
queue.add("apple");
|
||||
queue.add("banana");
|
||||
queue.add("cherry");
|
||||
|
Loading…
Reference in New Issue
Block a user