mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
Revert "[feature] 新增BooleanUtil.isJsFalsy以及isJsTruthy"
This reverts commit 4db9c44d18
.
This commit is contained in:
parent
2919749c8f
commit
a1144f5228
@ -17,8 +17,6 @@ public class BooleanUtil {
|
||||
private static final Set<String> TRUE_SET = SetUtil.of("true", "yes", "y", "t", "ok", "1", "on", "是", "对", "真", "對", "√");
|
||||
/** 表示为假的字符串 */
|
||||
private static final Set<String> FALSE_SET = SetUtil.of("false", "no", "n", "f", "0", "off", "否", "错", "假", "錯", "×");
|
||||
/** js中表示假值Falsy的部分值 false、0、-0、0n、""、null、undefined 和 NaN */
|
||||
public static final Set<Object> FALSY_SET = SetUtil.of(false, 0, -0, 0L, 0.0D, -0.0D, "", null);
|
||||
|
||||
/**
|
||||
* 取相反值
|
||||
@ -524,28 +522,4 @@ public class BooleanUtil {
|
||||
public static boolean isBoolean(final Class<?> clazz) {
|
||||
return (clazz == Boolean.class || clazz == boolean.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为假值(定义来源js)
|
||||
*
|
||||
* @param value 参数
|
||||
* @return 是否为假值
|
||||
* 定义{@see https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy}
|
||||
*/
|
||||
public static boolean isJsFalsy(Object value) {
|
||||
return FALSY_SET.contains(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为真值(定义来源js)
|
||||
* 所有除 false、0、-0、0n、""、null、undefined 和 NaN 以外的皆为真值
|
||||
* 由于java中无法使用值来代表undefined 和 NaN,因此此处不做判断
|
||||
*
|
||||
* @param value 参数
|
||||
* @return 是否为真值
|
||||
* 定义{@see https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy}
|
||||
*/
|
||||
public static boolean isJsTruthy(Object value) {
|
||||
return false == isJsFalsy(value);
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public class BooleanUtilTest {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void toBooleanObjectTest() {
|
||||
public void toBooleanObjectTest(){
|
||||
Assert.assertTrue(BooleanUtil.toBooleanObject("yes"));
|
||||
Assert.assertTrue(BooleanUtil.toBooleanObject("真"));
|
||||
Assert.assertTrue(BooleanUtil.toBooleanObject("是"));
|
||||
@ -95,30 +95,4 @@ public class BooleanUtilTest {
|
||||
Assert.assertNull(BooleanUtil.toBooleanObject(null));
|
||||
Assert.assertNull(BooleanUtil.toBooleanObject("不识别"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isJsFalsyTest() {
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(false));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(0));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(-0));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(0L));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(0.0D));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(0.00D));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(-0.00D));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(""));
|
||||
Assert.assertTrue(BooleanUtil.isJsFalsy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isJsTruthyTest() {
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy(true));
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy(1));
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy(-1));
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy("0"));
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy("null"));
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy("undefined"));
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy(1L));
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy(0.1D));
|
||||
Assert.assertTrue(BooleanUtil.isJsTruthy(-0.01D));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user