mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-15 14:04:33 +08:00
[enhancement] 支持NaN类型
This commit is contained in:
parent
4ccb44ee26
commit
d620a72585
@ -533,13 +533,19 @@ public class BooleanUtil {
|
||||
* 定义{@see https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy}
|
||||
*/
|
||||
public static boolean isJsFalsy(Object value) {
|
||||
return FALSY_SET.contains(value);
|
||||
if (FALSY_SET.contains(value)) {
|
||||
return true;
|
||||
}
|
||||
if (value instanceof Double) {
|
||||
return Double.isNaN((Double) value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为真值(定义来源js)
|
||||
* 所有除 false、0、-0、0n、""、null、undefined 和 NaN 以外的皆为真值
|
||||
* 由于java中无法使用值来代表undefined 和 NaN,因此此处不做判断
|
||||
* 由于java中无法使用值来代表undefined,因此此处不做判断
|
||||
*
|
||||
* @param value 参数
|
||||
* @return 是否为真值
|
||||
|
@ -110,6 +110,7 @@ public class BooleanUtilTest {
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(-0.00F));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(""));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(null));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(Math.sqrt(-1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user