Skip to content

Commit 21042a4

Browse files
author
sailok.chinta
committed
feat: fix linting issues
1 parent 270ad9a commit 21042a4

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

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

+16-11
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.util.HashMap;
44

5-
public class IntegerToEnglish {
6-
private static final HashMap<Integer, String> baseNumbersMap = new HashMap<>() {
5+
public final class IntegerToEnglish {
6+
private static final HashMap<Integer, String> BASE_NUMBERS_MAP = new HashMap<>() {
77
{
88
put(0, "");
99
put(1, "One");
@@ -37,14 +37,17 @@ public class IntegerToEnglish {
3737
}
3838
};
3939

40-
private static final HashMap<Integer, String> thousandPowerMap = new HashMap<>() {
40+
private static final HashMap<Integer, String> THOUSAND_POWER_MAP = new HashMap<>() {
4141
{
4242
put(1, "Thousand");
4343
put(2, "Million");
4444
put(3, "Billion");
4545
}
4646
};
4747

48+
private IntegerToEnglish() {
49+
}
50+
4851
/**
4952
converts numbers < 1000 to english words
5053
*/
@@ -54,20 +57,20 @@ private static String convertToWords(int number) {
5457
String result;
5558

5659
if (remainder <= 20) {
57-
result = baseNumbersMap.get(remainder);
58-
} else if (baseNumbersMap.containsKey(remainder)) {
59-
result = baseNumbersMap.get(remainder);
60+
result = BASE_NUMBERS_MAP.get(remainder);
61+
} else if (BASE_NUMBERS_MAP.containsKey(remainder)) {
62+
result = BASE_NUMBERS_MAP.get(remainder);
6063
} else {
6164
int tensDigit = remainder / 10;
6265
int onesDigit = remainder % 10;
6366

64-
result = String.format("%s %s", baseNumbersMap.get(tensDigit * 10), baseNumbersMap.get(onesDigit));
67+
result = String.format("%s %s", BASE_NUMBERS_MAP.get(tensDigit * 10), BASE_NUMBERS_MAP.get(onesDigit));
6568
}
6669

6770
int hundredsDigit = number / 100;
6871

6972
if (hundredsDigit > 0) {
70-
result = String.format("%s %s%s", baseNumbersMap.get(hundredsDigit), baseNumbersMap.get(100), (result.isEmpty() ? "" : " " + result));
73+
result = String.format("%s %s%s", BASE_NUMBERS_MAP.get(hundredsDigit), BASE_NUMBERS_MAP.get(100), (result.isEmpty() ? "" : " " + result));
7174
}
7275

7376
return result;
@@ -77,7 +80,9 @@ private static String convertToWords(int number) {
7780
Only convert groups of three digit if they are non-zero
7881
*/
7982
public static String integerToEnglishWords(int number) {
80-
if (number == 0) return "Zero";
83+
if (number == 0) {
84+
return "Zero";
85+
}
8186

8287
StringBuilder result = new StringBuilder();
8388

@@ -92,10 +97,10 @@ public static String integerToEnglishWords(int number) {
9297

9398
if (!subResult.isEmpty()) {
9499
if (!result.isEmpty()) {
95-
result.insert(0, subResult + " " + thousandPowerMap.get(index) + " ");
100+
result.insert(0, subResult + " " + THOUSAND_POWER_MAP.get(index) + " ");
96101
} else {
97102
if (index > 0) {
98-
result = new StringBuilder(subResult + " " + thousandPowerMap.get(index));
103+
result = new StringBuilder(subResult + " " + THOUSAND_POWER_MAP.get(index));
99104
} else {
100105
result = new StringBuilder(subResult);
101106
}

0 commit comments

Comments
 (0)