Mercurial > dive4elements > river
changeset 5233:37ff7c030ec9
WaterlevelDifferencesParser: Create ImportWsts directly.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 12 Mar 2013 09:39:53 +0100 |
parents | 11b2a0c55318 |
children | d1e24f26dee0 |
files | flys-backend/src/main/java/de/intevation/flys/importer/parsers/WaterlevelDifferencesParser.java |
diffstat | 1 files changed, 20 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- 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<ImportWaterlevelDifference> differences; + /** List of parsed differences as ImportWst s. */ + private List<ImportWst> differences; - private ImportWaterlevelDifferenceColumn[] columns; + private ImportWstColumn[] columns; - private ImportWaterlevelDifference current; + /** The currently processed dataset. */ + private ImportWst current; public WaterlevelDifferencesParser() { - differences = new ArrayList<ImportWaterlevelDifference>(); + differences = new ArrayList<ImportWst>(); } - public List<ImportWaterlevelDifference> getDifferences() { + /** Get the differences as wst parsed so far. */ + public List<ImportWst> getDifferences() { return differences; } public List<ImportWst> exportWsts() { - List<ImportWst> wsts = new ArrayList<ImportWst>(); - 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 + "'");