diff --git a/CHANGELOG.md b/CHANGELOG.md index 0562c290f..522308299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ ## 4.6.9 ### 新特性 +* 【all】 修复注释中的错别字(issue#I12XE6@Gitee) +* 【core】 CsvWriter支持其它类型的参数(issue#I12XE3@Gitee) + ### Bug修复 +* 【all】 修复阶乘计算错误bug(issue#I12XE4@Gitee) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/convert/Convert.java b/hutool-core/src/main/java/cn/hutool/core/convert/Convert.java index 08e718ac3..3d485f5ec 100644 --- a/hutool-core/src/main/java/cn/hutool/core/convert/Convert.java +++ b/hutool-core/src/main/java/cn/hutool/core/convert/Convert.java @@ -233,7 +233,7 @@ public class Convert { /** * 转换为Integer数组
- * + * * @param value 被转换的值 * @return 结果 */ diff --git a/hutool-core/src/main/java/cn/hutool/core/text/csv/CsvWriter.java b/hutool-core/src/main/java/cn/hutool/core/text/csv/CsvWriter.java index 7db1433cf..bdbfbdf70 100644 --- a/hutool-core/src/main/java/cn/hutool/core/text/csv/CsvWriter.java +++ b/hutool-core/src/main/java/cn/hutool/core/text/csv/CsvWriter.java @@ -11,6 +11,7 @@ import java.nio.charset.Charset; import java.util.Collection; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.io.IoUtil; @@ -183,14 +184,14 @@ public final class CsvWriter implements Closeable, Flushable, Serializable { /** * 将多行写出到Writer * - * @param lines 多行数据 + * @param lines 多行数据,每行数据可以是集合或者数组 * @return this * @throws IORuntimeException IO异常 */ - public CsvWriter write(Collection lines) throws IORuntimeException { + public CsvWriter write(Collection lines) throws IORuntimeException { if (CollUtil.isNotEmpty(lines)) { - for (final String[] values : lines) { - appendLine(values); + for (Object values : lines) { + appendLine(Convert.toStrArray(values)); } flush(); } diff --git a/hutool-core/src/main/java/cn/hutool/core/util/NumberUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/NumberUtil.java index 75f1d6a21..6293a370d 100644 --- a/hutool-core/src/main/java/cn/hutool/core/util/NumberUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/NumberUtil.java @@ -13,6 +13,7 @@ import java.util.Set; import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.lang.Assert; +import cn.hutool.core.lang.Console; /** * 数字工具类
@@ -1382,17 +1383,17 @@ public class NumberUtil { *

* * @param start 阶乘起始 - * @param end 阶乘结束 + * @param end 阶乘结束,必须小于起始 * @return 结果 * @since 4.1.0 */ public static long factorial(long start, long end) { + if (0L == start || start == end) { + return 1L; + } if (start < end) { return 0L; } - if (start == end) { - return 1L; - } return start * factorial(start - 1, end); } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java index 4622f9eaa..fda651f73 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java @@ -188,13 +188,13 @@ public class NumberUtilTest { BigDecimal bigDecimal = NumberUtil.toBigDecimal(a); Assert.assertEquals("3.14", bigDecimal.toString()); } - + @Test public void maxTest() { int max = NumberUtil.max(new int[]{5,4,3,6,1}); Assert.assertEquals(6, max); } - + @Test public void minTest() { int min = NumberUtil.min(new int[]{5,4,3,6,1}); @@ -232,4 +232,15 @@ public class NumberUtilTest { long v6 = NumberUtil.parseLong("22.4D"); Assert.assertEquals(22L, v6); } + + @Test + public void factorialTest(){ + long factorial = NumberUtil.factorial(0); + Assert.assertEquals(1, factorial); + + factorial = NumberUtil.factorial(5, 0); + Assert.assertEquals(120, factorial); + factorial = NumberUtil.factorial(5, 1); + Assert.assertEquals(120, factorial); + } }