Mercurial > dive4elements > river
changeset 8690:11c88a2f695a
Handle empty strings as missing values without warning when parsing SQ-relations.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 17 Apr 2015 14:50:08 +0200 |
parents | ea676691e533 |
children | bfca77cbf353 |
files | backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java |
diffstat | 1 files changed, 30 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java Thu Apr 16 18:38:19 2015 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java Fri Apr 17 14:50:08 2015 +0200 @@ -119,30 +119,26 @@ protected void handleDataLine(String line) { String[] cols = line.split(SEPERATOR_CHAR); - if (cols.length < 14) { - log.warn("skip invalid data line: '" + line + "'"); - return; - } - - Double km = parseDouble(cols[3], line); - Double a = parseDouble(cols[6], line); - Double b = parseDouble(cols[7], line); - Double qMax = parseDouble(cols[8], line); - Double rSq = parseDouble(cols[9], line); - Integer nTot = parseInteger(cols[10], line); - Integer nOutlier = parseInteger(cols[11], line); - Double cFer = parseDouble(cols[12], line); - Double cDuan = parseDouble(cols[13], line); + String parameter = cols[1].trim(); + Double km = parseDouble(cols, 3); + Double a = parseDouble(cols, 6); + Double b = parseDouble(cols, 7); + Double qMax = parseDouble(cols, 8); + Double rSq = parseDouble(cols, 9); + Integer nTot = parseInteger(cols, 10); + Integer nOutlier = parseInteger(cols, 11); + Double cFer = parseDouble(cols, 12); + Double cDuan = parseDouble(cols, 13); if (km == null || a == null || b == null - || qMax == null || cols[1].length() == 0 + || qMax == null || parameter.length() == 0 ) { if (km == null) { log.error("No km for measurement station: Can not reference measurement station: " + line); } if (a == null || b == null - || qMax == null || cols[1].length() == 0 + || qMax == null || parameter.length() == 0 ) { log.error("Incomplete SQ-relation row (missing a, b, Qmax or parameter): " + line); @@ -170,26 +166,28 @@ } } - private Double parseDouble(String value, String line) { - Double result = null; - try { - result = Double.valueOf(value.replace(",", ".")); + private Double parseDouble(String[] values, int idx) { + if (idx >= 0 && idx < values.length && !values[idx].isEmpty()) { + try { + return nf.parse(values[idx]).doubleValue(); + } + catch (ParseException e) { + log.warn("Unparseable value '" + values[idx] + "'"); + } } - catch (NumberFormatException nfe) { - log.warn("Unparseable " + value + " in sq relation row: " + line); - } - return result; + return null; } - private Integer parseInteger(String value, String line) { - Integer result = null; - try { - result = Integer.valueOf(value); + private Integer parseInteger(String[] values, int idx) { + if (idx >= 0 && idx < values.length && !values[idx].isEmpty()) { + try { + return nf.parse(values[idx]).intValue(); + } + catch (ParseException e) { + log.warn("Unparseable value '" + values[idx] + "'"); + } } - catch (NumberFormatException nfe) { - log.warn("Unparseable " + value + " in sq relation row: " + line); - } - return result; + return null; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :