style: enable ConstantName in checkstyle (#5139)

Co-authored-by: Maria Paszkiewicz SCC <maria.paszkiewicz@kit.edu>
This commit is contained in:
marysiuniq
2024-05-02 18:31:37 +02:00
committed by GitHub
parent ede3e4651f
commit 1e2d7e9431
16 changed files with 87 additions and 90 deletions

View File

@ -3,10 +3,10 @@ package com.thealgorithms.conversions;
// 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',
@ -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();
}

View File

@ -9,7 +9,7 @@ package com.thealgorithms.conversions;
*/
public class IntegerToRoman {
private static final int[] allArabianRomanNumbers = new int[] {
private static final int[] ALL_ROMAN_NUMBERS_IN_ARABIC = new int[] {
1000,
900,
500,
@ -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",
@ -48,13 +48,13 @@ public class IntegerToRoman {
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();

View File

@ -4,9 +4,7 @@ import java.util.*;
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);
@ -38,10 +36,10 @@ public class RomanToInteger {
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) {