This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push: new 9d5ad9442 Add fill method for boolean arrays in ArrayFill utility class (#1386) 9d5ad9442 is described below commit 9d5ad944277b0e6f4003953fc33710cae9d95d0b Author: kommalapatiraviteja <1ra4...@gmail.com> AuthorDate: Mon May 19 12:03:35 2025 -0700 Add fill method for boolean arrays in ArrayFill utility class (#1386) - Completes the fill methods for all primitive array types Co-authored-by: Raviteja Kommalapati <1ra4...@gmail.com@example.com> --- src/main/java/org/apache/commons/lang3/ArrayFill.java | 15 +++++++++++++++ .../java/org/apache/commons/lang3/ArrayFillTest.java | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/main/java/org/apache/commons/lang3/ArrayFill.java b/src/main/java/org/apache/commons/lang3/ArrayFill.java index cf2a58b33..17ca5a770 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayFill.java +++ b/src/main/java/org/apache/commons/lang3/ArrayFill.java @@ -44,6 +44,21 @@ public static byte[] fill(final byte[] a, final byte val) { return a; } + /** + * Fills and returns the given array, assigning the given {@code boolean} value to each element of the array. + * + * @param a the array to be filled (may be null). + * @param val the value to be stored in all elements of the array. + * @return the given array. + * @see Arrays#fill(boolean[],boolean) + */ + public static boolean[] fill(final boolean[] a, final boolean val) { + if (a != null) { + Arrays.fill(a, val); + } + return a; + } + /** * Fills and returns the given array, assigning the given {@code char} value to each element of the array. * diff --git a/src/test/java/org/apache/commons/lang3/ArrayFillTest.java b/src/test/java/org/apache/commons/lang3/ArrayFillTest.java index c1deb4384..550ca7c24 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayFillTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayFillTest.java @@ -49,6 +49,25 @@ public void testFillByteArrayNull() { assertSame(array, actual); } + @Test + public void testFillBooleanArray() { + final boolean[] array = new boolean[3]; + final boolean val = true; + final boolean[] actual = ArrayFill.fill(array, val); + assertSame(array, actual); + for (final boolean v : actual) { + assertEquals(val, v); + } + } + + @Test + public void testFillBooleanArrayNull() { + final boolean[] array = null; + final boolean val = true; + final boolean[] actual = ArrayFill.fill(array, val); + assertSame(array, actual); + } + @Test public void testFillCharArray() { final char[] array = new char[3];