view backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/FlowDepthColumnParser.java @ 8971:50416a0df385

Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
author mschaefer
date Tue, 03 Apr 2018 10:18:30 +0200
parents
children 31549fdfaf4f
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.importer.sinfo.parsers;

import java.io.File;

import org.apache.log4j.Logger;
import org.dive4elements.river.importer.ImportRiver;
import org.dive4elements.river.importer.common.AbstractParser;
import org.dive4elements.river.importer.common.ParsingState;
import org.dive4elements.river.importer.sinfo.importitem.FlowDepthColumnSeriesImport;
import org.dive4elements.river.importer.sinfo.importitem.FlowDepthKmLineImport;
import org.dive4elements.river.importer.sinfo.importitem.FlowDepthSeriesImport;
import org.dive4elements.river.model.sinfo.FlowDepthColumn;
import org.dive4elements.river.model.sinfo.FlowDepthValue;

/**
 * Reads and parses a column of a flow depth file
 *
 * @author Matthias Schäfer
 *
 */
public class FlowDepthColumnParser extends AbstractParser<FlowDepthColumn, FlowDepthValue, FlowDepthKmLineImport, FlowDepthColumnSeriesImport> {

    /***** FIELDS *****/

    private static final Logger log = Logger.getLogger(FlowDepthColumnParser.class);

    private final FlowDepthSeriesImport parent;

    private final int colIndex;

    private final String colName;


    /***** CONSTRUCTORS *****/

    public FlowDepthColumnParser(final File importPath, final File rootRelativePath, final ImportRiver river, final FlowDepthSeriesImport parent,
            final int colIndex,
            final String colName) {
        super(importPath, rootRelativePath, river);
        this.parent = parent;
        this.colIndex = colIndex;
        this.colName = colName;
    }


    /***** METHODS *****/

    @Override
    protected Logger getLog() {
        return log;
    }

    @Override
    protected void logStartInfo() {
        getLog().info(String.format("Start parsing column %d '%s':;'%s'", this.colIndex, this.colName, this.rootRelativePath));
    }

    @Override
    protected boolean handleMetaOther() {
        this.headerParsingState = ParsingState.IGNORE;
        return false;
    }

    @Override
    protected FlowDepthColumnSeriesImport createSeriesImport(final String filename) {
        return new FlowDepthColumnSeriesImport(filename, this.parent, this.colName, this.rootRelativePath);
    }

    @Override
    protected FlowDepthKmLineImport createKmLineImport(final Double km, final String[] values) {
        final double tkheight = parseDoubleWithNull(values[this.colIndex]).doubleValue();
        return new FlowDepthKmLineImport(km, tkheight);
    }
}

http://dive4elements.wald.intevation.org