Mercurial > dive4elements > river
changeset 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 | 11c88a2f695a |
files | backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java |
diffstat | 1 files changed, 18 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java Wed Apr 15 18:36:11 2015 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java Thu Apr 16 18:38:19 2015 +0200 @@ -383,6 +383,20 @@ return false; } + private Double parse(String []values, int idx, String msg) { + + if (idx >= 0 && idx < values.length && !values[idx].isEmpty()) { + try { + return nf.parse(values[idx]).doubleValue(); + } + catch (ParseException e) { + log.warn("BSP: unparseable " + msg + " '" + values[idx] + "'"); + } + } + + return null; + } + protected void handleDataLine(ImportBedHeight obj, String line) { String[] values = line.split(SEPERATOR_CHAR, 0); @@ -408,55 +422,13 @@ return; } - Double height = null; - if (values[1].length() > 0) { - try { - height = new Double(nf.parse(values[1]).doubleValue()); - } - catch (ParseException e) { - log.warn("BSP: unparseable height '" + values[1] + "'"); - } - } - - Double uncertainty = null; - if (values.length > 2 && values[2].length() > 0) { - try { - uncertainty = new Double(nf.parse(values[2]).doubleValue()); - } - catch (ParseException e) { - log.warn("BSP: unparseable uncertainty value '" - + values[2] + "'"); - } - } - - Double dataGap = null; - if (values.length > 3 && values[3].length() > 0) { - try { - dataGap = new Double(nf.parse(values[3]).doubleValue()); - } - catch (ParseException e) { - log.warn("BSP: unparseable data gap '" + values[3] + "'"); - } - } - - Double soundingWidth = null; - if (values.length > 4 && values[4].length() > 0) { - try { - soundingWidth = new Double(nf.parse(values[4]).doubleValue()); - } - catch (ParseException e) { - log.warn("BSP: unparseable sounding width '" + - values[4] + "'"); - } - } - ImportBedHeightValue value = new ImportBedHeightValue( (ImportBedHeight) obj, km, - height, - uncertainty, - dataGap, - soundingWidth); + parse(values, 1, "height"), + parse(values, 2, "uncertainty"), + parse(values, 3, "data gap"), + parse(values, 4, "sounding width")); obj.addValue(value); }