Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/common/AbstractParser.java @ 8991:c43d8c1a4455
Parse via decimalformat instead of bigdecimal constructor (to cope with strings with chars after the actual number)
author | mschaefer |
---|---|
date | Tue, 10 Apr 2018 16:43:32 +0200 |
parents | 2693bfaf503d |
children | abe069eb180c |
comparison
equal
deleted
inserted
replaced
8990:07dcedddf839 | 8991:c43d8c1a4455 |
---|---|
15 import java.io.FilenameFilter; | 15 import java.io.FilenameFilter; |
16 import java.io.IOException; | 16 import java.io.IOException; |
17 import java.io.InputStreamReader; | 17 import java.io.InputStreamReader; |
18 import java.io.LineNumberReader; | 18 import java.io.LineNumberReader; |
19 import java.math.BigDecimal; | 19 import java.math.BigDecimal; |
20 import java.text.DecimalFormat; | |
20 import java.text.NumberFormat; | 21 import java.text.NumberFormat; |
21 import java.text.ParseException; | 22 import java.text.ParseException; |
22 import java.util.ArrayList; | 23 import java.util.ArrayList; |
23 import java.util.List; | 24 import java.util.List; |
24 import java.util.Locale; | 25 import java.util.Locale; |
71 | 72 |
72 private static final Pattern META_SUBGROUP = Pattern.compile("^##.*", Pattern.CASE_INSENSITIVE); | 73 private static final Pattern META_SUBGROUP = Pattern.compile("^##.*", Pattern.CASE_INSENSITIVE); |
73 | 74 |
74 private static NumberFormat numberFormat = NumberFormat.getInstance(Locale.ROOT); | 75 private static NumberFormat numberFormat = NumberFormat.getInstance(Locale.ROOT); |
75 | 76 |
77 private static DecimalFormat bigDecimalFormat; | |
78 | |
79 static { | |
80 bigDecimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ROOT); | |
81 bigDecimalFormat.setParseBigDecimal(true); | |
82 } | |
83 | |
76 /** | 84 /** |
77 * Path of the file or directory to import from | 85 * Path of the file or directory to import from |
78 */ | 86 */ |
79 protected final File importPath; | 87 protected final File importPath; |
80 | 88 |
263 } | 271 } |
264 | 272 |
265 /** | 273 /** |
266 * Parses a number string as a BigDecimal, replacing a comma with a dot first | 274 * Parses a number string as a BigDecimal, replacing a comma with a dot first |
267 */ | 275 */ |
268 public static BigDecimal parseDecimal(final String text) throws NumberFormatException { | 276 public static BigDecimal parseDecimal(final String text) throws ParseException { |
269 return new BigDecimal(text.replace(',', '.')); | 277 return (BigDecimal) bigDecimalFormat.parse(text.replace(',', '.')); |
270 } | 278 } |
271 | 279 |
272 /** | 280 /** |
273 * Gets the class's logger | 281 * Gets the class's logger |
274 */ | 282 */ |