Skip to content

Commit 440f3ce

Browse files
authored
style: include MAC_MANUAL_ARRAY_COPY (#5199)
1 parent 493942e commit 440f3ce

File tree

5 files changed

+5
-17
lines changed

5 files changed

+5
-17
lines changed

spotbugs-exclude.xml

-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@
138138
<Match>
139139
<Bug pattern="USBR_UNNECESSARY_STORE_BEFORE_RETURN" />
140140
</Match>
141-
<Match>
142-
<Bug pattern="MAC_MANUAL_ARRAY_COPY" />
143-
</Match>
144141
<Match>
145142
<Bug pattern="SPP_USE_ISEMPTY" />
146143
</Match>

src/main/java/com/thealgorithms/others/BFPRT.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public static int getMinKthByBFPRT(int[] arr, int k) {
3434

3535
public static int[] copyArray(int[] arr) {
3636
int[] copyArr = new int[arr.length];
37-
for (int i = 0; i < arr.length; i++) {
38-
copyArr[i] = arr[i];
39-
}
37+
System.arraycopy(arr, 0, copyArr, 0, arr.length);
4038
return copyArr;
4139
}
4240

src/main/java/com/thealgorithms/others/BankersAlgorithm.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ static boolean checkSafeSystem(int[] processes, int[] availableArray, int[][] ma
6060
int[] safeSequenceArray = new int[totalProcess];
6161

6262
int[] workArray = new int[totalResources];
63-
64-
for (int i = 0; i < totalResources; i++) {
65-
workArray[i] = availableArray[i];
66-
}
63+
System.arraycopy(availableArray, 0, workArray, 0, totalResources);
6764

6865
int count = 0;
6966

src/main/java/com/thealgorithms/others/ReturnSubsequence.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ private static String[] returnSubsequence(String givenString) {
3434
// position=1
3535

3636
String[] ans = new String[2 * smallAns.length]; // Our answer will be an array off string of size=2*smallAns
37-
int i = 0;
38-
for (; i < smallAns.length; i++) {
39-
ans[i] = smallAns[i]; // Copying all the strings present in smallAns to ans string array
40-
}
37+
System.arraycopy(smallAns, 0, ans, 0, smallAns.length);
38+
4139
for (int k = 0; k < smallAns.length; k++) {
4240
ans[k + smallAns.length] = givenString.charAt(0) + smallAns[k]; // Insert character at index=0 of the given
4341
// substring in front of every string

src/main/java/com/thealgorithms/sorts/RadixSort.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ private static void countSort(int[] arr, int n, int exp) {
3535
count[(arr[i] / exp) % 10]--;
3636
}
3737

38-
for (i = 0; i < n; i++) {
39-
arr[i] = output[i];
40-
}
38+
System.arraycopy(output, 0, arr, 0, n);
4139
}
4240

4341
private static void radixsort(int[] arr, int n) {

0 commit comments

Comments
 (0)