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 a99961183..685fbd959 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
@@ -227,15 +227,20 @@ public class CollUtil {
}
/**
- * 是否包含{@code null}元素
+ * 是否包含{@code null}元素
+ *
+ * 集合为{@code null},返回{@code true}
+ * 集合为空集合,即元素个数为0,返回{@code false}
+ * 集合中元素为"",返回{@code false}
+ *
*
* @param iterable 被检查的Iterable对象,如果为{@code null} 返回true
* @return 是否包含{@code null}元素
- * @see IterUtil#hasNull(Iterable)
+ * @see IterUtil#hasNull(Iterator)
* @since 3.0.7
*/
public static boolean hasNull(final Iterable> iterable) {
- return IterUtil.hasNull(iterable);
+ return IterUtil.hasNull(IterUtil.getIter(iterable));
}
/**
@@ -1359,6 +1364,10 @@ public class CollUtil {
* @return 第一个元素,为空返回{@code null}
*/
public static T getFirst(final Iterable iterable) {
+ if (iterable instanceof List) {
+ final List list = (List) iterable;
+ return CollUtil.isEmpty(list) ? null: list.get(0);
+ }
return IterUtil.getFirst(IterUtil.getIter(iterable));
}
diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/iter/IterUtil.java b/hutool-core/src/main/java/cn/hutool/core/collection/iter/IterUtil.java
index 214b15063..5b018d640 100644
--- a/hutool-core/src/main/java/cn/hutool/core/collection/iter/IterUtil.java
+++ b/hutool-core/src/main/java/cn/hutool/core/collection/iter/IterUtil.java
@@ -87,17 +87,12 @@ public class IterUtil {
}
/**
- * 是否包含{@code null}元素
- *
- * @param iter 被检查的{@link Iterable}对象,如果为{@code null} 返回true
- * @return 是否包含{@code null}元素
- */
- public static boolean hasNull(final Iterable> iter) {
- return hasNull(null == iter ? null : iter.iterator());
- }
-
- /**
- * 是否包含{@code null}元素
+ * 是否包含{@code null}元素
+ *
+ * Iterator为{@code null},返回{@code true}
+ * Iterator为空集合,即元素个数为0,返回{@code false}
+ * Iterator中元素为"",返回{@code false}
+ *
*
* @param iter 被检查的{@link Iterator}对象,如果为{@code null} 返回true
* @return 是否包含{@code null}元素
diff --git a/hutool-core/src/main/java/cn/hutool/core/date/format/parser/UTCDateParser.java b/hutool-core/src/main/java/cn/hutool/core/date/format/parser/UTCDateParser.java
index 9403c858a..c14812701 100644
--- a/hutool-core/src/main/java/cn/hutool/core/date/format/parser/UTCDateParser.java
+++ b/hutool-core/src/main/java/cn/hutool/core/date/format/parser/UTCDateParser.java
@@ -64,6 +64,9 @@ public class UTCDateParser extends DefaultDateBasic implements DateParser {
if (length == DatePattern.UTC_SIMPLE_PATTERN.length() - 2) {
// 格式类似:2018-09-13T05:34:31
return new DateTime(source, DatePattern.UTC_SIMPLE_FORMAT);
+ } else if (length == DatePattern.UTC_SIMPLE_PATTERN.length() - 5) {
+ // 格式类似:2018-09-13T05:34
+ return new DateTime(source + ":00", DatePattern.UTC_SIMPLE_FORMAT);
} else if (StrUtil.contains(source, CharUtil.DOT)) {
// 可能为: 2021-03-17T06:31:33.99
return new DateTime(source, DatePattern.UTC_SIMPLE_MS_FORMAT);
diff --git a/hutool-core/src/main/java/cn/hutool/core/math/NumberUtil.java b/hutool-core/src/main/java/cn/hutool/core/math/NumberUtil.java
index 923058e4c..ca075472f 100644
--- a/hutool-core/src/main/java/cn/hutool/core/math/NumberUtil.java
+++ b/hutool-core/src/main/java/cn/hutool/core/math/NumberUtil.java
@@ -267,7 +267,7 @@ public class NumberUtil {
}
/**
- * 补充Math.ceilDiv() JDK8中添加了和Math.floorDiv()但却没有ceilDiv()
+ * 补充Math.ceilDiv() JDK8中添加了和 {@link Math#floorDiv(int, int)} 但却没有ceilDiv()
*
* @param v1 被除数
* @param v2 除数
@@ -1448,6 +1448,7 @@ public class NumberUtil {
* 4、空串返回0
* 5、.123形式返回0(按照小于0的小数对待)
* 6、123.56截取小数点之前的数字,忽略小数部分
+ * 7、科学计数法抛出NumberFormatException异常
*
*
* @param number 数字,支持0x开头、0开头和普通十进制
@@ -1460,6 +1461,11 @@ public class NumberUtil {
return 0;
}
+ if(StrUtil.containsIgnoreCase(number, "E")){
+ // 科学计数法忽略支持,科学计数法一般用于表示非常小和非常大的数字,这类数字转换为int后精度丢失,没有意义。
+ throw new NumberFormatException(StrUtil.format("Unsupported int format: [{}]", number));
+ }
+
if (StrUtil.startWithIgnoreCase(number, "0x")) {
// 0x04表示16进制数
return Integer.parseInt(number.substring(2), 16);
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 a55948404..69131a156 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
@@ -15,6 +15,7 @@ import lombok.ToString;
import org.junit.Assert;
import org.junit.Test;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -39,6 +40,34 @@ import java.util.function.Function;
*/
public class CollUtilTest {
+ @SuppressWarnings("ConstantConditions")
+ @Test
+ public void emptyIfNullTest() {
+ final Set> set = null;
+ final Set> set1 = CollUtil.emptyIfNull(set);
+ Assert.assertEquals(SetUtil.empty(), set1);
+
+ final List> list = null;
+ final List> list1 = CollUtil.emptyIfNull(list);
+ Assert.assertEquals(ListUtil.empty(), list1);
+ }
+
+ @SuppressWarnings("ConstantConditions")
+ @Test
+ public void hasNullTest() {
+ ArrayList