mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
BooleanUtil的andOfWrap和orOfWrap()忽略null
This commit is contained in:
parent
4696576598
commit
b2c90d7d88
@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.8.7.M1 (2022-09-07)
|
# 5.8.7.M1 (2022-09-13)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
|
* 【core 】 BooleanUtil的andOfWrap和orOfWrap()忽略null(issue#2599@Github)
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -356,8 +356,13 @@ public class BooleanUtil {
|
|||||||
if (ArrayUtil.isEmpty(array)) {
|
if (ArrayUtil.isEmpty(array)) {
|
||||||
throw new IllegalArgumentException("The Array must not be empty !");
|
throw new IllegalArgumentException("The Array must not be empty !");
|
||||||
}
|
}
|
||||||
final boolean[] primitive = Convert.convert(boolean[].class, array);
|
|
||||||
return and(primitive);
|
for (final Boolean b : array) {
|
||||||
|
if(isFalse(b)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -407,8 +412,13 @@ public class BooleanUtil {
|
|||||||
if (ArrayUtil.isEmpty(array)) {
|
if (ArrayUtil.isEmpty(array)) {
|
||||||
throw new IllegalArgumentException("The Array must not be empty !");
|
throw new IllegalArgumentException("The Array must not be empty !");
|
||||||
}
|
}
|
||||||
final boolean[] primitive = Convert.convert(boolean[].class, array);
|
|
||||||
return or(primitive);
|
for (final Boolean b : array) {
|
||||||
|
if(isTrue(b)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1283,7 +1283,8 @@ public class PrimitiveArrayUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 包装类数组转为原始类型数组
|
* 包装类数组转为原始类型数组<br>
|
||||||
|
* {@code null} 按照 {@code false} 对待
|
||||||
*
|
*
|
||||||
* @param values 包装类型数组
|
* @param values 包装类型数组
|
||||||
* @return 原始类型数组
|
* @return 原始类型数组
|
||||||
|
@ -39,4 +39,37 @@ public class BooleanUtilTest {
|
|||||||
Assert.assertTrue(BooleanUtil.xor(true,false));
|
Assert.assertTrue(BooleanUtil.xor(true,false));
|
||||||
Assert.assertTrue(BooleanUtil.xorOfWrap(true,false));
|
Assert.assertTrue(BooleanUtil.xorOfWrap(true,false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void orOfWrapTest() {
|
||||||
|
Assert.assertFalse(BooleanUtil.orOfWrap(Boolean.FALSE, null));
|
||||||
|
Assert.assertTrue(BooleanUtil.orOfWrap(Boolean.TRUE, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
@Test
|
||||||
|
public void isTrueIsFalseTest() {
|
||||||
|
Assert.assertFalse(BooleanUtil.isTrue(null));
|
||||||
|
Assert.assertFalse(BooleanUtil.isFalse(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
public void negateTest() {
|
||||||
|
Assert.assertFalse(BooleanUtil.negate(Boolean.TRUE));
|
||||||
|
Assert.assertTrue(BooleanUtil.negate(Boolean.FALSE));
|
||||||
|
|
||||||
|
Assert.assertFalse(BooleanUtil.negate(Boolean.TRUE.booleanValue()));
|
||||||
|
Assert.assertTrue(BooleanUtil.negate(Boolean.FALSE.booleanValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toStringTest() {
|
||||||
|
Assert.assertEquals("true", BooleanUtil.toStringTrueFalse(true));
|
||||||
|
Assert.assertEquals("false", BooleanUtil.toStringTrueFalse(false));
|
||||||
|
|
||||||
|
Assert.assertEquals("yes", BooleanUtil.toStringYesNo(true));
|
||||||
|
Assert.assertEquals("no", BooleanUtil.toStringYesNo(false));
|
||||||
|
|
||||||
|
Assert.assertEquals("on", BooleanUtil.toStringOnOff(true));
|
||||||
|
Assert.assertEquals("off", BooleanUtil.toStringOnOff(false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user