Skip to content

style: enable ConstantName in checkstyle #5139

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 1 commit into from
May 2, 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 @@ -108,7 +108,7 @@

<!-- Checks for Naming Conventions. -->
<!-- See https://checkstyle.org/checks/naming/index.html -->
<!-- TODO <module name="ConstantName"/> -->
<module name="ConstantName"/>
<!-- TODO <module name="LocalFinalVariableName"/> -->
<!-- TODO <module name="LocalVariableName"/> -->
<!-- TODO <module name="MemberName"/> -->
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/thealgorithms/backtracking/KnightsTour.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*/
public class KnightsTour {

private static final int base = 12;
private static final int[][] moves = {
private static final int BASE = 12;
private static final int[][] MOVES = {
{1, -2},
{2, -1},
{2, 1},
Expand All @@ -41,19 +41,19 @@ public class KnightsTour {
private static int total; // total squares in chess

public static void main(String[] args) {
grid = new int[base][base];
total = (base - 4) * (base - 4);
grid = new int[BASE][BASE];
total = (BASE - 4) * (BASE - 4);

for (int r = 0; r < base; r++) {
for (int c = 0; c < base; c++) {
if (r < 2 || r > base - 3 || c < 2 || c > base - 3) {
for (int r = 0; r < BASE; r++) {
for (int c = 0; c < BASE; c++) {
if (r < 2 || r > BASE - 3 || c < 2 || c > BASE - 3) {
grid[r][c] = -1;
}
}
}

int row = 2 + (int) (Math.random() * (base - 4));
int col = 2 + (int) (Math.random() * (base - 4));
int row = 2 + (int) (Math.random() * (BASE - 4));
int col = 2 + (int) (Math.random() * (BASE - 4));

grid[row][col] = 1;

Expand Down Expand Up @@ -95,7 +95,7 @@ private static boolean solve(int row, int column, int count) {
private static List<int[]> neighbors(int row, int column) {
List<int[]> neighbour = new ArrayList<>();

for (int[] m : moves) {
for (int[] m : MOVES) {
int x = m[0];
int y = m[1];
if (grid[row + y][column + x] == 0) {
Expand All @@ -109,7 +109,7 @@ private static List<int[]> neighbors(int row, int column) {
// Returns the total count of neighbors
private static int countNeighbors(int row, int column) {
int num = 0;
for (int[] m : moves) {
for (int[] m : MOVES) {
if (grid[row + m[1]][column + m[0]] == 0) {
num++;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/thealgorithms/ciphers/Polybius.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class Polybius {

private static final char[][] key = {
private static final char[][] KEY = {
// 0 1 2 3 4
/* 0 */ {'A', 'B', 'C', 'D', 'E'},
/* 1 */ {'F', 'G', 'H', 'I', 'J'},
Expand All @@ -26,9 +26,9 @@ public class Polybius {

private static String findLocationByCharacter(final char character) {
final StringBuilder location = new StringBuilder();
for (int i = 0; i < key.length; i++) {
for (int j = 0; j < key[i].length; j++) {
if (character == key[i][j]) {
for (int i = 0; i < KEY.length; i++) {
for (int j = 0; j < KEY[i].length; j++) {
if (character == KEY[i][j]) {
location.append(i).append(j);
break;
}
Expand All @@ -53,7 +53,7 @@ public static String decrypt(final String ciphertext) {
for (int i = 0; i < chars.length; i += 2) {
int pozitionX = Character.getNumericValue(chars[i]);
int pozitionY = Character.getNumericValue(chars[i + 1]);
plaintext.append(key[pozitionX][pozitionY]);
plaintext.append(KEY[pozitionX][pozitionY]);
}
return plaintext.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// hex = [0 - 9] -> [A - F]
class DecimalToHexaDecimal {

private static final int sizeOfIntInHalfBytes = 8;
private static final int numberOfBitsInAHalfByte = 4;
private static final int halfByte = 0x0F;
private static final char[] hexDigits = {
private static final int SIZE_OF_INT_IN_HALF_BYTES = 8;
private static final int NUMBER_OF_BITS_IN_HALF_BYTE = 4;
private static final int HALF_BYTE = 0x0F;
private static final char[] HEX_DIGITS = {
'0',
'1',
'2',
Expand All @@ -27,12 +27,12 @@ class DecimalToHexaDecimal {

// Returns the hex value of the dec entered in the parameter.
public static String decToHex(int dec) {
StringBuilder hexBuilder = new StringBuilder(sizeOfIntInHalfBytes);
hexBuilder.setLength(sizeOfIntInHalfBytes);
for (int i = sizeOfIntInHalfBytes - 1; i >= 0; --i) {
int j = dec & halfByte;
hexBuilder.setCharAt(i, hexDigits[j]);
dec >>= numberOfBitsInAHalfByte;
StringBuilder hexBuilder = new StringBuilder(SIZE_OF_INT_IN_HALF_BYTES);
hexBuilder.setLength(SIZE_OF_INT_IN_HALF_BYTES);
for (int i = SIZE_OF_INT_IN_HALF_BYTES - 1; i >= 0; --i) {
int j = dec & HALF_BYTE;
hexBuilder.setCharAt(i, HEX_DIGITS[j]);
dec >>= NUMBER_OF_BITS_IN_HALF_BYTE;
}
return hexBuilder.toString().toLowerCase();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class IntegerToRoman {

private static final int[] allArabianRomanNumbers = new int[] {
private static final int[] ALL_ROMAN_NUMBERS_IN_ARABIC = new int[] {
1000,
900,
500,
Expand All @@ -24,7 +24,7 @@ public class IntegerToRoman {
4,
1,
};
private static final String[] allRomanNumbers = new String[] {
private static final String[] ALL_ROMAN_NUMBERS = new String[] {
"M",
"CM",
"D",
Expand All @@ -48,13 +48,13 @@ public static String integerToRoman(int num) {

StringBuilder builder = new StringBuilder();

for (int a = 0; a < allArabianRomanNumbers.length; a++) {
int times = num / allArabianRomanNumbers[a];
for (int a = 0; a < ALL_ROMAN_NUMBERS_IN_ARABIC.length; a++) {
int times = num / ALL_ROMAN_NUMBERS_IN_ARABIC[a];
for (int b = 0; b < times; b++) {
builder.append(allRomanNumbers[a]);
builder.append(ALL_ROMAN_NUMBERS[a]);
}

num -= times * allArabianRomanNumbers[a];
num -= times * ALL_ROMAN_NUMBERS_IN_ARABIC[a];
}

return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

public class RomanToInteger {

private static final Map<Character, Integer> map = new HashMap<>() {
private static final long serialVersionUID = 87605733047260530L;

private static final Map<Character, Integer> ROMAN_TO_INT = new HashMap<>() {
{
put('I', 1);
put('V', 5);
Expand Down Expand Up @@ -38,10 +36,10 @@ public static int romanToInt(String A) {

if (prev != ' ') {
// checking current Number greater then previous or not
newPrev = map.get(prev) > newPrev ? map.get(prev) : newPrev;
newPrev = ROMAN_TO_INT.get(prev) > newPrev ? ROMAN_TO_INT.get(prev) : newPrev;
}

int currentNum = map.get(c);
int currentNum = ROMAN_TO_INT.get(c);

// if current number greater then prev max previous then add
if (currentNum >= newPrev) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/thealgorithms/datastructures/trees/LCA.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

public class LCA {

private static final Scanner scanner = new Scanner(System.in);
private static final Scanner SCANNER = new Scanner(System.in);

public static void main(String[] args) {
// The adjacency list representation of a tree:
ArrayList<ArrayList<Integer>> adj = new ArrayList<>();

// v is the number of vertices and e is the number of edges
int v = scanner.nextInt(), e = v - 1;
int v = SCANNER.nextInt(), e = v - 1;

for (int i = 0; i < v; i++) {
adj.add(new ArrayList<Integer>());
Expand All @@ -21,8 +21,8 @@ public static void main(String[] args) {
// Storing the given tree as an adjacency list
int to, from;
for (int i = 0; i < e; i++) {
to = scanner.nextInt();
from = scanner.nextInt();
to = SCANNER.nextInt();
from = SCANNER.nextInt();

adj.get(to).add(from);
adj.get(from).add(to);
Expand All @@ -38,7 +38,7 @@ public static void main(String[] args) {
dfs(adj, 0, -1, parent, depth);

// Inputting the two vertices whose LCA is to be calculated
int v1 = scanner.nextInt(), v2 = scanner.nextInt();
int v1 = SCANNER.nextInt(), v2 = SCANNER.nextInt();

// Outputting the LCA
System.out.println(getLCA(v1, v2, depth, parent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class Fibonacci {

private static final Map<Integer, Integer> map = new HashMap<>();
private static final Map<Integer, Integer> CACHE = new HashMap<>();

public static void main(String[] args) {
// Methods all returning [0, 1, 1, 2, 3, 5, ...] for n = [0, 1, 2, 3, 4, 5, ...]
Expand All @@ -30,8 +30,8 @@ public static void main(String[] args) {
* Outputs the nth fibonacci number
*/
public static int fibMemo(int n) {
if (map.containsKey(n)) {
return map.get(n);
if (CACHE.containsKey(n)) {
return CACHE.get(n);
}

int f;
Expand All @@ -40,7 +40,7 @@ public static int fibMemo(int n) {
f = n;
} else {
f = fibMemo(n - 1) + fibMemo(n - 2);
map.put(n, f);
CACHE.put(n, f);
}
return f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

public class MatrixChainMultiplication {

private static final Scanner scan = new Scanner(System.in);
private static final ArrayList<Matrix> mArray = new ArrayList<>();
private static final Scanner SCANNER = new Scanner(System.in);
private static final ArrayList<Matrix> MATRICES = new ArrayList<>();
private static int size;
private static int[][] m;
private static int[][] s;
Expand All @@ -24,14 +24,14 @@ public static void main(String[] args) {
int row = Integer.parseInt(mSize[1]);

Matrix matrix = new Matrix(count, col, row);
mArray.add(matrix);
MATRICES.add(matrix);
count++;
}
for (Matrix m : mArray) {
for (Matrix m : MATRICES) {
System.out.format("A(%d) = %2d x %2d%n", m.count(), m.col(), m.row());
}

size = mArray.size();
size = MATRICES.size();
m = new int[size + 1][size + 1];
s = new int[size + 1][size + 1];
p = new int[size + 1];
Expand All @@ -42,7 +42,7 @@ public static void main(String[] args) {
}

for (int i = 0; i < p.length; i++) {
p[i] = i == 0 ? mArray.get(i).col() : mArray.get(i - 1).row();
p[i] = i == 0 ? MATRICES.get(i).col() : MATRICES.get(i - 1).row();
}

matrixChainOrder();
Expand Down Expand Up @@ -109,7 +109,7 @@ private static void matrixChainOrder() {

private static String[] input(String string) {
System.out.print(string);
return (scan.nextLine().split(" "));
return (SCANNER.nextLine().split(" "));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/thealgorithms/maths/FindKthNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
public class FindKthNumber {

private static final Random random = new Random();
private static final Random RANDOM = new Random();

public static void main(String[] args) {
/* generate an array with random size and random elements */
Expand All @@ -29,11 +29,11 @@ public static void main(String[] args) {
}

private static int[] generateArray(int capacity) {
int size = random.nextInt(capacity) + 1;
int size = RANDOM.nextInt(capacity) + 1;
int[] array = new int[size];

for (int i = 0; i < size; i++) {
array[i] = random.nextInt() % 100;
array[i] = RANDOM.nextInt() % 100;
}
return array;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
public class Fibonacci {

// Exponentiation matrix for Fibonacci sequence
private static final int[][] fibMatrix = {{1, 1}, {1, 0}};
private static final int[][] identityMatrix = {{1, 0}, {0, 1}};
private static final int[][] FIB_MATRIX = {{1, 1}, {1, 0}};
private static final int[][] IDENTITY_MATRIX = {{1, 0}, {0, 1}};
// First 2 fibonacci numbers
private static final int[][] baseFibNumbers = {{1}, {0}};
private static final int[][] BASE_FIB_NUMBERS = {{1}, {0}};

/**
* Performs multiplication of 2 matrices
Expand Down Expand Up @@ -53,14 +53,14 @@ private static int[][] matrixMultiplication(int[][] matrix1, int[][] matrix2) {
*/
public static int[][] fib(int n) {
if (n == 0) {
return Fibonacci.identityMatrix;
return Fibonacci.IDENTITY_MATRIX;
} else {
int[][] cachedResult = fib(n / 2);
int[][] matrixExpResult = matrixMultiplication(cachedResult, cachedResult);
if (n % 2 == 0) {
return matrixExpResult;
} else {
return matrixMultiplication(Fibonacci.fibMatrix, matrixExpResult);
return matrixMultiplication(Fibonacci.FIB_MATRIX, matrixExpResult);
}
}
}
Expand All @@ -69,7 +69,7 @@ public static void main(String[] args) {
// Returns [0, 1, 1, 2, 3, 5 ..] for n = [0, 1, 2, 3, 4, 5.. ]
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] result = matrixMultiplication(fib(n), baseFibNumbers);
int[][] result = matrixMultiplication(fib(n), BASE_FIB_NUMBERS);
System.out.println("Fib(" + n + ") = " + result[1][0]);
sc.close();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/thealgorithms/others/Conway.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Conway {
*1s, two 2s, one 1" or 312211. https://en.wikipedia.org/wiki/Look-and-say_sequence
* */

private static final StringBuilder builder = new StringBuilder();
private static final StringBuilder BUILDER = new StringBuilder();

protected static List<String> generateList(String originalString, int maxIteration) {
List<String> numbers = new ArrayList<>();
Expand All @@ -25,9 +25,9 @@ protected static List<String> generateList(String originalString, int maxIterati
}

public static String generateNextElement(String originalString) {
builder.setLength(0);
BUILDER.setLength(0);
String[] stp = originalString.split("(?<=(.))(?!\\1)");
Arrays.stream(stp).forEach(s -> builder.append(s.length()).append(s.charAt(0)));
return builder.toString();
Arrays.stream(stp).forEach(s -> BUILDER.append(s.length()).append(s.charAt(0)));
return BUILDER.toString();
}
}
Loading