BooleanUtil的andOfWrap和orOfWrap()忽略null

This commit is contained in:
Looly 2022-09-13 11:17:13 +08:00
parent 4696576598
commit b2c90d7d88
4 changed files with 53 additions and 8 deletions

View File

@ -3,9 +3,10 @@
-------------------------------------------------------------------------------------------------------------
# 5.8.7.M1 (2022-09-07)
# 5.8.7.M1 (2022-09-13)
### 🐣新特性
* 【core 】 BooleanUtil的andOfWrap和orOfWrap()忽略nullissue#2599@Github
### 🐞Bug修复
-------------------------------------------------------------------------------------------------------------

View File

@ -356,8 +356,13 @@ public class BooleanUtil {
if (ArrayUtil.isEmpty(array)) {
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)) {
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;
}
/**

View File

@ -1283,7 +1283,8 @@ public class PrimitiveArrayUtil {
}
/**
* 包装类数组转为原始类型数组
* 包装类数组转为原始类型数组<br>
* {@code null} 按照 {@code false} 对待
*
* @param values 包装类型数组
* @return 原始类型数组

View File

@ -4,7 +4,7 @@ import org.junit.Assert;
import org.junit.Test;
public class BooleanUtilTest {
@Test
public void toBooleanTest() {
Assert.assertTrue(BooleanUtil.toBoolean("true"));
@ -16,7 +16,7 @@ public class BooleanUtilTest {
Assert.assertTrue(BooleanUtil.toBoolean(""));
Assert.assertTrue(BooleanUtil.toBoolean(""));
Assert.assertTrue(BooleanUtil.toBoolean(""));
Assert.assertFalse(BooleanUtil.toBoolean("false"));
Assert.assertFalse(BooleanUtil.toBoolean("6455434"));
Assert.assertFalse(BooleanUtil.toBoolean(""));
@ -39,4 +39,37 @@ public class BooleanUtilTest {
Assert.assertTrue(BooleanUtil.xor(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));
}
}