view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoCalculationResult.java @ 8948:a4f1ac81f26d

Work on SINFO-FlowDepthMinMax. Also rework of result row stuff, in order to reduce abstraction, using result type concept
author gernotbelger
date Wed, 14 Mar 2018 14:10:32 +0100
parents 5d5d482da3e9
children b194fa64506a
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.artifacts.sinfo.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.dive4elements.river.artifacts.sinfo.util.WstInfo;

import gnu.trove.TDoubleArrayList;

/**
 * @author Gernot Belger
 */
public abstract class AbstractSInfoCalculationResult implements Serializable {

    private static final long serialVersionUID = 1L;

    private final Collection<SInfoResultRow> rows;

    private final String label;

    private final WstInfo wst;

    public AbstractSInfoCalculationResult(final String label, final WstInfo wst, final Collection<SInfoResultRow> rows) {
        this.label = label;
        this.wst = wst;
        this.rows = new ArrayList<>(rows);
    }

    public final String getLabel() {
        return this.label;
    }

    public final WstInfo getWst() {
        return this.wst;
    }

    public final void addRow(final SInfoResultRow resultRow) {
        this.rows.add(resultRow);
    }

    public final Collection<SInfoResultRow> getRows() {
        return Collections.unmodifiableCollection(this.rows);
    }

    public final double[][] getStationPoints(final SInfoResultType type) {

        final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
        final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());

        for (final SInfoResultRow row : this.rows) {

            final double station = row.getDoubleValue(SInfoResultType.station);
            final double value = row.getDoubleValue(type);

            xPoints.add(station);
            yPoints.add(value);
        }

        return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
    }

    protected final <TYPE> List<TYPE> getValues(final SInfoResultType type) {

        final List<TYPE> values = new ArrayList<>();

        for (final SInfoResultRow row : this.rows) {
            @SuppressWarnings("unchecked")
            final TYPE value = (TYPE) row.getValue(type);
            values.add(value);
        }

        return values;
    }
}

http://dive4elements.wald.intevation.org