Browse Source

add check

Looly 5 years ago
parent
commit
52d341e650
2 changed files with 5 additions and 4 deletions
  1. 2 1
      CHANGELOG.md
  2. 3 3
      hutool-core/src/main/java/cn/hutool/core/collection/ListUtil.java

+ 2 - 1
CHANGELOG.md

@@ -3,11 +3,12 @@
 
 -------------------------------------------------------------------------------------------------------------
 
-# 5.5.3 (2020-12-02)
+# 5.5.3 (2020-12-04)
 
 ### 新特性
 * 【core   】     IdcardUtil增加行政区划83(issue#1277@Github)
 * 【core   】     multipart中int改为long,解决大文件上传越界问题(issue#I27WZ3@Gitee)
+* 【core   】     ListUtil.page增加检查(pr#224@Gitee)
 
 ### Bug修复
 * 【cache  】     修复Cache中get重复misCount计数问题(issue#1281@Github)

+ 3 - 3
hutool-core/src/main/java/cn/hutool/core/collection/ListUtil.java

@@ -245,7 +245,7 @@ public class ListUtil {
 		int resultSize = list.size();
 		// 每页条目数大于总数直接返回所有
 		if (resultSize <= pageSize) {
-			if (pageNo < (PageUtil.getFirstPageNo()+1)) {
+			if (pageNo < (PageUtil.getFirstPageNo() + 1)) {
 				return Collections.unmodifiableList(list);
 			} else {
 				// 越界直接返回空
@@ -253,7 +253,7 @@ public class ListUtil {
 			}
 		}
 		// 相乘可能会导致越界 临时用long
-		if (((long) (pageNo-PageUtil.getFirstPageNo()) * pageSize) > resultSize) {
+		if (((long) (pageNo - PageUtil.getFirstPageNo()) * pageSize) > resultSize) {
 			// 越界直接返回空
 			return new ArrayList<>(0);
 		}
@@ -262,7 +262,7 @@ public class ListUtil {
 		if (startEnd[1] > resultSize) {
 			startEnd[1] = resultSize;
 			if (startEnd[0] > startEnd[1]) {
-			    return new ArrayList<>(0);
+				return empty();
 			}
 		}