mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
!919 修复“sax方式读取excel2003版本,会调用两次doAfterAllAnalysed方法”问题。
Merge pull request !919 from hellozrh/v5-dev
This commit is contained in:
@@ -1659,6 +1659,35 @@ public class CollUtil {
|
||||
return collection == null || collection.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 集合是否为空。
|
||||
* 如果集合中所有元素为null或空串,也认为此集合为空。
|
||||
* @param collection
|
||||
* @return
|
||||
*/
|
||||
public static boolean isBlank(Collection<?> collection) {
|
||||
if(isEmpty(collection)){
|
||||
return true;
|
||||
}
|
||||
|
||||
for(Object o: collection){
|
||||
if(ObjectUtil.isNotEmpty(o)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 集合是否为非空。
|
||||
* 集合长度大于0,且所有元素中至少有一个不为null或空串。
|
||||
* @param collection
|
||||
* @return
|
||||
*/
|
||||
public static boolean isNotBlank(Collection<?> collection) {
|
||||
return false == isBlank(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果给定集合为空,返回默认集合
|
||||
*
|
||||
|
@@ -1047,4 +1047,27 @@ public class CollUtilTest {
|
||||
final Object first = CollUtil.getFirst(nullList);
|
||||
Assert.assertNull(first);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blankTest() {
|
||||
List<String> strs = new ArrayList<>();
|
||||
strs.add(null);
|
||||
strs.add("");
|
||||
strs.add("");
|
||||
|
||||
boolean c = CollUtil.isBlank(strs);
|
||||
Assert.assertEquals(true, c );
|
||||
|
||||
|
||||
List<String> arrs = new ArrayList<>();
|
||||
arrs.add(null);
|
||||
arrs.add("");
|
||||
arrs.add(" ");
|
||||
arrs.add("");
|
||||
arrs.add(" a ");
|
||||
|
||||
boolean d = CollUtil.isNotBlank(arrs);
|
||||
Assert.assertEquals(true, d );
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user