Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/parsers/PRFParser.java @ 5925:59f6a47822a4
PRFParser: Ignore skip-lines field, simplifies code a bit.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 08 May 2013 15:04:04 +0200 |
parents | 454b7b455cb6 |
children | 4d526e313fa0 |
comparison
equal
deleted
inserted
replaced
5924:454b7b455cb6 | 5925:59f6a47822a4 |
---|---|
83 } | 83 } |
84 | 84 |
85 /** | 85 /** |
86 * @param kmData where data points will be added to. | 86 * @param kmData where data points will be added to. |
87 * @param line Line to parse. | 87 * @param line Line to parse. |
88 * @return -1 at invalid lines, 1 if maxRepetitions values have been | |
89 * read, 0 otherwise. | |
90 */ | 88 */ |
91 public int extractData(String line, List<XY> kmData) { | 89 public void extractData(String line, List<XY> kmData) { |
92 int L = line.length(); | 90 int L = line.length(); |
93 if (L <= deleteChars) { | 91 if (L <= deleteChars) { |
94 return -1; | 92 return -1; |
95 } | 93 } |
96 | 94 |
115 try { | 113 try { |
116 x = Double.parseDouble(first); | 114 x = Double.parseDouble(first); |
117 y = Double.parseDouble(second); | 115 y = Double.parseDouble(second); |
118 } | 116 } |
119 catch (NumberFormatException nfe) { | 117 catch (NumberFormatException nfe) { |
120 // broken line -> substract from dataset skip | 118 // "Dummy" line to separate datasets, or missing values. |
121 return -1; | 119 log.debug("PRFParser: Broken line: " + line); |
120 return; | |
122 } | 121 } |
123 | 122 |
124 if (first.indexOf('.') < 0) { | 123 if (first.indexOf('.') < 0) { |
125 x /= firstShift; | 124 x /= firstShift; |
126 } | 125 } |
140 kmData.add(new XY(x, y, kmData.size())); | 139 kmData.add(new XY(x, y, kmData.size())); |
141 | 140 |
142 pos += firstIntegerPlaces + secondIntegerPlaces; | 141 pos += firstIntegerPlaces + secondIntegerPlaces; |
143 } | 142 } |
144 | 143 |
145 return rep == maxRepetitions ? 1 : 0; | 144 return; |
146 } | 145 } |
147 } // class DataFormat | 146 } // class DataFormat |
148 | 147 |
149 public static class KMFormat { | 148 public static class KMFormat { |
150 | 149 |
341 log.warn( | 340 log.warn( |
342 "PRF: line 5 is not an positive integer."); | 341 "PRF: line 5 is not an positive integer."); |
343 return false; | 342 return false; |
344 } | 343 } |
345 | 344 |
346 int skip = lineSkipCount; | |
347 | |
348 while ((line = in.readLine()) != null) { | 345 while ((line = in.readLine()) != null) { |
349 if (skip > 0) { | |
350 --skip; | |
351 continue; | |
352 } | |
353 double km; | 346 double km; |
354 try { | 347 try { |
355 km = kmFormat.extractKm(line); | 348 km = kmFormat.extractKm(line); |
356 } | 349 } |
357 catch (NumberFormatException iae) { | 350 catch (NumberFormatException iae) { |
367 //log.debug("found new km: " + station); | 360 //log.debug("found new km: " + station); |
368 kmData = new ArrayList<XY>(); | 361 kmData = new ArrayList<XY>(); |
369 data.put(station, kmData); | 362 data.put(station, kmData); |
370 } | 363 } |
371 | 364 |
372 int c = dataFormat.extractData(line, kmData); | 365 dataFormat.extractData(line, kmData); |
373 if (c < 1) { | |
374 skip = lineSkipCount + c; | |
375 } | |
376 } | 366 } |
377 | 367 |
378 // sort all the lists by x and index | 368 // sort all the lists by x and index |
379 sortLists(); | 369 sortLists(); |
380 } | 370 } |