comparison backend/src/main/java/org/dive4elements/river/importer/common/AbstractParser.java @ 9012:abe069eb180c

Import of vegetation zones added
author mschaefer
date Wed, 18 Apr 2018 07:43:55 +0200
parents c43d8c1a4455
children 4c5eeaff554c
comparison
equal deleted inserted replaced
9011:a44200bf0547 9012:abe069eb180c
80 bigDecimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ROOT); 80 bigDecimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ROOT);
81 bigDecimalFormat.setParseBigDecimal(true); 81 bigDecimalFormat.setParseBigDecimal(true);
82 } 82 }
83 83
84 /** 84 /**
85 * How the km column and its content are expected
86 */
87 protected enum KmMode {
88 NONE, UNIQUE, DUPLICATES
89 }
90
91 /**
85 * Path of the file or directory to import from 92 * Path of the file or directory to import from
86 */ 93 */
87 protected final File importPath; 94 protected final File importPath;
88 95
89 /** 96 /**
380 return true; 387 return true;
381 } 388 }
382 return false; 389 return false;
383 } 390 }
384 391
385 private void handleDataLine() { 392 /**
393 * Parses a values line and adds the values record
394 */
395 protected void handleDataLine() {
386 final String[] values = this.currentLine.split(SEPARATOR_CHAR, 0); 396 final String[] values = this.currentLine.split(SEPARATOR_CHAR, 0);
387 // Skip import line without data or only km 397 // Skip import line without data or only km
388 if (values.length < 2) 398 if (values.length < 2)
389 return; 399 return;
390 Double km; 400 Double km = Double.NaN;
391 try { 401 if (kmMode() != KmMode.NONE) {
392 km = Double.valueOf(parseDouble(values[0]).doubleValue()); 402 try {
393 if (kmMustBeUnique()) { 403 km = Double.valueOf(parseDouble(values[0]).doubleValue());
394 if (this.kmExists.contains(km)) { 404 if (kmMode() == KmMode.UNIQUE) {
395 logWarning("Ignoring duplicate station '" + values[0] + "' in line " + this.in.getLineNumber()); 405 if (this.kmExists.contains(km)) {
396 return; 406 logWarning("Ignoring duplicate station '" + values[0] + "' in line " + this.in.getLineNumber());
407 return;
408 }
409 this.kmExists.add(km);
397 } 410 }
398 this.kmExists.add(km); 411 }
399 } 412 catch (final Exception e) {
400 } 413 logError("Not parseable km in line " + this.in.getLineNumber() + ": " + e.getMessage());
401 catch (final Exception e) { 414 return;
402 logError("Not parseable km in line " + this.in.getLineNumber() + ": " + e.getMessage()); 415 }
403 return;
404 } 416 }
405 final KMLINE value = createKmLineImport(km, values); 417 final KMLINE value = createKmLineImport(km, values);
406 if (value != null) 418 if (value != null)
407 this.seriesHeader.addValue(value); 419 this.seriesHeader.addValue(value);
408 } 420 }
409 421
410 /** 422 /**
411 * Whether {@link handleDataLine} shall check for and reject km duplicates 423 * How {@link handleDataLine} shall handle the km column (if any)
412 */ 424 */
413 protected boolean kmMustBeUnique() { 425 protected KmMode kmMode() {
414 return true; 426 return KmMode.UNIQUE;
415 } 427 }
416 428
417 /** 429 /**
418 * Creates a value import item with the km and other fields of the current line; 430 * Creates a value import item with the km and other fields of the current line;
419 * the km has been validated 431 * the km has been validated

http://dive4elements.wald.intevation.org