This commit is contained in:
Looly 2024-07-05 09:48:45 +08:00
parent 8f62647519
commit c054d025dd
2 changed files with 15 additions and 1 deletions

View File

@ -1832,7 +1832,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
* 按照指定规则将一种类型的数组转换为另一种类型
*
* @param array 被转换的数组
* @param targetComponentType 目标的元素类型
* @param targetComponentType 目标的元素类型只能为包装类型
* @param func 转换规则函数
* @param <R> 目标数组类型
* @return 转换后的数组

View File

@ -1011,4 +1011,18 @@ public class ArrayUtilTest {
final String[] a = {" ", " ", ""};
Assertions.assertTrue(ArrayUtil.isAllBlank(a));
}
@Test
void firstMatchShouldReturnFirstMatch() {
final Integer[] array = {5, 10, 15, 20, 25};
final Integer result = ArrayUtil.firstMatch(value -> value > 15, array);
assertEquals(20, result);
}
@Test
void testMatchIndexWithMatchingFirstElement() {
final Integer[] array = {1, 2, 3, 4, 5};
final int index = ArrayUtil.matchIndex(value -> value == 3, array);
assertEquals(2, index);
}
}