Merge pull request #1008 from Saron123456/v5-dev

多个字段是否全部不为空
This commit is contained in:
Golden Looly 2020-08-07 17:43:50 +08:00 committed by GitHub
commit 4d9b19ab26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 255 additions and 224 deletions

View File

@ -4240,4 +4240,27 @@ public class ArrayUtil {
Collections.addAll(set, array); Collections.addAll(set, array);
return toArray(set, (Class<T>)getComponentType(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;
}
} }

View File

@ -289,4 +289,12 @@ public class ArrayUtilTest {
final int[] ints = ArrayUtil.addAll(new int[]{1, 2, 3}, new int[]{4, 5, 6}); 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); 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));
}
} }