diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java index fa94976ed..c89186805 100755 --- a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java @@ -1652,6 +1652,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); + } + /** * 如果给定集合为空,返回默认集合 * diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java index b9b9d4775..5400cd5fe 100755 --- a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java @@ -1047,4 +1047,27 @@ public class CollUtilTest { final Object first = CollUtil.getFirst(nullList); Assert.assertNull(first); } + + @Test + public void blankTest() { + List strs = new ArrayList<>(); + strs.add(null); + strs.add(""); + strs.add(""); + + boolean c = CollUtil.isBlank(strs); + Assert.assertEquals(true, c ); + + + List arrs = new ArrayList<>(); + arrs.add(null); + arrs.add(""); + arrs.add(" "); + arrs.add(""); + arrs.add(" a "); + + boolean d = CollUtil.isNotBlank(arrs); + Assert.assertEquals(true, d ); + } + } diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel03SaxReader.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel03SaxReader.java index 0f1f3d184..e9416b9cd 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel03SaxReader.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel03SaxReader.java @@ -1,7 +1,9 @@ package cn.hutool.poi.excel.sax; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.poi.excel.sax.handler.RowHandler; @@ -344,8 +346,11 @@ public class Excel03SaxReader implements HSSFListener, ExcelSaxReader(this.rowCellList.size()); } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelUtilTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelUtilTest.java index 2b66d5754..c5be2efa9 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelUtilTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelUtilTest.java @@ -1,11 +1,21 @@ package cn.hutool.poi.excel; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.poi.excel.cell.CellLocation; +import cn.hutool.poi.excel.sax.handler.RowHandler; import org.junit.Assert; import org.junit.Test; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; public class ExcelUtilTest { @@ -61,4 +71,23 @@ public class ExcelUtilTest { reader.close(); Assert.assertEquals(1L, list.get(1).get("鞋码")); } + + @Test + public void readBySaxTest() { + String path = "readBySax.xls"; + AtomicInteger assertRowNum = new AtomicInteger(0); + try{ + ExcelUtil.readBySax(path, 0, new RowHandler() { + @Override + public void handle(int sheetIndex, long rowIndex, List rowCells) { + System.out.println(StrUtil.format("sheetIndex={};rowIndex={},rowCells={}",sheetIndex,rowIndex,rowCells)); + assertRowNum.addAndGet(1); + } + }); + }catch (Exception ex){ + ex.printStackTrace(); + } + Assert.assertEquals(3, assertRowNum.intValue()); + } + }