# HG changeset patch # User Felix Wolfsteller # Date 1363077593 -3600 # Node ID 37ff7c030ec9c0e52d08716b335e8f5d5e7a20cd # Parent 11b2a0c55318abdde0fb6cc287a5ca987ac7c279 WaterlevelDifferencesParser: Create ImportWsts directly. diff -r 11b2a0c55318 -r 37ff7c030ec9 flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java Mon Mar 11 15:10:11 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java Tue Mar 12 09:39:53 2013 +0100 @@ -35,55 +35,34 @@ public static final Pattern META_UNIT = Pattern.compile("^Einheit: \\[(.*)\\].*"); - private List differences; + /** List of parsed differences as ImportWst s. */ + private List differences; - private ImportWaterlevelDifferenceColumn[] columns; + private ImportWstColumn[] columns; - private ImportWaterlevelDifference current; + /** The currently processed dataset. */ + private ImportWst current; public WaterlevelDifferencesParser() { - differences = new ArrayList(); + differences = new ArrayList(); } - public List getDifferences() { + /** Get the differences as wst parsed so far. */ + public List getDifferences() { return differences; } public List exportWsts() { - List wsts = new ArrayList(); - for(ImportWaterlevelDifference waterlevel: getDifferences()) { - String description = waterlevel.getDescription(); - ImportWst wst = new ImportWst(); - wsts.add(wst); - wst.setDescription(description); - // Fixation kind. - wst.setKind(7); - wst.setUnit(waterlevel.getUnit()); - wst.setNumberColumns(waterlevel.getColumns().size()); - - int i = 0; - for (ImportWaterlevelDifferenceColumn wdc: waterlevel.getColumns()) { - ImportWstColumn column = wst.getColumn(i); - column.setDescription(wdc.getDescription()); - column.setName(wdc.getDescription()); - column.setPosition(i); - for (ImportWaterlevelDifferenceValue val: wdc.getValues()) { - column.addColumnValue(BigDecimal.valueOf(val.getStation()), - BigDecimal.valueOf(val.getValue())); - - } - i++; - } - } - return wsts; + return differences; } @Override public void parse(File file) throws IOException { - current = new ImportWaterlevelDifference(file.getName()); + current = new ImportWst(file.getName()); + current.setKind(7); super.parse(file); } @@ -97,8 +76,10 @@ @Override protected void finish() { if (columns != null && current != null) { - for (ImportWaterlevelDifferenceColumn col: columns) { - current.addValue(col); + // TODO figure out if its needed, as the columns + // are registered at their construction time. + for (ImportWstColumn col: columns) { + // TODO place a current.addColumn(col); here? } differences.add(current); @@ -165,13 +146,13 @@ private void initColumns(String[] cols) { - columns = new ImportWaterlevelDifferenceColumn[cols.length]; + columns = new ImportWstColumn[cols.length]; for (int i = 0; i < cols.length; i++) { String name = cols[i].replace("\"", ""); log.debug("Create new column '" + name + "'"); - columns[i] = new ImportWaterlevelDifferenceColumn(name); + columns[i] = new ImportWstColumn(current, name, name, i); } } @@ -198,10 +179,9 @@ String value = cols[idx]; try { - columns[i].addValue(new ImportWaterlevelDifferenceValue( - station, - nf.parse(value).doubleValue() - )); + columns[i].addColumnValue( + new BigDecimal(station), + new BigDecimal(nf.parse(value).doubleValue())); } catch (ParseException pe) { log.warn("Error while parsing value: '" + value + "'");