mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
commit
4d9b19ab26
@ -4240,4 +4240,27 @@ public class ArrayUtil {
|
||||
Collections.addAll(set, array);
|
||||
return toArray(set, (Class<T>)getComponentType(array));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 多个字段是否全部不为null
|
||||
*
|
||||
* @param <T> 数组元素类型
|
||||
* @param array 被检查的数组
|
||||
* @return 多个字段是否全部不为null
|
||||
* @since 5.3.11
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> boolean isAllNotNull(T... array) {
|
||||
if (isNotEmpty(array)) {
|
||||
for (T element : array) {
|
||||
if (null == element) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -289,4 +289,12 @@ public class ArrayUtilTest {
|
||||
final int[] ints = ArrayUtil.addAll(new int[]{1, 2, 3}, new int[]{4, 5, 6});
|
||||
Assert.assertArrayEquals(new int[]{1,2,3,4,5,6}, ints);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAllNotNullTest(){
|
||||
String[] allNotNull = {"aa", "bb", "cc", "dd", "bb", "dd"};
|
||||
Assert.assertTrue(ArrayUtil.isAllNotNull(allNotNull));
|
||||
String[] hasNull = {"aa", "bb", "cc", null, "bb", "dd"};
|
||||
Assert.assertFalse(ArrayUtil.isAllNotNull(hasNull));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user