Skip to content

style: enable LocalVariableName in CheckStyle #5191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<!-- See https://checkstyle.org/checks/naming/index.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<!-- TODO <module name="LocalVariableName"/> -->
<module name="LocalVariableName"/>
<!-- TODO <module name="MemberName"/> -->
<module name="MethodName"/>
<module name="PackageName"/>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/thealgorithms/ciphers/AffineCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static String encryptMessage(char[] msg) {

static String decryptCipher(String cipher) {
String msg = "";
int a_inv = 0;
int aInv = 0;
int flag = 0;

// Find a^-1 (the multiplicative inverse of a
Expand All @@ -38,15 +38,15 @@ static String decryptCipher(String cipher) {
// Check if (a*i)%26 == 1,
// then i will be the multiplicative inverse of a
if (flag == 1) {
a_inv = i;
aInv = i;
}
}
for (int i = 0; i < cipher.length(); i++) {
/*Applying decryption formula a^-1 ( x - b ) mod m
{here x is cipher[i] and m is 26} and added 'A'
to bring it in range of ASCII alphabet[ 65-90 | A-Z ] */
if (cipher.charAt(i) != ' ') {
msg = msg + (char) (((a_inv * ((cipher.charAt(i) + 'A' - b)) % 26)) + 'A');
msg = msg + (char) (((aInv * ((cipher.charAt(i) + 'A' - b)) % 26)) + 'A');
} else { // else simply append space character
msg += cipher.charAt(i);
}
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/thealgorithms/ciphers/DES.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ private String[] getSubkeys(String originalKey) {
}
String[] subKeys = new String[16];
String initialPermutedKey = permutedKey.toString();
String C0 = initialPermutedKey.substring(0, 28);
String D0 = initialPermutedKey.substring(28);
String c0 = initialPermutedKey.substring(0, 28);
String d0 = initialPermutedKey.substring(28);

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

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

// Iterate 16 times
for (i = 0; i < 16; i++) {
String Ln = R0; // Previous Right block
String Rn = xOR(L0, feistel(R0, keys[i]));
L0 = Ln;
R0 = Rn;
String eN = f0; // Previous Right block
String fN = xOR(e0, feistel(f0, keys[i]));
e0 = eN;
f0 = fN;
}

String combinedBlock = R0 + L0; // Reverse the 16th block
String combinedBlock = f0 + e0; // Reverse the 16th block
permutedMessage.setLength(0);
for (i = 0; i < 64; i++) {
permutedMessage.append(combinedBlock.charAt(IP_INVERSE[i] - 1));
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/thealgorithms/ciphers/HillCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void encrypt(String message) {
validateDeterminant(keyMatrix, matrixSize);

int[][] messageVector = new int[matrixSize][1];
String CipherText = "";
String cipherText = "";
int[][] cipherMatrix = new int[matrixSize][1];
int j = 0;
while (j < message.length()) {
Expand All @@ -60,10 +60,10 @@ static void encrypt(String message) {
cipherMatrix[i][0] = cipherMatrix[i][0] % 26;
}
for (i = 0; i < matrixSize; i++) {
CipherText += (char) (cipherMatrix[i][0] + 65);
cipherText += (char) (cipherMatrix[i][0] + 65);
}
}
System.out.println("Ciphertext: " + CipherText);
System.out.println("Ciphertext: " + cipherText);
}

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

// solving for the required plaintext message
int[][] messageVector = new int[n][1];
String PlainText = "";
String plainText = "";
int[][] plainMatrix = new int[n][1];
int j = 0;
while (j < message.length()) {
Expand All @@ -109,10 +109,10 @@ static void decrypt(String message) {
plainMatrix[i][0] = plainMatrix[i][0] % 26;
}
for (i = 0; i < n; i++) {
PlainText += (char) (plainMatrix[i][0] + 65);
plainText += (char) (plainMatrix[i][0] + 65);
}
}
System.out.println("Plaintext: " + PlainText);
System.out.println("Plaintext: " + plainText);
}

// Determinant calculator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public static int getHexaToDec(String hex) {

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

System.out.print("Enter Hexadecimal Number : ");
hexa_Input = scan.nextLine();
hexaInput = scan.nextLine();

// convert hexadecimal to decimal
dec_output = getHexaToDec(hexa_Input);
decOutput = getHexaToDec(hexaInput);
/*
Pass the string to the getHexaToDec function
and it returns the decimal form in the variable dec_output.
and it returns the decimal form in the variable decOutput.
*/
System.out.println("Number in Decimal: " + dec_output);
System.out.println("Number in Decimal: " + decOutput);
scan.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine().trim());
while (t-- > 0) {
String[] S = read.readLine().trim().split(" ");
int V = Integer.parseInt(S[0]);
int E = Integer.parseInt(S[1]);
String[] str1 = read.readLine().trim().split(" ");
int numVertices = Integer.parseInt(str1[0]);
int numEdges = Integer.parseInt(str1[1]);

ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
for (int i = 0; i < V; i++) {
for (int i = 0; i < numVertices; i++) {
adj.add(new ArrayList<>());
}
for (int i = 0; i < E; i++) {
String[] s = read.readLine().trim().split(" ");
int u = Integer.parseInt(s[0]);
int v = Integer.parseInt(s[1]);
adj.get(u).add(v);
adj.get(v).add(u);
for (int i = 0; i < numEdges; i++) {
String[] str2 = read.readLine().trim().split(" ");
int vertexU = Integer.parseInt(str2[0]);
int vertexV = Integer.parseInt(str2[1]);
adj.get(vertexU).add(vertexV);
adj.get(vertexV).add(vertexU);
}

boolean ans = isBipartite(V, adj);
boolean ans = isBipartite(numVertices, adj);
if (ans) {
System.out.println("YES");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ class dijkstras {

int k = 9;

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

for (int r = 0; r < k; r++) {
if (!Set[r] && dist[r] <= min) {
if (!set[r] && dist[r] <= min) {
min = dist[r];
min_index = r;
minIndex = r;
}
}

return min_index;
return minIndex;
}

void print(int[] dist) {
Expand All @@ -31,22 +31,22 @@ void print(int[] dist) {

void dijkstra(int[][] graph, int src) {
int[] dist = new int[k];
Boolean[] Set = new Boolean[k];
Boolean[] set = new Boolean[k];

for (int i = 0; i < k; i++) {
dist[i] = Integer.MAX_VALUE;
Set[i] = Boolean.FALSE;
set[i] = Boolean.FALSE;
}

dist[src] = 0;

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

Set[u] = Boolean.TRUE;
set[u] = Boolean.TRUE;

for (int v = 0; v < k; v++) {
if (!Set[v] && graph[u][v] != 0 && dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) {
if (!set[v] && graph[u][v] != 0 && dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) {
dist[v] = dist[u] + graph[u][v];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class PrimMST {
int minKey(int[] key, Boolean[] mstSet) {
// Initialize min value
int min = Integer.MAX_VALUE;
int min_index = -1;
int minIndex = -1;

for (int v = 0; v < V; v++) {
if (!mstSet[v] && key[v] < min) {
min = key[v];
min_index = v;
minIndex = v;
}
}

return min_index;
return minIndex;
}

// A utility function to print the constructed MST stored in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void main(String[] args) {
int key;

HashMap h = new HashMap(7);
Scanner In = new Scanner(System.in);
Scanner scan = new Scanner(System.in);

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

choice = In.nextInt();
choice = scan.nextInt();

switch (choice) {
case 1: {
System.out.println("Enter the Key: ");
key = In.nextInt();
key = scan.nextInt();
h.insertHash(key);
break;
}
case 2: {
System.out.println("Enter the Key delete: ");
key = In.nextInt();
key = scan.nextInt();
h.deleteHash(key);
break;
}
Expand All @@ -41,7 +41,7 @@ public static void main(String[] args) {
break;
}
case 4: {
In.close();
scan.close();
return;
}
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void main(String[] args) {
int key;

HashMapCuckooHashing h = new HashMapCuckooHashing(7);
Scanner In = new Scanner(System.in);
Scanner scan = new Scanner(System.in);

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

choice = In.nextInt();
choice = scan.nextInt();

switch (choice) {
case 1: {
System.out.println("Enter the Key: ");
key = In.nextInt();
key = scan.nextInt();
h.insertKey2HashTable(key);
break;
}
case 2: {
System.out.println("Enter the Key delete: ");
key = In.nextInt();
key = scan.nextInt();
h.deleteKeyFromHashTable(key);
break;
}
Expand All @@ -45,12 +45,12 @@ public static void main(String[] args) {
break;
}
case 4: {
In.close();
scan.close();
return;
}
case 5: {
System.out.println("Enter the Key to find and print: ");
key = In.nextInt();
key = scan.nextInt();
System.out.println("Key: " + key + " is at index: " + h.findKeyInTable(key) + "\n");
break;
}
Expand Down
Loading