style: include OCP_OVERLY_CONCRETE_PARAMETER (#5833)

This commit is contained in:
Piotr Idzik
2024-10-14 22:46:28 +02:00
committed by GitHub
parent 3af4cfd7c8
commit 8886e0996a
28 changed files with 46 additions and 33 deletions

View File

@ -87,9 +87,6 @@
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
</Match>
<!-- fb-contrib -->
<Match>
<Bug pattern="OCP_OVERLY_CONCRETE_PARAMETER" />
</Match>
<Match>
<Bug pattern="LSC_LITERAL_STRING_COMPARISON" />
</Match>

View File

@ -1,6 +1,7 @@
package com.thealgorithms.backtracking;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -95,7 +96,7 @@ public final class CrosswordSolver {
* @param words The list of words to be placed.
* @return true if the crossword is solved, false otherwise.
*/
public static boolean solveCrossword(char[][] puzzle, List<String> words) {
public static boolean solveCrossword(char[][] puzzle, Collection<String> words) {
// Create a mutable copy of the words list
List<String> remainingWords = new ArrayList<>(words);

View File

@ -94,7 +94,7 @@ public final class AStar {
}
// Initializes the graph with edges defined in the input data
static void initializeGraph(Graph graph, ArrayList<Integer> data) {
static void initializeGraph(Graph graph, List<Integer> data) {
for (int i = 0; i < data.size(); i += 4) {
graph.addEdge(new Edge(data.get(i), data.get(i + 1), data.get(i + 2)));
}

View File

@ -30,7 +30,7 @@ public final class EdmondsBlossomAlgorithm {
* @param vertexCount The number of vertices in the graph.
* @return A list of matched pairs of vertices.
*/
public static List<int[]> maximumMatching(List<int[]> edges, int vertexCount) {
public static List<int[]> maximumMatching(Iterable<int[]> edges, int vertexCount) {
List<List<Integer>> graph = new ArrayList<>(vertexCount);
// Initialize each vertex's adjacency list.

View File

@ -1,6 +1,7 @@
package com.thealgorithms.datastructures.lists;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -38,7 +39,7 @@ public final class MergeSortedArrayList {
* @param listB the second list to merge
* @param listC the result list after merging
*/
public static void merge(List<Integer> listA, List<Integer> listB, List<Integer> listC) {
public static void merge(List<Integer> listA, List<Integer> listB, Collection<Integer> listC) {
int pa = 0;
/* the index of listA */
int pb = 0;

View File

@ -1,6 +1,7 @@
package com.thealgorithms.geometry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
@ -89,7 +90,7 @@ public final class ConvexHull {
return result;
}
private static void constructHull(List<Point> points, Point left, Point right, Set<Point> convexSet) {
private static void constructHull(Collection<Point> points, Point left, Point right, Set<Point> convexSet) {
if (!points.isEmpty()) {
Point extremePoint = null;
int extremePointDistance = Integer.MIN_VALUE;

View File

@ -1,6 +1,7 @@
package com.thealgorithms.maths;
import java.util.ArrayList;
import java.util.Collection;
/**
* Class for circular convolution of two discrete signals using the convolution
@ -19,7 +20,7 @@ public final class CircularConvolutionFFT {
* @param x The signal to be padded.
* @param newSize The new size of the signal.
*/
private static void padding(ArrayList<FFT.Complex> x, int newSize) {
private static void padding(Collection<FFT.Complex> x, int newSize) {
if (x.size() < newSize) {
int diff = newSize - x.size();
for (int i = 0; i < diff; i++) {

View File

@ -1,6 +1,7 @@
package com.thealgorithms.maths;
import java.util.ArrayList;
import java.util.Collection;
/**
* Class for linear convolution of two discrete signals using the convolution
@ -19,7 +20,7 @@ public final class ConvolutionFFT {
* @param x The signal to be padded.
* @param newSize The new size of the signal.
*/
private static void padding(ArrayList<FFT.Complex> x, int newSize) {
private static void padding(Collection<FFT.Complex> x, int newSize) {
if (x.size() < newSize) {
int diff = newSize - x.size();
for (int i = 0; i < diff; i++) {

View File

@ -1,6 +1,7 @@
package com.thealgorithms.maths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
@ -274,7 +275,7 @@ public final class FFT {
*
* @param x The ArrayList to be padded.
*/
private static void paddingPowerOfTwo(ArrayList<Complex> x) {
private static void paddingPowerOfTwo(Collection<Complex> x) {
int n = 1;
int oldSize = x.size();
while (n < oldSize) {

View File

@ -1,6 +1,7 @@
package com.thealgorithms.maths;
import java.util.ArrayList;
import java.util.List;
/**
* Class for calculating the Fast Fourier Transform (FFT) of a discrete signal
@ -25,7 +26,7 @@ public final class FFTBluestein {
* IFFT of signal x.
* @param inverse True if you want to find the inverse FFT.
*/
public static void fftBluestein(ArrayList<FFT.Complex> x, boolean inverse) {
public static void fftBluestein(List<FFT.Complex> x, boolean inverse) {
int n = x.size();
int bnSize = 2 * n - 1;
int direction = inverse ? -1 : 1;

View File

@ -1,12 +1,13 @@
package com.thealgorithms.maths;
import java.util.ArrayList;
import java.util.List;
public final class Gaussian {
private Gaussian() {
}
public static ArrayList<Double> gaussian(int matSize, ArrayList<Double> matrix) {
public static ArrayList<Double> gaussian(int matSize, List<Double> matrix) {
int i;
int j = 0;

View File

@ -2,6 +2,7 @@ package com.thealgorithms.maths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import org.apache.commons.lang3.tuple.MutablePair;
/**
@ -64,7 +65,7 @@ public class NthUglyNumber {
}
}
private long computeCandidate(final MutablePair<Integer, Integer> entry) {
private long computeCandidate(final Map.Entry<Integer, Integer> entry) {
return entry.getKey() * uglyNumbers.get(entry.getValue());
}

View File

@ -13,7 +13,7 @@ public final class MedianOfMatrix {
private MedianOfMatrix() {
}
public static int median(List<List<Integer>> matrix) {
public static int median(Iterable<List<Integer>> matrix) {
// Flatten the matrix into a 1D list
List<Integer> linear = new ArrayList<>();
for (List<Integer> row : matrix) {

View File

@ -1,6 +1,5 @@
package com.thealgorithms.misc;
import com.thealgorithms.datastructures.lists.SinglyLinkedList;
import java.util.Stack;
/**
@ -15,8 +14,8 @@ public final class PalindromeSinglyLinkedList {
private PalindromeSinglyLinkedList() {
}
public static boolean isPalindrome(final SinglyLinkedList linkedList) {
Stack<Integer> linkedListValues = new Stack<>();
public static boolean isPalindrome(final Iterable linkedList) {
var linkedListValues = new Stack<>();
for (final var x : linkedList) {
linkedListValues.push(x);

View File

@ -7,6 +7,7 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
/**
@ -125,7 +126,7 @@ public final class KochSnowflake {
* applied.
* @return The transformed vectors after the iteration-step.
*/
private static ArrayList<Vector2> iterationStep(ArrayList<Vector2> vectors) {
private static ArrayList<Vector2> iterationStep(List<Vector2> vectors) {
ArrayList<Vector2> newVectors = new ArrayList<Vector2>();
for (int i = 0; i < vectors.size() - 1; i++) {
Vector2 startVector = vectors.get(i);

View File

@ -2,6 +2,7 @@ package com.thealgorithms.scheduling;
import com.thealgorithms.devutils.entities.ProcessDetails;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
@ -15,7 +16,7 @@ public class PreemptivePriorityScheduling {
protected final List<ProcessDetails> processes;
protected final List<String> ganttChart;
public PreemptivePriorityScheduling(List<ProcessDetails> processes) {
public PreemptivePriorityScheduling(Collection<ProcessDetails> processes) {
this.processes = new ArrayList<>(processes);
this.ganttChart = new ArrayList<>();
}

View File

@ -2,6 +2,7 @@ package com.thealgorithms.scheduling;
import com.thealgorithms.devutils.entities.ProcessDetails;
import java.util.ArrayList;
import java.util.List;
/**
* Implementation of Shortest Job First Algorithm: The algorithm allows the waiting process with the
@ -87,7 +88,7 @@ public class SJFScheduling {
* @return returns the process' with the shortest burst time OR NULL if there are no ready
* processes
*/
private ProcessDetails findShortestJob(ArrayList<ProcessDetails> readyProcesses) {
private ProcessDetails findShortestJob(List<ProcessDetails> readyProcesses) {
if (readyProcesses.isEmpty()) {
return null;
}

View File

@ -1,6 +1,7 @@
package com.thealgorithms.scheduling.diskscheduling;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -24,7 +25,7 @@ public class SSFScheduling {
this.currentPosition = currentPosition;
}
public List<Integer> execute(List<Integer> requests) {
public List<Integer> execute(Collection<Integer> requests) {
List<Integer> result = new ArrayList<>(requests);
List<Integer> orderedRequests = new ArrayList<>();

View File

@ -79,7 +79,7 @@ public class BucketSort implements SortAlgorithm {
* @param <T> the type of elements in the array
* @return the sorted array
*/
private <T extends Comparable<T>> T[] concatenateBuckets(List<List<T>> buckets, T[] array) {
private <T extends Comparable<T>> T[] concatenateBuckets(Iterable<List<T>> buckets, T[] array) {
int index = 0;
for (List<T> bucket : buckets) {
Collections.sort(bucket);

View File

@ -72,7 +72,7 @@ public class PatienceSort implements SortAlgorithm {
* @param <T> the type of elements in the piles, must be comparable
* @return a priority queue containing the top element of each pile
*/
private static <T extends Comparable<T>> PriorityQueue<PileNode<T>> mergePiles(final List<List<T>> piles) {
private static <T extends Comparable<T>> PriorityQueue<PileNode<T>> mergePiles(final Iterable<List<T>> piles) {
PriorityQueue<PileNode<T>> pq = new PriorityQueue<>();
for (List<T> pile : piles) {
pq.add(new PileNode<>(pile.removeLast(), pile));

View File

@ -78,7 +78,7 @@ public final class PigeonholeSort {
* @param array the array to be sorted
* @param pigeonHoles the populated pigeonholes
*/
private static void collectFromPigeonHoles(int[] array, List<List<Integer>> pigeonHoles) {
private static void collectFromPigeonHoles(int[] array, Iterable<List<Integer>> pigeonHoles) {
int index = 0;
for (final var pigeonHole : pigeonHoles) {
for (final int element : pigeonHole) {

View File

@ -51,7 +51,7 @@ public class TreeSort implements SortAlgorithm {
return unsortedArray;
}
private <T extends Comparable<T>> List<T> doTreeSortList(List<T> unsortedList) {
private <T extends Comparable<T>> List<T> doTreeSortList(Iterable<T> unsortedList) {
// create a generic BST tree
BSTRecursiveGeneric<T> tree = new BSTRecursiveGeneric<T>();

View File

@ -1,8 +1,8 @@
package com.thealgorithms.strings;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
@ -22,7 +22,7 @@ public final class WordLadder {
* @param wordList a list of words that can be used in the transformation sequence
* @return the number of words in the shortest transformation sequence, or 0 if no such sequence exists
*/
public static int ladderLength(String beginWord, String endWord, List<String> wordList) {
public static int ladderLength(String beginWord, String endWord, Collection<String> wordList) {
Set<String> wordSet = new HashSet<>(wordList);
if (!wordSet.contains(endWord)) {

View File

@ -183,7 +183,7 @@ public class BoruvkaAlgorithmTest {
* @param result list of edges in the Minimum Spanning Tree
* @return the total weight of the Minimum Spanning Tree
*/
int computeTotalWeight(final List<BoruvkaAlgorithm.Edge> result) {
int computeTotalWeight(final Iterable<BoruvkaAlgorithm.Edge> result) {
int totalWeight = 0;
for (final var edge : result) {
totalWeight += edge.weight;

View File

@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
@ -25,7 +26,7 @@ public class EdmondsBlossomAlgorithmTest {
* @param matching List of matched pairs returned by the algorithm.
* @return A sorted 2D array of matching pairs.
*/
private int[][] convertMatchingToArray(List<int[]> matching) {
private int[][] convertMatchingToArray(Collection<int[]> matching) {
// Convert the list of pairs into an array
int[][] result = matching.toArray(new int[0][]);

View File

@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
@ -44,7 +45,7 @@ class WordBoggleTest {
@ParameterizedTest
@MethodSource("provideSpecialCases")
void testBoggleBoardSpecialCases(char[][] specialBoard, String[] words, List<String> expectedWords, String testDescription) {
void testBoggleBoardSpecialCases(char[][] specialBoard, String[] words, Collection<String> expectedWords, String testDescription) {
List<String> result = WordBoggle.boggleBoard(specialBoard, words);
assertEquals(expectedWords.size(), result.size(), "Test failed for: " + testDescription);
assertTrue(expectedWords.containsAll(result), "Test failed for: " + testDescription);

View File

@ -3,6 +3,7 @@ package com.thealgorithms.scheduling;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.thealgorithms.devutils.entities.ProcessDetails;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
@ -17,7 +18,7 @@ import org.junit.jupiter.params.provider.MethodSource;
class PreemptivePrioritySchedulingTest {
@ParameterizedTest
@MethodSource("provideProcessesAndExpectedSchedules")
void testPreemptivePriorityScheduling(List<ProcessDetails> processes, List<String> expectedSchedule) {
void testPreemptivePriorityScheduling(Collection<ProcessDetails> processes, List<String> expectedSchedule) {
PreemptivePriorityScheduling scheduler = new PreemptivePriorityScheduling(processes);
scheduler.scheduleProcesses();
assertEquals(expectedSchedule, scheduler.ganttChart);

View File

@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@ -225,7 +226,7 @@ class QuickSelectTest {
return RANDOM.ints(n, ASCII_A, ASCII_Z).mapToObj(i -> (char) i).collect(Collectors.toList());
}
private static <T extends Comparable<T>> List<T> getSortedCopyOfList(List<T> list) {
private static <T extends Comparable<T>> List<T> getSortedCopyOfList(Collection<T> list) {
return list.stream().sorted().collect(Collectors.toList());
}
}