comparison backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java @ 8559:6d8d7425a6b5

Bed heights are just bed heights since a while ('single' is obsolete).
author "Tom Gottfried <tom@intevation.de>"
date Mon, 16 Feb 2015 11:08:33 +0100
parents 29ab66ce06aa
children 6fcf4717605f
comparison
equal deleted inserted replaced
8558:d0ea092a32f5 8559:6d8d7425a6b5
29 import java.io.FileInputStream; 29 import java.io.FileInputStream;
30 import java.io.InputStreamReader; 30 import java.io.InputStreamReader;
31 31
32 import org.apache.log4j.Logger; 32 import org.apache.log4j.Logger;
33 33
34 import org.dive4elements.river.importer.ImportBedHeightSingle; 34 import org.dive4elements.river.importer.ImportBedHeight;
35 import org.dive4elements.river.importer.ImportBedHeightSingleValue; 35 import org.dive4elements.river.importer.ImportBedHeightValue;
36 import org.dive4elements.river.importer.ImportBedHeightType; 36 import org.dive4elements.river.importer.ImportBedHeightType;
37 import org.dive4elements.river.importer.ImportElevationModel; 37 import org.dive4elements.river.importer.ImportElevationModel;
38 import org.dive4elements.river.importer.ImportLocationSystem; 38 import org.dive4elements.river.importer.ImportLocationSystem;
39 import org.dive4elements.river.importer.ImportRange; 39 import org.dive4elements.river.importer.ImportRange;
40 import org.dive4elements.river.importer.ImportTimeInterval; 40 import org.dive4elements.river.importer.ImportTimeInterval;
88 88
89 89
90 protected static NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); 90 protected static NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE);
91 91
92 92
93 protected List<ImportBedHeightSingle> bedHeights; 93 protected List<ImportBedHeight> bedHeights;
94 94
95 95
96 protected ImportBedHeightSingle newImportBedHeight(String description) { 96 protected ImportBedHeight newImportBedHeight(String description) {
97 return new ImportBedHeightSingle(description); 97 return new ImportBedHeight(description);
98 } 98 }
99 99
100 100
101 protected TreeSet<Double> kmExists; 101 protected TreeSet<Double> kmExists;
102 102
103 public BedHeightParser() { 103 public BedHeightParser() {
104 bedHeights = new ArrayList<ImportBedHeightSingle>(); 104 bedHeights = new ArrayList<ImportBedHeight>();
105 kmExists = new TreeSet<Double>(EpsilonComparator.CMP); 105 kmExists = new TreeSet<Double>(EpsilonComparator.CMP);
106 } 106 }
107 107
108 108
109 public List<ImportBedHeightSingle> getBedHeights() { 109 public List<ImportBedHeight> getBedHeights() {
110 return bedHeights; 110 return bedHeights;
111 } 111 }
112 112
113 113
114 public void parse(File file) throws IOException { 114 public void parse(File file) throws IOException {
115 log.info("Parsing bed height single file '" + file + "'"); 115 log.info("Parsing bed height single file '" + file + "'");
116 116
117 ImportBedHeightSingle obj = newImportBedHeight(file.getName().replaceAll("\\.csv", "")); 117 ImportBedHeight obj = newImportBedHeight(file.getName().replaceAll("\\.csv", ""));
118 118
119 kmExists.clear(); 119 kmExists.clear();
120 120
121 LineNumberReader in = null; 121 LineNumberReader in = null;
122 try { 122 try {
160 return tmp; 160 return tmp;
161 } 161 }
162 } 162 }
163 163
164 164
165 protected void handleMetaLine(ImportBedHeightSingle obj, String line) { 165 protected void handleMetaLine(ImportBedHeight obj, String line) {
166 String meta = stripMetaLine(line); 166 String meta = stripMetaLine(line);
167 167
168 if (handleMetaYear(obj, meta)) { 168 if (handleMetaYear(obj, meta)) {
169 return; 169 return;
170 } 170 }
199 log.warn("BHP: Meta line did not match any known type: " + line); 199 log.warn("BHP: Meta line did not match any known type: " + line);
200 } 200 }
201 } 201 }
202 202
203 203
204 protected boolean handleMetaYear(ImportBedHeightSingle obj, String line) { 204 protected boolean handleMetaYear(ImportBedHeight obj, String line) {
205 Matcher m = META_YEAR.matcher(line); 205 Matcher m = META_YEAR.matcher(line);
206 206
207 if (m.matches()) { 207 if (m.matches()) {
208 String tmp = m.group(1); 208 String tmp = m.group(1);
209 if (tmp.length() > 0) { 209 if (tmp.length() > 0) {
217 217
218 return false; 218 return false;
219 } 219 }
220 220
221 221
222 protected boolean handleMetaTimeInterval(ImportBedHeightSingle obj, String line) { 222 protected boolean handleMetaTimeInterval(ImportBedHeight obj, String line) {
223 Matcher m = META_TIMEINTERVAL.matcher(line); 223 Matcher m = META_TIMEINTERVAL.matcher(line);
224 224
225 if (m.matches()) { 225 if (m.matches()) {
226 String lo = m.group(1); 226 String lo = m.group(1);
227 String up = m.group(2); 227 String up = m.group(2);
246 246
247 return false; 247 return false;
248 } 248 }
249 249
250 250
251 protected boolean handleMetaSoundingWidth(ImportBedHeightSingle obj, String line) { 251 protected boolean handleMetaSoundingWidth(ImportBedHeight obj, String line) {
252 Matcher m = META_SOUNDING_WIDTH.matcher(line); 252 Matcher m = META_SOUNDING_WIDTH.matcher(line);
253 253
254 if (m.matches()) { 254 if (m.matches()) {
255 String tmp = m.group(1); 255 String tmp = m.group(1);
256 256
268 268
269 return false; 269 return false;
270 } 270 }
271 271
272 272
273 protected boolean handleMetaComment(ImportBedHeightSingle obj, String line) { 273 protected boolean handleMetaComment(ImportBedHeight obj, String line) {
274 Matcher m = META_COMMENTS.matcher(line); 274 Matcher m = META_COMMENTS.matcher(line);
275 275
276 if (m.matches()) { 276 if (m.matches()) {
277 String tmp = m.group(1); 277 String tmp = m.group(1);
278 278
284 return false; 284 return false;
285 } 285 }
286 286
287 287
288 protected boolean handleMetaEvaluationBy( 288 protected boolean handleMetaEvaluationBy(
289 ImportBedHeightSingle obj, 289 ImportBedHeight obj,
290 String line 290 String line
291 ) { 291 ) {
292 Matcher m = META_EVALUATION_BY.matcher(line); 292 Matcher m = META_EVALUATION_BY.matcher(line);
293 293
294 if (m.matches()) { 294 if (m.matches()) {
302 302
303 return false; 303 return false;
304 } 304 }
305 305
306 306
307 protected boolean handleMetaRange(ImportBedHeightSingle obj, String line) { 307 protected boolean handleMetaRange(ImportBedHeight obj, String line) {
308 Matcher m = META_RANGE.matcher(line); 308 Matcher m = META_RANGE.matcher(line);
309 309
310 if (m.matches() && m.groupCount() >= 2) { 310 if (m.matches() && m.groupCount() >= 2) {
311 String a = m.group(1).replace(";", ""); 311 String a = m.group(1).replace(";", "");
312 String b = m.group(2).replace(";", ""); 312 String b = m.group(2).replace(";", "");
326 326
327 return false; 327 return false;
328 } 328 }
329 329
330 330
331 protected boolean handleMetaType(ImportBedHeightSingle obj, String line) { 331 protected boolean handleMetaType(ImportBedHeight obj, String line) {
332 Matcher m = META_TYPE.matcher(line); 332 Matcher m = META_TYPE.matcher(line);
333 333
334 if (m.matches()) { 334 if (m.matches()) {
335 String tmp = m.group(1).replace(";", "").trim(); 335 String tmp = m.group(1).replace(";", "").trim();
336 336
349 return false; 349 return false;
350 } 350 }
351 351
352 352
353 protected boolean handleMetaLocationSystem( 353 protected boolean handleMetaLocationSystem(
354 ImportBedHeightSingle obj, 354 ImportBedHeight obj,
355 String line 355 String line
356 ) { 356 ) {
357 Matcher m = META_LOCATION_SYSTEM.matcher(line); 357 Matcher m = META_LOCATION_SYSTEM.matcher(line);
358 358
359 if (m.matches()) { 359 if (m.matches()) {
367 return false; 367 return false;
368 } 368 }
369 369
370 370
371 protected boolean handleMetaCurElevationModel( 371 protected boolean handleMetaCurElevationModel(
372 ImportBedHeightSingle obj, 372 ImportBedHeight obj,
373 String line 373 String line
374 ) { 374 ) {
375 Matcher m = META_CUR_ELEVATION_SYSTEM.matcher(line); 375 Matcher m = META_CUR_ELEVATION_SYSTEM.matcher(line);
376 376
377 if (m.matches()) { 377 if (m.matches()) {
390 return false; 390 return false;
391 } 391 }
392 392
393 393
394 protected boolean handleMetaOldElevationModel( 394 protected boolean handleMetaOldElevationModel(
395 ImportBedHeightSingle obj, 395 ImportBedHeight obj,
396 String line 396 String line
397 ) { 397 ) {
398 Matcher m = META_OLD_ELEVATION_SYSTEM.matcher(line); 398 Matcher m = META_OLD_ELEVATION_SYSTEM.matcher(line);
399 399
400 if (m.matches()) { 400 if (m.matches()) {
411 } 411 }
412 412
413 return false; 413 return false;
414 } 414 }
415 415
416 protected void handleDataLine(ImportBedHeightSingle obj, String line) { 416 protected void handleDataLine(ImportBedHeight obj, String line) {
417 String[] values = line.split(SEPERATOR_CHAR, -1); 417 String[] values = line.split(SEPERATOR_CHAR, -1);
418 418
419 if (values == null) { 419 if (values == null) {
420 log.warn("BSP: Error while parsing data line: '" + line + "'"); 420 log.warn("BSP: Error while parsing data line: '" + line + "'");
421 return; 421 return;
489 catch (ParseException e) { 489 catch (ParseException e) {
490 log.warn("BSP: unparseable sounding width " + values[4]); 490 log.warn("BSP: unparseable sounding width " + values[4]);
491 } 491 }
492 } 492 }
493 493
494 ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( 494 ImportBedHeightValue value = new ImportBedHeightValue(
495 (ImportBedHeightSingle) obj, 495 (ImportBedHeight) obj,
496 km, 496 km,
497 height, 497 height,
498 uncertainty, 498 uncertainty,
499 dataGap, 499 dataGap,
500 soundingWidth); 500 soundingWidth);

http://dive4elements.wald.intevation.org