Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java @ 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 | 17db08570637 |
children | 67e53dbe05d2 |
comparison
equal
deleted
inserted
replaced
8689:ea676691e533 | 8690:11c88a2f695a |
---|---|
117 | 117 |
118 | 118 |
119 protected void handleDataLine(String line) { | 119 protected void handleDataLine(String line) { |
120 String[] cols = line.split(SEPERATOR_CHAR); | 120 String[] cols = line.split(SEPERATOR_CHAR); |
121 | 121 |
122 if (cols.length < 14) { | 122 String parameter = cols[1].trim(); |
123 log.warn("skip invalid data line: '" + line + "'"); | 123 Double km = parseDouble(cols, 3); |
124 return; | 124 Double a = parseDouble(cols, 6); |
125 } | 125 Double b = parseDouble(cols, 7); |
126 | 126 Double qMax = parseDouble(cols, 8); |
127 Double km = parseDouble(cols[3], line); | 127 Double rSq = parseDouble(cols, 9); |
128 Double a = parseDouble(cols[6], line); | 128 Integer nTot = parseInteger(cols, 10); |
129 Double b = parseDouble(cols[7], line); | 129 Integer nOutlier = parseInteger(cols, 11); |
130 Double qMax = parseDouble(cols[8], line); | 130 Double cFer = parseDouble(cols, 12); |
131 Double rSq = parseDouble(cols[9], line); | 131 Double cDuan = parseDouble(cols, 13); |
132 Integer nTot = parseInteger(cols[10], line); | |
133 Integer nOutlier = parseInteger(cols[11], line); | |
134 Double cFer = parseDouble(cols[12], line); | |
135 Double cDuan = parseDouble(cols[13], line); | |
136 | 132 |
137 if (km == null || a == null || b == null | 133 if (km == null || a == null || b == null |
138 || qMax == null || cols[1].length() == 0 | 134 || qMax == null || parameter.length() == 0 |
139 ) { | 135 ) { |
140 if (km == null) { | 136 if (km == null) { |
141 log.error("No km for measurement station: Can not reference measurement station: " | 137 log.error("No km for measurement station: Can not reference measurement station: " |
142 + line); | 138 + line); |
143 } | 139 } |
144 if (a == null || b == null | 140 if (a == null || b == null |
145 || qMax == null || cols[1].length() == 0 | 141 || qMax == null || parameter.length() == 0 |
146 ) { | 142 ) { |
147 log.error("Incomplete SQ-relation row (missing a, b, Qmax or parameter): " | 143 log.error("Incomplete SQ-relation row (missing a, b, Qmax or parameter): " |
148 + line); | 144 + line); |
149 } | 145 } |
150 return; | 146 return; |
168 cDuan | 164 cDuan |
169 )); | 165 )); |
170 } | 166 } |
171 } | 167 } |
172 | 168 |
173 private Double parseDouble(String value, String line) { | 169 private Double parseDouble(String[] values, int idx) { |
174 Double result = null; | 170 if (idx >= 0 && idx < values.length && !values[idx].isEmpty()) { |
175 try { | 171 try { |
176 result = Double.valueOf(value.replace(",", ".")); | 172 return nf.parse(values[idx]).doubleValue(); |
173 } | |
174 catch (ParseException e) { | |
175 log.warn("Unparseable value '" + values[idx] + "'"); | |
176 } | |
177 } | 177 } |
178 catch (NumberFormatException nfe) { | 178 return null; |
179 log.warn("Unparseable " + value + " in sq relation row: " + line); | |
180 } | |
181 return result; | |
182 } | 179 } |
183 | 180 |
184 private Integer parseInteger(String value, String line) { | 181 private Integer parseInteger(String[] values, int idx) { |
185 Integer result = null; | 182 if (idx >= 0 && idx < values.length && !values[idx].isEmpty()) { |
186 try { | 183 try { |
187 result = Integer.valueOf(value); | 184 return nf.parse(values[idx]).intValue(); |
185 } | |
186 catch (ParseException e) { | |
187 log.warn("Unparseable value '" + values[idx] + "'"); | |
188 } | |
188 } | 189 } |
189 catch (NumberFormatException nfe) { | 190 return null; |
190 log.warn("Unparseable " + value + " in sq relation row: " + line); | |
191 } | |
192 return result; | |
193 } | 191 } |
194 } | 192 } |
195 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 193 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |