view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoCalculationResult.java @ 8980:b194fa64506a

SINFO - show results themes according to spec, either raw data or floating mean values. Some improvements to error handling and handling of empty results.
author gernotbelger
date Thu, 05 Apr 2018 18:30:34 +0200
parents a4f1ac81f26d
children 50cc99579a46
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 boolean isEmpty() {
        return this.rows.isEmpty();
    }

    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