comparison backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java @ 8689:ea676691e533

(issue1763) Reduce code-duplication (patch by Sascha Teichmann).
author Tom Gottfried <tom@intevation.de>
date Thu, 16 Apr 2015 18:38:19 +0200
parents e1186c5ab169
children 5e38e2924c07
comparison
equal deleted inserted replaced
8688:e1186c5ab169 8689:ea676691e533
381 } 381 }
382 382
383 return false; 383 return false;
384 } 384 }
385 385
386 private Double parse(String []values, int idx, String msg) {
387
388 if (idx >= 0 && idx < values.length && !values[idx].isEmpty()) {
389 try {
390 return nf.parse(values[idx]).doubleValue();
391 }
392 catch (ParseException e) {
393 log.warn("BSP: unparseable " + msg + " '" + values[idx] + "'");
394 }
395 }
396
397 return null;
398 }
399
386 protected void handleDataLine(ImportBedHeight obj, String line) { 400 protected void handleDataLine(ImportBedHeight obj, String line) {
387 String[] values = line.split(SEPERATOR_CHAR, 0); 401 String[] values = line.split(SEPERATOR_CHAR, 0);
388 402
389 if (values.length < 2) { 403 if (values.length < 2) {
390 // Do not import line without data or only km 404 // Do not import line without data or only km
406 log.error("Error parsing km '" + values[0] + "': " + 420 log.error("Error parsing km '" + values[0] + "': " +
407 e.getMessage()); 421 e.getMessage());
408 return; 422 return;
409 } 423 }
410 424
411 Double height = null;
412 if (values[1].length() > 0) {
413 try {
414 height = new Double(nf.parse(values[1]).doubleValue());
415 }
416 catch (ParseException e) {
417 log.warn("BSP: unparseable height '" + values[1] + "'");
418 }
419 }
420
421 Double uncertainty = null;
422 if (values.length > 2 && values[2].length() > 0) {
423 try {
424 uncertainty = new Double(nf.parse(values[2]).doubleValue());
425 }
426 catch (ParseException e) {
427 log.warn("BSP: unparseable uncertainty value '"
428 + values[2] + "'");
429 }
430 }
431
432 Double dataGap = null;
433 if (values.length > 3 && values[3].length() > 0) {
434 try {
435 dataGap = new Double(nf.parse(values[3]).doubleValue());
436 }
437 catch (ParseException e) {
438 log.warn("BSP: unparseable data gap '" + values[3] + "'");
439 }
440 }
441
442 Double soundingWidth = null;
443 if (values.length > 4 && values[4].length() > 0) {
444 try {
445 soundingWidth = new Double(nf.parse(values[4]).doubleValue());
446 }
447 catch (ParseException e) {
448 log.warn("BSP: unparseable sounding width '" +
449 values[4] + "'");
450 }
451 }
452
453 ImportBedHeightValue value = new ImportBedHeightValue( 425 ImportBedHeightValue value = new ImportBedHeightValue(
454 (ImportBedHeight) obj, 426 (ImportBedHeight) obj,
455 km, 427 km,
456 height, 428 parse(values, 1, "height"),
457 uncertainty, 429 parse(values, 2, "uncertainty"),
458 dataGap, 430 parse(values, 3, "data gap"),
459 soundingWidth); 431 parse(values, 4, "sounding width"));
460 432
461 obj.addValue(value); 433 obj.addValue(value);
462 } 434 }
463 } 435 }
464 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 436 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org