@@ -158,10 +158,11 @@ public static <T> void fill(@NotNull T[] array, @NotNull IntFunction<T> factory)
158158 /**
159159 * Fill the array using the factory.
160160 *
161+ * @param <T> the element's type.
162+ * @param <F> the argument's type.
161163 * @param array the array.
162164 * @param argument the additional argument.
163165 * @param factory the element's factory.
164- * @param <T> the element's type.
165166 */
166167 public static <T , F > void fill (@ NotNull T [] array , @ Nullable F argument , @ NotNull Function <F , T > factory ) {
167168 for (int i = 0 ; i < array .length ; i ++) {
@@ -485,12 +486,14 @@ public static void copyTo(@NotNull final int[] source, final int[] target, final
485486 * @param object the object.
486487 * @return the object's index or -1.
487488 */
488- public static int indexOf (@ NotNull final Object [] array , @ Nullable final Object object ) {
489+ public static int indexOf (@ NotNull Object [] array , @ Nullable Object object ) {
489490
490491 int index = 0 ;
491492
492- for (final Object element : array ) {
493- if (Objects .equals (element , object )) return index ;
493+ for (var element : array ) {
494+ if (Objects .equals (element , object )) {
495+ return index ;
496+ }
494497 index ++;
495498 }
496499
@@ -575,6 +578,7 @@ public static <T> void sort(@NotNull final T[] array, final int fromIndex, final
575578 /**
576579 * Convert the array to a string presentation.
577580 *
581+ * @param <T> the element's type.
578582 * @param array the array.
579583 * @param toString the to string function.
580584 * @return the string presentation.
@@ -585,11 +589,11 @@ public static <T> void sort(@NotNull final T[] array, final int fromIndex, final
585589 return "[]" ;
586590 }
587591
588- String className = array .array ()
592+ var className = array .array ()
589593 .getClass ()
590594 .getSimpleName ();
591595
592- StringBuilder builder = new StringBuilder (className .substring (0 , className .length () - 1 ));
596+ var builder = new StringBuilder (className .substring (0 , className .length () - 1 ));
593597
594598 for (int i = 0 , length = array .size () - 1 ; i <= length ; i ++) {
595599
@@ -1885,6 +1889,61 @@ public static boolean isEmpty(@Nullable double[] array) {
18851889 return array == null || array .length == 0 ;
18861890 }
18871891
1892+ /**
1893+ * Convert T array to R array if a source array is not null.
1894+ *
1895+ * @param <T> the source component type.
1896+ * @param <M> the mapped element's type.
1897+ * @param <R> the result element's type.
1898+ * @param source the source array.
1899+ * @param mapper the mapper.
1900+ * @param resultType the result component type.
1901+ * @return the mapped array or null.
1902+ * @since 9.3.0
1903+ */
1904+ public static <T , R , M extends R > R @ Nullable [] mapNullable (
1905+ T @ Nullable [] source ,
1906+ @ NotNull Function <@ NotNull T , @ NotNull M > mapper ,
1907+ @ NotNull Class <R > resultType
1908+ ) {
1909+
1910+ if (source == null ) {
1911+ return null ;
1912+ } else if (source .length == 0 ) {
1913+ return create (resultType , 0 );
1914+ }
1915+
1916+ R [] resultArray = create (resultType , source .length );
1917+
1918+ for (int i = 0 ; i < source .length ; i ++) {
1919+ resultArray [i ] = mapper .apply (source [i ]);
1920+ }
1921+
1922+ return resultArray ;
1923+ }
1924+
1925+ /**
1926+ * Convert long array to int array.
1927+ *
1928+ * @param source the source array.
1929+ * @return the int array.
1930+ * @since 9.3.0
1931+ */
1932+ public static int @ NotNull [] longsToInts (long @ NotNull [] source ) {
1933+
1934+ if (source .length == 0 ) {
1935+ return ArrayUtils .EMPTY_INT_ARRAY ;
1936+ }
1937+
1938+ int [] resultArray = new int [source .length ];
1939+
1940+ for (int i = 0 ; i < source .length ; i ++) {
1941+ resultArray [i ] = (int ) source [i ];
1942+ }
1943+
1944+ return resultArray ;
1945+ }
1946+
18881947 private ArrayUtils () {
18891948 throw new RuntimeException ();
18901949 }
0 commit comments