6
6
import java .util .HashMap ;
7
7
import java .util .List ;
8
8
9
-
10
9
/**
11
10
A Java-based utility for converting English word representations of numbers
12
11
into their numeric form. This utility supports whole numbers, decimals,
@@ -112,8 +111,7 @@ public static String convert(String numberInWords) {
112
111
113
112
if (chunks .isEmpty () || isAdditionSafe (chunks .getLast (), nextChunk )) {
114
113
chunks .add (nextChunk );
115
- }
116
- else {
114
+ } else {
117
115
return "Invalid Input. Unexpected Word: " + word ;
118
116
}
119
117
currentChunk = BigDecimal .ZERO ;
@@ -131,8 +129,7 @@ public static String convert(String numberInWords) {
131
129
132
130
if (currentChunkIsZero || isAdditionSafe (currentChunk , bigDecimalNumber )) {
133
131
currentChunk = currentChunk .add (bigDecimalNumber );
134
- }
135
- else {
132
+ } else {
136
133
return "Invalid Input. Unexpected Word: " + word ;
137
134
}
138
135
continue ;
@@ -147,8 +144,7 @@ public static String convert(String numberInWords) {
147
144
String decimalPart = convertDecimalPart (wordDeque );
148
145
if (!decimalPart .startsWith ("I" )) {
149
146
chunks .add (new BigDecimal (decimalPart ));
150
- }
151
- else {
147
+ } else {
152
148
return decimalPart ;
153
149
}
154
150
break ;
@@ -204,8 +200,7 @@ private static String convertDecimalPart(ArrayDeque<String> wordDeque) {
204
200
Integer number = NUMBER_MAP .getOrDefault (word , null );
205
201
if (number != null ) {
206
202
decimalPart .append (number );
207
- }
208
- else {
203
+ } else {
209
204
return "Invalid Input. Unexpected Word (after Point): " + word ;
210
205
}
211
206
}
@@ -218,7 +213,9 @@ private static String convertDecimalPart(ArrayDeque<String> wordDeque) {
218
213
219
214
private static BigDecimal combineChunks (List <BigDecimal > chunks ) {
220
215
BigDecimal completeNumber = BigDecimal .ZERO ;
221
- for (BigDecimal chunk : chunks ) completeNumber = completeNumber .add (chunk );
216
+ for (BigDecimal chunk : chunks ) {
217
+ completeNumber = completeNumber .add (chunk );
218
+ }
222
219
return completeNumber ;
223
220
}
224
221
0 commit comments