Skip to content

Commit c42b1c9

Browse files
authored
style: enable ParameterName in CheckStyle. (#5196)
* Enabled: ParameterName in CheckStyle. * Refactored to fix bug caused by selfAssignment of variables in VectorCrossproduct class
1 parent 2568b96 commit c42b1c9

23 files changed

+139
-139
lines changed

checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<module name="MemberName"/>
115115
<module name="MethodName"/>
116116
<module name="PackageName"/>
117-
<!-- TODO <module name="ParameterName"/> -->
117+
<module name="ParameterName"/>
118118
<module name="StaticVariableName"/>
119119
<!-- TODO <module name="TypeName"/> -->
120120

src/main/java/com/thealgorithms/backtracking/PowerSum.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ public class PowerSum {
1111
private int count = 0;
1212
private int sum = 0;
1313

14-
public int powSum(int N, int X) {
15-
sum(N, X, 1);
14+
public int powSum(int n, int x) {
15+
sum(n, x, 1);
1616
return count;
1717
}
1818

1919
// here i is the natural number which will be raised by X and added in sum.
20-
public void sum(int N, int X, int i) {
20+
public void sum(int n, int x, int i) {
2121
// if sum is equal to N that is one of our answer and count is increased.
22-
if (sum == N) {
22+
if (sum == n) {
2323
count++;
2424
return;
2525
} // we will be adding next natural number raised to X only if on adding it in sum the
2626
// result is less than N.
27-
else if (sum + power(i, X) <= N) {
28-
sum += power(i, X);
29-
sum(N, X, i + 1);
27+
else if (sum + power(i, x) <= n) {
28+
sum += power(i, x);
29+
sum(n, x, i + 1);
3030
// backtracking and removing the number added last since no possible combination is
3131
// there with it.
32-
sum -= power(i, X);
32+
sum -= power(i, x);
3333
}
34-
if (power(i, X) < N) {
34+
if (power(i, x) < n) {
3535
// calling the sum function with next natural number after backtracking if when it is
3636
// raised to X is still less than X.
37-
sum(N, X, i + 1);
37+
sum(n, x, i + 1);
3838
}
3939
}
4040

src/main/java/com/thealgorithms/conversions/RomanToInteger.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ private RomanToInteger() {
2424
/**
2525
* This function convert Roman number into Integer
2626
*
27-
* @param A Roman number string
27+
* @param a Roman number string
2828
* @return integer
2929
*/
30-
public static int romanToInt(String A) {
31-
A = A.toUpperCase();
30+
public static int romanToInt(String a) {
31+
a = a.toUpperCase();
3232
char prev = ' ';
3333

3434
int sum = 0;
3535

3636
int newPrev = 0;
37-
for (int i = A.length() - 1; i >= 0; i--) {
38-
char c = A.charAt(i);
37+
for (int i = a.length() - 1; i >= 0; i--) {
38+
char c = a.charAt(i);
3939

4040
if (prev != ' ') {
41-
// checking current Number greater then previous or not
41+
// checking current Number greater than previous or not
4242
newPrev = ROMAN_TO_INT.get(prev) > newPrev ? ROMAN_TO_INT.get(prev) : newPrev;
4343
}
4444

4545
int currentNum = ROMAN_TO_INT.get(c);
4646

47-
// if current number greater then prev max previous then add
47+
// if current number greater than prev max previous then add
4848
if (currentNum >= newPrev) {
4949
sum += currentNum;
5050
} else {
51-
// subtract upcoming number until upcoming number not greater then prev max
51+
// subtract upcoming number until upcoming number not greater than prev max
5252
sum -= currentNum;
5353
}
5454

src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGrapfDFS.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public final class BipartiteGrapfDFS {
1818
private BipartiteGrapfDFS() {
1919
}
2020

21-
private static boolean bipartite(int V, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
21+
private static boolean bipartite(int v, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
2222
if (color[node] == -1) {
2323
color[node] = 1;
2424
}
2525
for (Integer it : adj.get(node)) {
2626
if (color[it] == -1) {
2727
color[it] = 1 - color[node];
28-
if (!bipartite(V, adj, color, it)) {
28+
if (!bipartite(v, adj, color, it)) {
2929
return false;
3030
}
3131
} else if (color[it] == color[node]) {
@@ -35,14 +35,14 @@ private static boolean bipartite(int V, ArrayList<ArrayList<Integer>> adj, int[]
3535
return true;
3636
}
3737

38-
public static boolean isBipartite(int V, ArrayList<ArrayList<Integer>> adj) {
38+
public static boolean isBipartite(int v, ArrayList<ArrayList<Integer>> adj) {
3939
// Code here
40-
int[] color = new int[V + 1];
40+
int[] color = new int[v + 1];
4141
Arrays.fill(color, -1);
4242

43-
for (int i = 0; i < V; i++) {
43+
for (int i = 0; i < v; i++) {
4444
if (color[i] == -1) {
45-
if (!bipartite(V, adj, color, i)) {
45+
if (!bipartite(v, adj, color, i)) {
4646
return false;
4747
}
4848
}

src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public FloydWarshall(int numberofvertices) {
1515
this.numberofvertices = numberofvertices;
1616
}
1717

18-
public void floydwarshall(int[][] AdjacencyMatrix) { // calculates all the distances from source to destination vertex
18+
public void floydwarshall(int[][] adjacencyMatrix) { // calculates all the distances from source to destination vertex
1919
for (int source = 1; source <= numberofvertices; source++) {
2020
for (int destination = 1; destination <= numberofvertices; destination++) {
21-
distanceMatrix[source][destination] = AdjacencyMatrix[source][destination];
21+
distanceMatrix[source][destination] = adjacencyMatrix[source][destination];
2222
}
2323
}
2424
for (int intermediate = 1; intermediate <= numberofvertices; intermediate++) {

src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,28 @@ public class TarjansAlgorithm {
6060

6161
private List<List<Integer>> sccList = new ArrayList<List<Integer>>();
6262

63-
public List<List<Integer>> stronglyConnectedComponents(int V, List<List<Integer>> graph) {
63+
public List<List<Integer>> stronglyConnectedComponents(int v, List<List<Integer>> graph) {
6464

6565
// Initially all vertices as unvisited, insertion and low time are undefined
6666

6767
// insertionTime:Time when a node is visited 1st time while DFS traversal
6868

6969
// lowTime: indicates the earliest visited vertex (the vertex with minimum insertion time)
7070
// that can be reached from a subtree rooted with a particular node.
71-
int[] lowTime = new int[V];
72-
int[] insertionTime = new int[V];
73-
for (int i = 0; i < V; i++) {
71+
int[] lowTime = new int[v];
72+
int[] insertionTime = new int[v];
73+
for (int i = 0; i < v; i++) {
7474
insertionTime[i] = -1;
7575
lowTime[i] = -1;
7676
}
7777

7878
// To check if element is present in stack
79-
boolean[] isInStack = new boolean[V];
79+
boolean[] isInStack = new boolean[v];
8080

8181
// Store nodes during DFS
8282
Stack<Integer> st = new Stack<Integer>();
8383

84-
for (int i = 0; i < V; i++) {
84+
for (int i = 0; i < v; i++) {
8585
if (insertionTime[i] == -1) stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
8686
}
8787

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArray.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public GenericHashMapUsingArray() {
1919
// 75, then adding 76th item it will double the size, copy all elements
2020
// & then add 76th item.
2121

22-
private void initBuckets(int N) {
23-
buckets = new LinkedList[N];
22+
private void initBuckets(int n) {
23+
buckets = new LinkedList[n];
2424
for (int i = 0; i < buckets.length; i++) {
2525
buckets[i] = new LinkedList<>();
2626
}

src/main/java/com/thealgorithms/datastructures/lists/Merge_K_SortedLinkedlist.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public class Merge_K_SortedLinkedlist {
1313
* This function merge K sorted LinkedList
1414
*
1515
* @param a array of LinkedList
16-
* @param N size of array
16+
* @param n size of array
1717
* @return node
1818
*/
19-
Node mergeKList(Node[] a, int N) {
19+
Node mergeKList(Node[] a, int n) {
2020
// Min Heap
2121
PriorityQueue<Node> min = new PriorityQueue<>(Comparator.comparingInt(x -> x.data));
2222

2323
// adding head of all linkedList in min heap
24-
min.addAll(Arrays.asList(a).subList(0, N));
24+
min.addAll(Arrays.asList(a).subList(0, n));
2525

2626
// Make new head among smallest heads in K linkedList
2727
Node head = min.poll();

src/main/java/com/thealgorithms/datastructures/trees/SegmentTree.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ public final int constructTree(int[] arr, int start, int end, int index) {
3232

3333
/* A function which will update the value at a index i. This will be called by the
3434
update function internally*/
35-
private void updateTree(int start, int end, int index, int diff, int seg_index) {
35+
private void updateTree(int start, int end, int index, int diff, int segIndex) {
3636
if (index < start || index > end) {
3737
return;
3838
}
3939

40-
this.segTree[seg_index] += diff;
40+
this.segTree[segIndex] += diff;
4141
if (start != end) {
4242
int mid = start + (end - start) / 2;
43-
updateTree(start, mid, index, diff, seg_index * 2 + 1);
44-
updateTree(mid + 1, end, index, diff, seg_index * 2 + 2);
43+
updateTree(start, mid, index, diff, segIndex * 2 + 1);
44+
updateTree(mid + 1, end, index, diff, segIndex * 2 + 2);
4545
}
4646
}
4747

@@ -58,17 +58,17 @@ public void update(int index, int value) {
5858

5959
/* A function to get the sum of the elements from index l to index r. This will be called
6060
* internally*/
61-
private int getSumTree(int start, int end, int q_start, int q_end, int seg_index) {
62-
if (q_start <= start && q_end >= end) {
63-
return this.segTree[seg_index];
61+
private int getSumTree(int start, int end, int qStart, int qEnd, int segIndex) {
62+
if (qStart <= start && qEnd >= end) {
63+
return this.segTree[segIndex];
6464
}
6565

66-
if (q_start > end || q_end < start) {
66+
if (qStart > end || qEnd < start) {
6767
return 0;
6868
}
6969

7070
int mid = start + (end - start) / 2;
71-
return (getSumTree(start, mid, q_start, q_end, seg_index * 2 + 1) + getSumTree(mid + 1, end, q_start, q_end, seg_index * 2 + 2));
71+
return (getSumTree(start, mid, qStart, qEnd, segIndex * 2 + 1) + getSumTree(mid + 1, end, qStart, qEnd, segIndex * 2 + 2));
7272
}
7373

7474
/* A function to query the sum of the subarray [start...end]*/

src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public static long calculatePower(long x, long y) {
2727
}
2828

2929
// iterative function to calculate a to the power of b
30-
long power(long N, long M) {
31-
long power = N;
30+
long power(long n, long m) {
31+
long power = n;
3232
long sum = 1;
33-
while (M > 0) {
34-
if ((M & 1) == 1) {
33+
while (m > 0) {
34+
if ((m & 1) == 1) {
3535
sum *= power;
3636
}
3737
power = power * power;
38-
M = M >> 1;
38+
m = m >> 1;
3939
}
4040
return sum;
4141
}

src/main/java/com/thealgorithms/dynamicprogramming/BoundaryFill.java

+23-23
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,44 @@ private BoundaryFill() {
1212
* Get the color at the given co-odrinates of a 2D image
1313
*
1414
* @param image The image to be filled
15-
* @param x_co_ordinate The x co-ordinate of which color is to be obtained
16-
* @param y_co_ordinate The y co-ordinate of which color is to be obtained
15+
* @param xCoordinate The x co-ordinate of which color is to be obtained
16+
* @param yCoordinate The y co-ordinate of which color is to be obtained
1717
*/
18-
public static int getPixel(int[][] image, int x_co_ordinate, int y_co_ordinate) {
19-
return image[x_co_ordinate][y_co_ordinate];
18+
public static int getPixel(int[][] image, int xCoordinate, int yCoordinate) {
19+
return image[xCoordinate][yCoordinate];
2020
}
2121

2222
/**
2323
* Put the color at the given co-odrinates of a 2D image
2424
*
2525
* @param image The image to be filed
26-
* @param x_co_ordinate The x co-ordinate at which color is to be filled
27-
* @param y_co_ordinate The y co-ordinate at which color is to be filled
26+
* @param xCoordinate The x co-ordinate at which color is to be filled
27+
* @param yCoordinate The y co-ordinate at which color is to be filled
2828
*/
29-
public static void putPixel(int[][] image, int x_co_ordinate, int y_co_ordinate, int new_color) {
30-
image[x_co_ordinate][y_co_ordinate] = new_color;
29+
public static void putPixel(int[][] image, int xCoordinate, int yCoordinate, int newColor) {
30+
image[xCoordinate][yCoordinate] = newColor;
3131
}
3232

3333
/**
3434
* Fill the 2D image with new color
3535
*
3636
* @param image The image to be filed
37-
* @param x_co_ordinate The x co-ordinate at which color is to be filled
38-
* @param y_co_ordinate The y co-ordinate at which color is to be filled
39-
* @param new_color The new color which to be filled in the image
40-
* @param boundary_color The old color which is to be replaced in the image
37+
* @param xCoordinate The x co-ordinate at which color is to be filled
38+
* @param yCoordinate The y co-ordinate at which color is to be filled
39+
* @param newColor The new color which to be filled in the image
40+
* @param boundaryColor The old color which is to be replaced in the image
4141
*/
42-
public static void boundaryFill(int[][] image, int x_co_ordinate, int y_co_ordinate, int new_color, int boundary_color) {
43-
if (x_co_ordinate >= 0 && y_co_ordinate >= 0 && getPixel(image, x_co_ordinate, y_co_ordinate) != new_color && getPixel(image, x_co_ordinate, y_co_ordinate) != boundary_color) {
44-
putPixel(image, x_co_ordinate, y_co_ordinate, new_color);
45-
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate, new_color, boundary_color);
46-
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate, new_color, boundary_color);
47-
boundaryFill(image, x_co_ordinate, y_co_ordinate + 1, new_color, boundary_color);
48-
boundaryFill(image, x_co_ordinate, y_co_ordinate - 1, new_color, boundary_color);
49-
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate - 1, new_color, boundary_color);
50-
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate + 1, new_color, boundary_color);
51-
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate + 1, new_color, boundary_color);
52-
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate - 1, new_color, boundary_color);
42+
public static void boundaryFill(int[][] image, int xCoordinate, int yCoordinate, int newColor, int boundaryColor) {
43+
if (xCoordinate >= 0 && yCoordinate >= 0 && getPixel(image, xCoordinate, yCoordinate) != newColor && getPixel(image, xCoordinate, yCoordinate) != boundaryColor) {
44+
putPixel(image, xCoordinate, yCoordinate, newColor);
45+
boundaryFill(image, xCoordinate + 1, yCoordinate, newColor, boundaryColor);
46+
boundaryFill(image, xCoordinate - 1, yCoordinate, newColor, boundaryColor);
47+
boundaryFill(image, xCoordinate, yCoordinate + 1, newColor, boundaryColor);
48+
boundaryFill(image, xCoordinate, yCoordinate - 1, newColor, boundaryColor);
49+
boundaryFill(image, xCoordinate + 1, yCoordinate - 1, newColor, boundaryColor);
50+
boundaryFill(image, xCoordinate - 1, yCoordinate + 1, newColor, boundaryColor);
51+
boundaryFill(image, xCoordinate + 1, yCoordinate + 1, newColor, boundaryColor);
52+
boundaryFill(image, xCoordinate - 1, yCoordinate - 1, newColor, boundaryColor);
5353
}
5454
}
5555

src/main/java/com/thealgorithms/dynamicprogramming/BruteForceKnapsack.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ private BruteForceKnapsack() {
88
// Returns the maximum value that
99
// can be put in a knapsack of
1010
// capacity W
11-
static int knapSack(int W, int[] wt, int[] val, int n) {
11+
static int knapSack(int w, int[] wt, int[] val, int n) {
1212
// Base Case
13-
if (n == 0 || W == 0) {
13+
if (n == 0 || w == 0) {
1414
return 0;
1515
}
1616

1717
// If weight of the nth item is
1818
// more than Knapsack capacity W,
1919
// then this item cannot be included
2020
// in the optimal solution
21-
if (wt[n - 1] > W) {
22-
return knapSack(W, wt, val, n - 1);
21+
if (wt[n - 1] > w) {
22+
return knapSack(w, wt, val, n - 1);
2323
} // Return the maximum of two cases:
2424
// (1) nth item included
2525
// (2) not included
2626
else {
27-
return Math.max(val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1), knapSack(W, wt, val, n - 1));
27+
return Math.max(val[n - 1] + knapSack(w - wt[n - 1], wt, val, n - 1), knapSack(w, wt, val, n - 1));
2828
}
2929
}
3030

src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public final class KadaneAlgorithm {
1010
private KadaneAlgorithm() {
1111
}
1212

13-
public static boolean maxSum(int[] a, int predicted_answer) {
13+
public static boolean maxSum(int[] a, int predictedAnswer) {
1414
int sum = a[0];
1515
int runningSum = 0;
1616
for (int k : a) {
@@ -22,7 +22,7 @@ public static boolean maxSum(int[] a, int predicted_answer) {
2222
// if running sum is negative then it is initialized to zero
2323
}
2424
// for-each loop is used to iterate over the array and find the maximum subarray sum
25-
return sum == predicted_answer;
25+
return sum == predictedAnswer;
2626
// It returns true if sum and predicted answer matches
2727
// The predicted answer is the answer itself. So it always return true
2828
}

0 commit comments

Comments
 (0)