Skip to content

Commit 1e2d7e9

Browse files
marysiuniqMaria Paszkiewicz SCC
and
Maria Paszkiewicz SCC
authored
style: enable ConstantName in checkstyle (#5139)
Co-authored-by: Maria Paszkiewicz SCC <[email protected]>
1 parent ede3e46 commit 1e2d7e9

File tree

16 files changed

+87
-90
lines changed

16 files changed

+87
-90
lines changed

checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
<!-- Checks for Naming Conventions. -->
110110
<!-- See https://checkstyle.org/checks/naming/index.html -->
111-
<!-- TODO <module name="ConstantName"/> -->
111+
<module name="ConstantName"/>
112112
<!-- TODO <module name="LocalFinalVariableName"/> -->
113113
<!-- TODO <module name="LocalVariableName"/> -->
114114
<!-- TODO <module name="MemberName"/> -->

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
*/
2727
public class KnightsTour {
2828

29-
private static final int base = 12;
30-
private static final int[][] moves = {
29+
private static final int BASE = 12;
30+
private static final int[][] MOVES = {
3131
{1, -2},
3232
{2, -1},
3333
{2, 1},
@@ -41,19 +41,19 @@ public class KnightsTour {
4141
private static int total; // total squares in chess
4242

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

47-
for (int r = 0; r < base; r++) {
48-
for (int c = 0; c < base; c++) {
49-
if (r < 2 || r > base - 3 || c < 2 || c > base - 3) {
47+
for (int r = 0; r < BASE; r++) {
48+
for (int c = 0; c < BASE; c++) {
49+
if (r < 2 || r > BASE - 3 || c < 2 || c > BASE - 3) {
5050
grid[r][c] = -1;
5151
}
5252
}
5353
}
5454

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

5858
grid[row][col] = 1;
5959

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

98-
for (int[] m : moves) {
98+
for (int[] m : MOVES) {
9999
int x = m[0];
100100
int y = m[1];
101101
if (grid[row + y][column + x] == 0) {
@@ -109,7 +109,7 @@ private static List<int[]> neighbors(int row, int column) {
109109
// Returns the total count of neighbors
110110
private static int countNeighbors(int row, int column) {
111111
int num = 0;
112-
for (int[] m : moves) {
112+
for (int[] m : MOVES) {
113113
if (grid[row + m[1]][column + m[0]] == 0) {
114114
num++;
115115
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
public class Polybius {
1717

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

2727
private static String findLocationByCharacter(final char character) {
2828
final StringBuilder location = new StringBuilder();
29-
for (int i = 0; i < key.length; i++) {
30-
for (int j = 0; j < key[i].length; j++) {
31-
if (character == key[i][j]) {
29+
for (int i = 0; i < KEY.length; i++) {
30+
for (int j = 0; j < KEY[i].length; j++) {
31+
if (character == KEY[i][j]) {
3232
location.append(i).append(j);
3333
break;
3434
}
@@ -53,7 +53,7 @@ public static String decrypt(final String ciphertext) {
5353
for (int i = 0; i < chars.length; i += 2) {
5454
int pozitionX = Character.getNumericValue(chars[i]);
5555
int pozitionY = Character.getNumericValue(chars[i + 1]);
56-
plaintext.append(key[pozitionX][pozitionY]);
56+
plaintext.append(KEY[pozitionX][pozitionY]);
5757
}
5858
return plaintext.toString();
5959
}

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// hex = [0 - 9] -> [A - F]
44
class DecimalToHexaDecimal {
55

6-
private static final int sizeOfIntInHalfBytes = 8;
7-
private static final int numberOfBitsInAHalfByte = 4;
8-
private static final int halfByte = 0x0F;
9-
private static final char[] hexDigits = {
6+
private static final int SIZE_OF_INT_IN_HALF_BYTES = 8;
7+
private static final int NUMBER_OF_BITS_IN_HALF_BYTE = 4;
8+
private static final int HALF_BYTE = 0x0F;
9+
private static final char[] HEX_DIGITS = {
1010
'0',
1111
'1',
1212
'2',
@@ -27,12 +27,12 @@ class DecimalToHexaDecimal {
2727

2828
// Returns the hex value of the dec entered in the parameter.
2929
public static String decToHex(int dec) {
30-
StringBuilder hexBuilder = new StringBuilder(sizeOfIntInHalfBytes);
31-
hexBuilder.setLength(sizeOfIntInHalfBytes);
32-
for (int i = sizeOfIntInHalfBytes - 1; i >= 0; --i) {
33-
int j = dec & halfByte;
34-
hexBuilder.setCharAt(i, hexDigits[j]);
35-
dec >>= numberOfBitsInAHalfByte;
30+
StringBuilder hexBuilder = new StringBuilder(SIZE_OF_INT_IN_HALF_BYTES);
31+
hexBuilder.setLength(SIZE_OF_INT_IN_HALF_BYTES);
32+
for (int i = SIZE_OF_INT_IN_HALF_BYTES - 1; i >= 0; --i) {
33+
int j = dec & HALF_BYTE;
34+
hexBuilder.setCharAt(i, HEX_DIGITS[j]);
35+
dec >>= NUMBER_OF_BITS_IN_HALF_BYTE;
3636
}
3737
return hexBuilder.toString().toLowerCase();
3838
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
public class IntegerToRoman {
1111

12-
private static final int[] allArabianRomanNumbers = new int[] {
12+
private static final int[] ALL_ROMAN_NUMBERS_IN_ARABIC = new int[] {
1313
1000,
1414
900,
1515
500,
@@ -24,7 +24,7 @@ public class IntegerToRoman {
2424
4,
2525
1,
2626
};
27-
private static final String[] allRomanNumbers = new String[] {
27+
private static final String[] ALL_ROMAN_NUMBERS = new String[] {
2828
"M",
2929
"CM",
3030
"D",
@@ -48,13 +48,13 @@ public static String integerToRoman(int num) {
4848

4949
StringBuilder builder = new StringBuilder();
5050

51-
for (int a = 0; a < allArabianRomanNumbers.length; a++) {
52-
int times = num / allArabianRomanNumbers[a];
51+
for (int a = 0; a < ALL_ROMAN_NUMBERS_IN_ARABIC.length; a++) {
52+
int times = num / ALL_ROMAN_NUMBERS_IN_ARABIC[a];
5353
for (int b = 0; b < times; b++) {
54-
builder.append(allRomanNumbers[a]);
54+
builder.append(ALL_ROMAN_NUMBERS[a]);
5555
}
5656

57-
num -= times * allArabianRomanNumbers[a];
57+
num -= times * ALL_ROMAN_NUMBERS_IN_ARABIC[a];
5858
}
5959

6060
return builder.toString();

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
public class RomanToInteger {
66

7-
private static final Map<Character, Integer> map = new HashMap<>() {
8-
private static final long serialVersionUID = 87605733047260530L;
9-
7+
private static final Map<Character, Integer> ROMAN_TO_INT = new HashMap<>() {
108
{
119
put('I', 1);
1210
put('V', 5);
@@ -38,10 +36,10 @@ public static int romanToInt(String A) {
3836

3937
if (prev != ' ') {
4038
// checking current Number greater then previous or not
41-
newPrev = map.get(prev) > newPrev ? map.get(prev) : newPrev;
39+
newPrev = ROMAN_TO_INT.get(prev) > newPrev ? ROMAN_TO_INT.get(prev) : newPrev;
4240
}
4341

44-
int currentNum = map.get(c);
42+
int currentNum = ROMAN_TO_INT.get(c);
4543

4644
// if current number greater then prev max previous then add
4745
if (currentNum >= newPrev) {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
public class LCA {
77

8-
private static final Scanner scanner = new Scanner(System.in);
8+
private static final Scanner SCANNER = new Scanner(System.in);
99

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

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

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

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

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

4343
// Outputting the LCA
4444
System.out.println(getLCA(v1, v2, depth, parent));

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
public class Fibonacci {
1111

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

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

3737
int f;
@@ -40,7 +40,7 @@ public static int fibMemo(int n) {
4040
f = n;
4141
} else {
4242
f = fibMemo(n - 1) + fibMemo(n - 2);
43-
map.put(n, f);
43+
CACHE.put(n, f);
4444
}
4545
return f;
4646
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public class MatrixChainMultiplication {
88

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

2626
Matrix matrix = new Matrix(count, col, row);
27-
mArray.add(matrix);
27+
MATRICES.add(matrix);
2828
count++;
2929
}
30-
for (Matrix m : mArray) {
30+
for (Matrix m : MATRICES) {
3131
System.out.format("A(%d) = %2d x %2d%n", m.count(), m.col(), m.row());
3232
}
3333

34-
size = mArray.size();
34+
size = MATRICES.size();
3535
m = new int[size + 1][size + 1];
3636
s = new int[size + 1][size + 1];
3737
p = new int[size + 1];
@@ -42,7 +42,7 @@ public static void main(String[] args) {
4242
}
4343

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

4848
matrixChainOrder();
@@ -109,7 +109,7 @@ private static void matrixChainOrder() {
109109

110110
private static String[] input(String string) {
111111
System.out.print(string);
112-
return (scan.nextLine().split(" "));
112+
return (SCANNER.nextLine().split(" "));
113113
}
114114
}
115115

src/main/java/com/thealgorithms/maths/FindKthNumber.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
public class FindKthNumber {
1010

11-
private static final Random random = new Random();
11+
private static final Random RANDOM = new Random();
1212

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

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

3535
for (int i = 0; i < size; i++) {
36-
array[i] = random.nextInt() % 100;
36+
array[i] = RANDOM.nextInt() % 100;
3737
}
3838
return array;
3939
}

src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
public class Fibonacci {
1111

1212
// Exponentiation matrix for Fibonacci sequence
13-
private static final int[][] fibMatrix = {{1, 1}, {1, 0}};
14-
private static final int[][] identityMatrix = {{1, 0}, {0, 1}};
13+
private static final int[][] FIB_MATRIX = {{1, 1}, {1, 0}};
14+
private static final int[][] IDENTITY_MATRIX = {{1, 0}, {0, 1}};
1515
// First 2 fibonacci numbers
16-
private static final int[][] baseFibNumbers = {{1}, {0}};
16+
private static final int[][] BASE_FIB_NUMBERS = {{1}, {0}};
1717

1818
/**
1919
* Performs multiplication of 2 matrices
@@ -53,14 +53,14 @@ private static int[][] matrixMultiplication(int[][] matrix1, int[][] matrix2) {
5353
*/
5454
public static int[][] fib(int n) {
5555
if (n == 0) {
56-
return Fibonacci.identityMatrix;
56+
return Fibonacci.IDENTITY_MATRIX;
5757
} else {
5858
int[][] cachedResult = fib(n / 2);
5959
int[][] matrixExpResult = matrixMultiplication(cachedResult, cachedResult);
6060
if (n % 2 == 0) {
6161
return matrixExpResult;
6262
} else {
63-
return matrixMultiplication(Fibonacci.fibMatrix, matrixExpResult);
63+
return matrixMultiplication(Fibonacci.FIB_MATRIX, matrixExpResult);
6464
}
6565
}
6666
}
@@ -69,7 +69,7 @@ public static void main(String[] args) {
6969
// Returns [0, 1, 1, 2, 3, 5 ..] for n = [0, 1, 2, 3, 4, 5.. ]
7070
Scanner sc = new Scanner(System.in);
7171
int n = sc.nextInt();
72-
int[][] result = matrixMultiplication(fib(n), baseFibNumbers);
72+
int[][] result = matrixMultiplication(fib(n), BASE_FIB_NUMBERS);
7373
System.out.println("Fib(" + n + ") = " + result[1][0]);
7474
sc.close();
7575
}

src/main/java/com/thealgorithms/others/Conway.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Conway {
1313
*1s, two 2s, one 1" or 312211. https://en.wikipedia.org/wiki/Look-and-say_sequence
1414
* */
1515

16-
private static final StringBuilder builder = new StringBuilder();
16+
private static final StringBuilder BUILDER = new StringBuilder();
1717

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

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

0 commit comments

Comments
 (0)