Skip to content

Commit f431d2e

Browse files
committed
Add ArrayFill.fill(boolean[], boolean) #1386
- Add missing Javadoc since tag - Sort members
1 parent 9d5ad94 commit f431d2e

File tree

3 files changed

+41
-39
lines changed

3 files changed

+41
-39
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ The <action> type attribute can be add,update,fix,remove.
121121
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemProperties.JAVA_SECURITY_KERBEROS_CONF.</action>
122122
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemProperties.JAVA_SECURITY_KERBEROS_KDC.</action>
123123
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemProperties.JAVA_SECURITY_KERBEROS_REAL.</action>
124+
<action type="add" dev="ggregory" due-to="kommalapatiraviteja">Add ArrayFill.fill(boolean[], boolean) #1386.</action>
124125
<!-- UPDATE -->
125126
<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>
126127
<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>

src/main/java/org/apache/commons/lang3/ArrayFill.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,30 @@
3030
public final class ArrayFill {
3131

3232
/**
33-
* Fills and returns the given array, assigning the given {@code byte} value to each element of the array.
33+
* Fills and returns the given array, assigning the given {@code boolean} value to each element of the array.
3434
*
3535
* @param a the array to be filled (may be null).
3636
* @param val the value to be stored in all elements of the array.
3737
* @return the given array.
38-
* @see Arrays#fill(byte[],byte)
38+
* @see Arrays#fill(boolean[],boolean)
39+
* @since 3.18.0
3940
*/
40-
public static byte[] fill(final byte[] a, final byte val) {
41+
public static boolean[] fill(final boolean[] a, final boolean val) {
4142
if (a != null) {
4243
Arrays.fill(a, val);
4344
}
4445
return a;
4546
}
4647

4748
/**
48-
* Fills and returns the given array, assigning the given {@code boolean} value to each element of the array.
49+
* Fills and returns the given array, assigning the given {@code byte} value to each element of the array.
4950
*
5051
* @param a the array to be filled (may be null).
5152
* @param val the value to be stored in all elements of the array.
5253
* @return the given array.
53-
* @see Arrays#fill(boolean[],boolean)
54+
* @see Arrays#fill(byte[],byte)
5455
*/
55-
public static boolean[] fill(final boolean[] a, final boolean val) {
56+
public static byte[] fill(final byte[] a, final byte val) {
5657
if (a != null) {
5758
Arrays.fill(a, val);
5859
}

src/test/java/org/apache/commons/lang3/ArrayFillTest.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,40 @@
3131
public class ArrayFillTest extends AbstractLangTest {
3232

3333
@Test
34-
public void testFillByteArray() {
35-
final byte[] array = new byte[3];
36-
final byte val = (byte) 1;
37-
final byte[] actual = ArrayFill.fill(array, val);
34+
public void testFillBooleanArray() {
35+
final boolean[] array = new boolean[3];
36+
final boolean val = true;
37+
final boolean[] actual = ArrayFill.fill(array, val);
3838
assertSame(array, actual);
39-
for (final byte v : actual) {
39+
for (final boolean v : actual) {
4040
assertEquals(val, v);
4141
}
4242
}
4343

4444
@Test
45-
public void testFillByteArrayNull() {
46-
final byte[] array = null;
47-
final byte val = (byte) 1;
48-
final byte[] actual = ArrayFill.fill(array, val);
45+
public void testFillBooleanArrayNull() {
46+
final boolean[] array = null;
47+
final boolean val = true;
48+
final boolean[] actual = ArrayFill.fill(array, val);
4949
assertSame(array, actual);
5050
}
5151

5252
@Test
53-
public void testFillBooleanArray() {
54-
final boolean[] array = new boolean[3];
55-
final boolean val = true;
56-
final boolean[] actual = ArrayFill.fill(array, val);
53+
public void testFillByteArray() {
54+
final byte[] array = new byte[3];
55+
final byte val = (byte) 1;
56+
final byte[] actual = ArrayFill.fill(array, val);
5757
assertSame(array, actual);
58-
for (final boolean v : actual) {
58+
for (final byte v : actual) {
5959
assertEquals(val, v);
6060
}
6161
}
6262

6363
@Test
64-
public void testFillBooleanArrayNull() {
65-
final boolean[] array = null;
66-
final boolean val = true;
67-
final boolean[] actual = ArrayFill.fill(array, val);
64+
public void testFillByteArrayNull() {
65+
final byte[] array = null;
66+
final byte val = (byte) 1;
67+
final byte[] actual = ArrayFill.fill(array, val);
6868
assertSame(array, actual);
6969
}
7070

@@ -125,6 +125,21 @@ public void testFillFloatArrayNull() {
125125
assertSame(array, actual);
126126
}
127127

128+
@Test
129+
public void testFillFunction() throws Exception {
130+
final FailableIntFunction<?, Exception> nullIntFunction = null;
131+
assertNull(ArrayFill.fill(null, nullIntFunction));
132+
assertArrayEquals(null, ArrayFill.fill(null, nullIntFunction));
133+
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayFill.fill(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, nullIntFunction));
134+
assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, ArrayFill.fill(ArrayUtils.EMPTY_OBJECT_ARRAY, nullIntFunction));
135+
final Integer[] array = new Integer[10];
136+
final Integer[] array2 = ArrayFill.fill(array, Integer::valueOf);
137+
assertSame(array, array2);
138+
for (int i = 0; i < array.length; i++) {
139+
assertEquals(i, array[i].intValue());
140+
}
141+
}
142+
128143
@Test
129144
public void testFillIntArray() {
130145
final int[] array = new int[3];
@@ -200,19 +215,4 @@ public void testFillShortArrayNull() {
200215
final short[] actual = ArrayFill.fill(array, val);
201216
assertSame(array, actual);
202217
}
203-
204-
@Test
205-
public void testFillFunction() throws Exception {
206-
final FailableIntFunction<?, Exception> nullIntFunction = null;
207-
assertNull(ArrayFill.fill(null, nullIntFunction));
208-
assertArrayEquals(null, ArrayFill.fill(null, nullIntFunction));
209-
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayFill.fill(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, nullIntFunction));
210-
assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, ArrayFill.fill(ArrayUtils.EMPTY_OBJECT_ARRAY, nullIntFunction));
211-
final Integer[] array = new Integer[10];
212-
final Integer[] array2 = ArrayFill.fill(array, Integer::valueOf);
213-
assertSame(array, array2);
214-
for (int i = 0; i < array.length; i++) {
215-
assertEquals(i, array[i].intValue());
216-
}
217-
}
218218
}

0 commit comments

Comments
 (0)