Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityModelParser.java @ 5707:53134ccc4a64
Backend: Import Flow Velocity Model: Use unique km for station.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 15 Apr 2013 15:45:18 +0200 |
parents | a3f7da9bf0d1 |
children | e8469247dc6b |
comparison
equal
deleted
inserted
replaced
5706:8a198db28de0 | 5707:53134ccc4a64 |
---|---|
6 import java.math.BigDecimal; | 6 import java.math.BigDecimal; |
7 import java.text.NumberFormat; | 7 import java.text.NumberFormat; |
8 import java.text.ParseException; | 8 import java.text.ParseException; |
9 import java.util.ArrayList; | 9 import java.util.ArrayList; |
10 import java.util.List; | 10 import java.util.List; |
11 import java.util.TreeSet; | |
11 import java.util.regex.Matcher; | 12 import java.util.regex.Matcher; |
12 import java.util.regex.Pattern; | 13 import java.util.regex.Pattern; |
13 | 14 |
14 import org.apache.log4j.Logger; | 15 import org.apache.log4j.Logger; |
15 | 16 |
16 import de.intevation.flys.importer.ImportDischargeZone; | 17 import de.intevation.flys.importer.ImportDischargeZone; |
17 import de.intevation.flys.importer.ImportFlowVelocityModel; | 18 import de.intevation.flys.importer.ImportFlowVelocityModel; |
18 import de.intevation.flys.importer.ImportFlowVelocityModelValue; | 19 import de.intevation.flys.importer.ImportFlowVelocityModelValue; |
20 import de.intevation.flys.utils.EpsilonComparator; | |
19 | 21 |
20 | 22 |
21 public class FlowVelocityModelParser extends LineParser { | 23 public class FlowVelocityModelParser extends LineParser { |
22 | 24 |
23 private static final Logger log = | 25 private static final Logger log = |
52 | 54 |
53 private ImportFlowVelocityModel current; | 55 private ImportFlowVelocityModel current; |
54 | 56 |
55 protected String description; | 57 protected String description; |
56 | 58 |
59 protected TreeSet<Double> kmExists; | |
60 | |
57 | 61 |
58 public FlowVelocityModelParser() { | 62 public FlowVelocityModelParser() { |
59 models = new ArrayList<ImportFlowVelocityModel>(); | 63 models = new ArrayList<ImportFlowVelocityModel>(); |
64 kmExists = new TreeSet<Double>(EpsilonComparator.CMP); | |
60 } | 65 } |
61 | 66 |
62 | 67 |
63 public List<ImportFlowVelocityModel> getModels() { | 68 public List<ImportFlowVelocityModel> getModels() { |
64 return models; | 69 return models; |
229 log.warn("skip invalid data line: '" + line + "'"); | 234 log.warn("skip invalid data line: '" + line + "'"); |
230 return; | 235 return; |
231 } | 236 } |
232 | 237 |
233 try { | 238 try { |
234 double km = nf.parse(cols[0]).doubleValue(); | 239 double km = nf.parse(cols[0]).doubleValue(); |
240 | |
241 Double key = Double.valueOf(km); | |
242 | |
243 if (kmExists.contains(key)) { | |
244 log.warn("duplicate stattion '" + km + "': -> ignored"); | |
245 return; | |
246 } | |
247 | |
235 double q = nf.parse(cols[1]).doubleValue(); | 248 double q = nf.parse(cols[1]).doubleValue(); |
236 double total = nf.parse(cols[2]).doubleValue(); | 249 double total = nf.parse(cols[2]).doubleValue(); |
237 double main = nf.parse(cols[3]).doubleValue(); | 250 double main = nf.parse(cols[3]).doubleValue(); |
238 double stress = nf.parse(cols[4]).doubleValue(); | 251 double stress = nf.parse(cols[4]).doubleValue(); |
239 | 252 |
242 new BigDecimal(q), | 255 new BigDecimal(q), |
243 new BigDecimal(total), | 256 new BigDecimal(total), |
244 new BigDecimal(main), | 257 new BigDecimal(main), |
245 new BigDecimal(stress) | 258 new BigDecimal(stress) |
246 )); | 259 )); |
260 | |
261 kmExists.add(key); | |
247 } | 262 } |
248 catch (ParseException pe) { | 263 catch (ParseException pe) { |
249 log.warn("Unparseable flow velocity values:", pe); | 264 log.warn("Unparseable flow velocity values:", pe); |
250 } | 265 } |
251 } | 266 } |