This commit is contained in:
Looly 2019-10-02 16:33:25 +08:00
parent e1fe54c59d
commit 1ddc01453f
5 changed files with 28 additions and 11 deletions

View File

@ -6,7 +6,11 @@
## 4.6.9
### 新特性
* 【all】 修复注释中的错别字issue#I12XE6@Gitee
* 【core】 CsvWriter支持其它类型的参数issue#I12XE3@Gitee
### Bug修复
* 【all】 修复阶乘计算错误bugissue#I12XE4@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -233,7 +233,7 @@ public class Convert {
/**
* 转换为Integer数组<br>
*
*
* @param value 被转换的值
* @return 结果
*/

View File

@ -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<String[]> 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();
}

View File

@ -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;
/**
* 数字工具类<br>
@ -1382,17 +1383,17 @@ public class NumberUtil {
* </p>
*
* @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);
}

View File

@ -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);
}
}