Skip to content

Commit 25d711c

Browse files
authored
style: enable LocalVariableName in CheckStyle (#5191)
* style: enable LocalVariableName in checkstyle * Removed minor bug * Resolved Method Name Bug * Changed names according to suggestions
1 parent 81cb09b commit 25d711c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+419
-418
lines changed

checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<!-- See https://checkstyle.org/checks/naming/index.html -->
111111
<module name="ConstantName"/>
112112
<module name="LocalFinalVariableName"/>
113-
<!-- TODO <module name="LocalVariableName"/> -->
113+
<module name="LocalVariableName"/>
114114
<!-- TODO <module name="MemberName"/> -->
115115
<module name="MethodName"/>
116116
<module name="PackageName"/>

src/main/java/com/thealgorithms/ciphers/AffineCipher.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static String encryptMessage(char[] msg) {
2727

2828
static String decryptCipher(String cipher) {
2929
String msg = "";
30-
int a_inv = 0;
30+
int aInv = 0;
3131
int flag = 0;
3232

3333
// Find a^-1 (the multiplicative inverse of a
@@ -38,15 +38,15 @@ static String decryptCipher(String cipher) {
3838
// Check if (a*i)%26 == 1,
3939
// then i will be the multiplicative inverse of a
4040
if (flag == 1) {
41-
a_inv = i;
41+
aInv = i;
4242
}
4343
}
4444
for (int i = 0; i < cipher.length(); i++) {
4545
/*Applying decryption formula a^-1 ( x - b ) mod m
4646
{here x is cipher[i] and m is 26} and added 'A'
4747
to bring it in range of ASCII alphabet[ 65-90 | A-Z ] */
4848
if (cipher.charAt(i) != ' ') {
49-
msg = msg + (char) (((a_inv * ((cipher.charAt(i) + 'A' - b)) % 26)) + 'A');
49+
msg = msg + (char) (((aInv * ((cipher.charAt(i) + 'A' - b)) % 26)) + 'A');
5050
} else { // else simply append space character
5151
msg += cipher.charAt(i);
5252
}

src/main/java/com/thealgorithms/ciphers/DES.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ private String[] getSubkeys(String originalKey) {
8181
}
8282
String[] subKeys = new String[16];
8383
String initialPermutedKey = permutedKey.toString();
84-
String C0 = initialPermutedKey.substring(0, 28);
85-
String D0 = initialPermutedKey.substring(28);
84+
String c0 = initialPermutedKey.substring(0, 28);
85+
String d0 = initialPermutedKey.substring(28);
8686

8787
// We will now operate on the left and right halves of the permutedKey
8888
for (i = 0; i < 16; i++) {
89-
String Cn = C0.substring(KEY_SHIFTS[i]) + C0.substring(0, KEY_SHIFTS[i]);
90-
String Dn = D0.substring(KEY_SHIFTS[i]) + D0.substring(0, KEY_SHIFTS[i]);
91-
subKeys[i] = Cn + Dn;
92-
C0 = Cn; // Re-assign the values to create running permutation
93-
D0 = Dn;
89+
String cN = c0.substring(KEY_SHIFTS[i]) + c0.substring(0, KEY_SHIFTS[i]);
90+
String dN = d0.substring(KEY_SHIFTS[i]) + d0.substring(0, KEY_SHIFTS[i]);
91+
subKeys[i] = cN + dN;
92+
c0 = cN; // Re-assign the values to create running permutation
93+
d0 = dN;
9494
}
9595

9696
// Let us shrink the keys to 48 bits (well, characters here) using pc2
@@ -169,18 +169,18 @@ private String encryptBlock(String message, String[] keys) {
169169
for (i = 0; i < 64; i++) {
170170
permutedMessage.append(message.charAt(IP[i] - 1));
171171
}
172-
String L0 = permutedMessage.substring(0, 32);
173-
String R0 = permutedMessage.substring(32);
172+
String e0 = permutedMessage.substring(0, 32);
173+
String f0 = permutedMessage.substring(32);
174174

175175
// Iterate 16 times
176176
for (i = 0; i < 16; i++) {
177-
String Ln = R0; // Previous Right block
178-
String Rn = xOR(L0, feistel(R0, keys[i]));
179-
L0 = Ln;
180-
R0 = Rn;
177+
String eN = f0; // Previous Right block
178+
String fN = xOR(e0, feistel(f0, keys[i]));
179+
e0 = eN;
180+
f0 = fN;
181181
}
182182

183-
String combinedBlock = R0 + L0; // Reverse the 16th block
183+
String combinedBlock = f0 + e0; // Reverse the 16th block
184184
permutedMessage.setLength(0);
185185
for (i = 0; i < 64; i++) {
186186
permutedMessage.append(combinedBlock.charAt(IP_INVERSE[i] - 1));

src/main/java/com/thealgorithms/ciphers/HillCipher.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void encrypt(String message) {
3535
validateDeterminant(keyMatrix, matrixSize);
3636

3737
int[][] messageVector = new int[matrixSize][1];
38-
String CipherText = "";
38+
String cipherText = "";
3939
int[][] cipherMatrix = new int[matrixSize][1];
4040
int j = 0;
4141
while (j < message.length()) {
@@ -60,10 +60,10 @@ static void encrypt(String message) {
6060
cipherMatrix[i][0] = cipherMatrix[i][0] % 26;
6161
}
6262
for (i = 0; i < matrixSize; i++) {
63-
CipherText += (char) (cipherMatrix[i][0] + 65);
63+
cipherText += (char) (cipherMatrix[i][0] + 65);
6464
}
6565
}
66-
System.out.println("Ciphertext: " + CipherText);
66+
System.out.println("Ciphertext: " + cipherText);
6767
}
6868

6969
// Following function decrypts a message
@@ -84,7 +84,7 @@ static void decrypt(String message) {
8484

8585
// solving for the required plaintext message
8686
int[][] messageVector = new int[n][1];
87-
String PlainText = "";
87+
String plainText = "";
8888
int[][] plainMatrix = new int[n][1];
8989
int j = 0;
9090
while (j < message.length()) {
@@ -109,10 +109,10 @@ static void decrypt(String message) {
109109
plainMatrix[i][0] = plainMatrix[i][0] % 26;
110110
}
111111
for (i = 0; i < n; i++) {
112-
PlainText += (char) (plainMatrix[i][0] + 65);
112+
plainText += (char) (plainMatrix[i][0] + 65);
113113
}
114114
}
115-
System.out.println("Plaintext: " + PlainText);
115+
System.out.println("Plaintext: " + plainText);
116116
}
117117

118118
// Determinant calculator

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ public static int getHexaToDec(String hex) {
2020

2121
// Main method gets the hexadecimal input from user and converts it into Decimal output.
2222
public static void main(String[] args) {
23-
String hexa_Input;
24-
int dec_output;
23+
String hexaInput;
24+
int decOutput;
2525
Scanner scan = new Scanner(System.in);
2626

2727
System.out.print("Enter Hexadecimal Number : ");
28-
hexa_Input = scan.nextLine();
28+
hexaInput = scan.nextLine();
2929

3030
// convert hexadecimal to decimal
31-
dec_output = getHexaToDec(hexa_Input);
31+
decOutput = getHexaToDec(hexaInput);
3232
/*
3333
Pass the string to the getHexaToDec function
34-
and it returns the decimal form in the variable dec_output.
34+
and it returns the decimal form in the variable decOutput.
3535
*/
36-
System.out.println("Number in Decimal: " + dec_output);
36+
System.out.println("Number in Decimal: " + decOutput);
3737
scan.close();
3838
}
3939
}

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ public static void main(String[] args) throws IOException {
5454
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
5555
int t = Integer.parseInt(read.readLine().trim());
5656
while (t-- > 0) {
57-
String[] S = read.readLine().trim().split(" ");
58-
int V = Integer.parseInt(S[0]);
59-
int E = Integer.parseInt(S[1]);
57+
String[] str1 = read.readLine().trim().split(" ");
58+
int numVertices = Integer.parseInt(str1[0]);
59+
int numEdges = Integer.parseInt(str1[1]);
6060

6161
ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
62-
for (int i = 0; i < V; i++) {
62+
for (int i = 0; i < numVertices; i++) {
6363
adj.add(new ArrayList<>());
6464
}
65-
for (int i = 0; i < E; i++) {
66-
String[] s = read.readLine().trim().split(" ");
67-
int u = Integer.parseInt(s[0]);
68-
int v = Integer.parseInt(s[1]);
69-
adj.get(u).add(v);
70-
adj.get(v).add(u);
65+
for (int i = 0; i < numEdges; i++) {
66+
String[] str2 = read.readLine().trim().split(" ");
67+
int vertexU = Integer.parseInt(str2[0]);
68+
int vertexV = Integer.parseInt(str2[1]);
69+
adj.get(vertexU).add(vertexV);
70+
adj.get(vertexV).add(vertexU);
7171
}
7272

73-
boolean ans = isBipartite(V, adj);
73+
boolean ans = isBipartite(numVertices, adj);
7474
if (ans) {
7575
System.out.println("YES");
7676
} else {

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ class dijkstras {
88

99
int k = 9;
1010

11-
int minDist(int[] dist, Boolean[] Set) {
11+
int minDist(int[] dist, Boolean[] set) {
1212
int min = Integer.MAX_VALUE;
13-
int min_index = -1;
13+
int minIndex = -1;
1414

1515
for (int r = 0; r < k; r++) {
16-
if (!Set[r] && dist[r] <= min) {
16+
if (!set[r] && dist[r] <= min) {
1717
min = dist[r];
18-
min_index = r;
18+
minIndex = r;
1919
}
2020
}
2121

22-
return min_index;
22+
return minIndex;
2323
}
2424

2525
void print(int[] dist) {
@@ -31,22 +31,22 @@ void print(int[] dist) {
3131

3232
void dijkstra(int[][] graph, int src) {
3333
int[] dist = new int[k];
34-
Boolean[] Set = new Boolean[k];
34+
Boolean[] set = new Boolean[k];
3535

3636
for (int i = 0; i < k; i++) {
3737
dist[i] = Integer.MAX_VALUE;
38-
Set[i] = Boolean.FALSE;
38+
set[i] = Boolean.FALSE;
3939
}
4040

4141
dist[src] = 0;
4242

4343
for (int c = 0; c < k - 1; c++) {
44-
int u = minDist(dist, Set);
44+
int u = minDist(dist, set);
4545

46-
Set[u] = Boolean.TRUE;
46+
set[u] = Boolean.TRUE;
4747

4848
for (int v = 0; v < k; v++) {
49-
if (!Set[v] && graph[u][v] != 0 && dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) {
49+
if (!set[v] && graph[u][v] != 0 && dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) {
5050
dist[v] = dist[u] + graph[u][v];
5151
}
5252
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ class PrimMST {
1515
int minKey(int[] key, Boolean[] mstSet) {
1616
// Initialize min value
1717
int min = Integer.MAX_VALUE;
18-
int min_index = -1;
18+
int minIndex = -1;
1919

2020
for (int v = 0; v < V; v++) {
2121
if (!mstSet[v] && key[v] < min) {
2222
min = key[v];
23-
min_index = v;
23+
minIndex = v;
2424
}
2525
}
2626

27-
return min_index;
27+
return minIndex;
2828
}
2929

3030
// A utility function to print the constructed MST stored in

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static void main(String[] args) {
1111
int key;
1212

1313
HashMap h = new HashMap(7);
14-
Scanner In = new Scanner(System.in);
14+
Scanner scan = new Scanner(System.in);
1515

1616
while (true) {
1717
System.out.println("Enter your Choice :");
@@ -20,18 +20,18 @@ public static void main(String[] args) {
2020
System.out.println("3. Print Table");
2121
System.out.println("4. Exit");
2222

23-
choice = In.nextInt();
23+
choice = scan.nextInt();
2424

2525
switch (choice) {
2626
case 1: {
2727
System.out.println("Enter the Key: ");
28-
key = In.nextInt();
28+
key = scan.nextInt();
2929
h.insertHash(key);
3030
break;
3131
}
3232
case 2: {
3333
System.out.println("Enter the Key delete: ");
34-
key = In.nextInt();
34+
key = scan.nextInt();
3535
h.deleteHash(key);
3636
break;
3737
}
@@ -41,7 +41,7 @@ public static void main(String[] args) {
4141
break;
4242
}
4343
case 4: {
44-
In.close();
44+
scan.close();
4545
return;
4646
}
4747
default: {

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static void main(String[] args) {
1111
int key;
1212

1313
HashMapCuckooHashing h = new HashMapCuckooHashing(7);
14-
Scanner In = new Scanner(System.in);
14+
Scanner scan = new Scanner(System.in);
1515

1616
while (true) {
1717
System.out.println("_________________________");
@@ -24,18 +24,18 @@ public static void main(String[] args) {
2424
System.out.println("6. Check load factor");
2525
System.out.println("7. Rehash Current Table");
2626

27-
choice = In.nextInt();
27+
choice = scan.nextInt();
2828

2929
switch (choice) {
3030
case 1: {
3131
System.out.println("Enter the Key: ");
32-
key = In.nextInt();
32+
key = scan.nextInt();
3333
h.insertKey2HashTable(key);
3434
break;
3535
}
3636
case 2: {
3737
System.out.println("Enter the Key delete: ");
38-
key = In.nextInt();
38+
key = scan.nextInt();
3939
h.deleteKeyFromHashTable(key);
4040
break;
4141
}
@@ -45,12 +45,12 @@ public static void main(String[] args) {
4545
break;
4646
}
4747
case 4: {
48-
In.close();
48+
scan.close();
4949
return;
5050
}
5151
case 5: {
5252
System.out.println("Enter the Key to find and print: ");
53-
key = In.nextInt();
53+
key = scan.nextInt();
5454
System.out.println("Key: " + key + " is at index: " + h.findKeyInTable(key) + "\n");
5555
break;
5656
}

0 commit comments

Comments
 (0)