You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/05/19 19:06:57 UTC

(commons-lang) branch master updated: Add ArrayFill.fill(boolean[], boolean) #1386

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 f431d2eeb Add ArrayFill.fill(boolean[], boolean) #1386
f431d2eeb is described below

commit f431d2eeb71c1e0cf910cdd4d930153e656379c3
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Mon May 19 15:06:52 2025 -0400

    Add ArrayFill.fill(boolean[], boolean) #1386
    
    - Add missing Javadoc since tag
    - Sort members
---
 src/changes/changes.xml                            |  1 +
 .../java/org/apache/commons/lang3/ArrayFill.java   | 13 +++--
 .../org/apache/commons/lang3/ArrayFillTest.java    | 66 +++++++++++-----------
 3 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cfea2f8d2..5949facbd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -121,6 +121,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add SystemProperties.JAVA_SECURITY_KERBEROS_CONF.</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add SystemProperties.JAVA_SECURITY_KERBEROS_KDC.</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add SystemProperties.JAVA_SECURITY_KERBEROS_REAL.</action>
+    <action                   type="add" dev="ggregory" due-to="kommalapatiraviteja">Add ArrayFill.fill(boolean[], boolean) #1386.</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 73 to 83 #1267, #1277, #1283, #1288, #1302, #1377.</action>
     <action                   type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">[site] Bump org.codehaus.mojo:taglist-maven-plugin from 3.1.0 to 3.2.1 #1300.</action>
diff --git a/src/main/java/org/apache/commons/lang3/ArrayFill.java b/src/main/java/org/apache/commons/lang3/ArrayFill.java
index 17ca5a770..5bcf5cbdf 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayFill.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayFill.java
@@ -30,14 +30,15 @@
 public final class ArrayFill {
 
     /**
-     * Fills and returns the given array, assigning the given {@code byte} value to each element of the array.
+     * 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(byte[],byte)
+     * @see Arrays#fill(boolean[],boolean)
+     * @since 3.18.0
      */
-    public static byte[] fill(final byte[] a, final byte val) {
+    public static boolean[] fill(final boolean[] a, final boolean val) {
         if (a != null) {
             Arrays.fill(a, val);
         }
@@ -45,14 +46,14 @@ public static byte[] fill(final byte[] a, final byte val) {
     }
 
     /**
-     * Fills and returns the given array, assigning the given {@code boolean} value to each element of the array.
+     * Fills and returns the given array, assigning the given {@code byte} 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)
+     * @see Arrays#fill(byte[],byte)
      */
-    public static boolean[] fill(final boolean[] a, final boolean val) {
+    public static byte[] fill(final byte[] a, final byte val) {
         if (a != null) {
             Arrays.fill(a, val);
         }
diff --git a/src/test/java/org/apache/commons/lang3/ArrayFillTest.java b/src/test/java/org/apache/commons/lang3/ArrayFillTest.java
index 550ca7c24..d12526d18 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayFillTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayFillTest.java
@@ -31,40 +31,40 @@
 public class ArrayFillTest extends AbstractLangTest {
 
     @Test
-    public void testFillByteArray() {
-        final byte[] array = new byte[3];
-        final byte val = (byte) 1;
-        final byte[] actual = ArrayFill.fill(array, val);
+    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 byte v : actual) {
+        for (final boolean v : actual) {
             assertEquals(val, v);
         }
     }
 
     @Test
-    public void testFillByteArrayNull() {
-        final byte[] array = null;
-        final byte val = (byte) 1;
-        final byte[] actual = ArrayFill.fill(array, val);
+    public void testFillBooleanArrayNull() {
+        final boolean[] array = null;
+        final boolean val = true;
+        final boolean[] actual = ArrayFill.fill(array, val);
         assertSame(array, actual);
     }
 
     @Test
-    public void testFillBooleanArray() {
-        final boolean[] array = new boolean[3];
-        final boolean val = true;
-        final boolean[] actual = ArrayFill.fill(array, val);
+    public void testFillByteArray() {
+        final byte[] array = new byte[3];
+        final byte val = (byte) 1;
+        final byte[] actual = ArrayFill.fill(array, val);
         assertSame(array, actual);
-        for (final boolean v : actual) {
+        for (final byte v : actual) {
             assertEquals(val, v);
         }
     }
 
     @Test
-    public void testFillBooleanArrayNull() {
-        final boolean[] array = null;
-        final boolean val = true;
-        final boolean[] actual = ArrayFill.fill(array, val);
+    public void testFillByteArrayNull() {
+        final byte[] array = null;
+        final byte val = (byte) 1;
+        final byte[] actual = ArrayFill.fill(array, val);
         assertSame(array, actual);
     }
 
@@ -125,6 +125,21 @@ public void testFillFloatArrayNull() {
         assertSame(array, actual);
     }
 
+    @Test
+    public void testFillFunction() throws Exception {
+        final FailableIntFunction<?, Exception> nullIntFunction = null;
+        assertNull(ArrayFill.fill(null, nullIntFunction));
+        assertArrayEquals(null, ArrayFill.fill(null, nullIntFunction));
+        assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayFill.fill(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, nullIntFunction));
+        assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, ArrayFill.fill(ArrayUtils.EMPTY_OBJECT_ARRAY, nullIntFunction));
+        final Integer[] array = new Integer[10];
+        final Integer[] array2 = ArrayFill.fill(array, Integer::valueOf);
+        assertSame(array, array2);
+        for (int i = 0; i < array.length; i++) {
+            assertEquals(i, array[i].intValue());
+        }
+    }
+
     @Test
     public void testFillIntArray() {
         final int[] array = new int[3];
@@ -200,19 +215,4 @@ public void testFillShortArrayNull() {
         final short[] actual = ArrayFill.fill(array, val);
         assertSame(array, actual);
     }
-
-    @Test
-    public void testFillFunction() throws Exception {
-        final FailableIntFunction<?, Exception> nullIntFunction = null;
-        assertNull(ArrayFill.fill(null, nullIntFunction));
-        assertArrayEquals(null, ArrayFill.fill(null, nullIntFunction));
-        assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayFill.fill(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, nullIntFunction));
-        assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, ArrayFill.fill(ArrayUtils.EMPTY_OBJECT_ARRAY, nullIntFunction));
-        final Integer[] array = new Integer[10];
-        final Integer[] array2 = ArrayFill.fill(array, Integer::valueOf);
-        assertSame(array, array2);
-        for (int i = 0; i < array.length; i++) {
-            assertEquals(i, array[i].intValue());
-        }
-    }
 }