66import java .util .HashMap ;
77import java .util .List ;
88
9-
109/**
1110 A Java-based utility for converting English word representations of numbers
1211 into their numeric form. This utility supports whole numbers, decimals,
@@ -112,8 +111,7 @@ public static String convert(String numberInWords) {
112111
113112 if (chunks .isEmpty () || isAdditionSafe (chunks .getLast (), nextChunk )) {
114113 chunks .add (nextChunk );
115- }
116- else {
114+ } else {
117115 return "Invalid Input. Unexpected Word: " + word ;
118116 }
119117 currentChunk = BigDecimal .ZERO ;
@@ -131,8 +129,7 @@ public static String convert(String numberInWords) {
131129
132130 if (currentChunkIsZero || isAdditionSafe (currentChunk , bigDecimalNumber )) {
133131 currentChunk = currentChunk .add (bigDecimalNumber );
134- }
135- else {
132+ } else {
136133 return "Invalid Input. Unexpected Word: " + word ;
137134 }
138135 continue ;
@@ -147,8 +144,7 @@ public static String convert(String numberInWords) {
147144 String decimalPart = convertDecimalPart (wordDeque );
148145 if (!decimalPart .startsWith ("I" )) {
149146 chunks .add (new BigDecimal (decimalPart ));
150- }
151- else {
147+ } else {
152148 return decimalPart ;
153149 }
154150 break ;
@@ -204,8 +200,7 @@ private static String convertDecimalPart(ArrayDeque<String> wordDeque) {
204200 Integer number = NUMBER_MAP .getOrDefault (word , null );
205201 if (number != null ) {
206202 decimalPart .append (number );
207- }
208- else {
203+ } else {
209204 return "Invalid Input. Unexpected Word (after Point): " + word ;
210205 }
211206 }
@@ -218,7 +213,9 @@ private static String convertDecimalPart(ArrayDeque<String> wordDeque) {
218213
219214 private static BigDecimal combineChunks (List <BigDecimal > chunks ) {
220215 BigDecimal completeNumber = BigDecimal .ZERO ;
221- for (BigDecimal chunk : chunks ) completeNumber = completeNumber .add (chunk );
216+ for (BigDecimal chunk : chunks ) {
217+ completeNumber = completeNumber .add (chunk );
218+ }
222219 return completeNumber ;
223220 }
224221
0 commit comments