view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQDay.java @ 724:90ee95945684

#164 Create the items for the adapted WQ state with range information for W and Q. flys-artifacts/trunk@2207 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 22 Jun 2011 14:47:22 +0000
parents eab5e5089d77
children 11e9489eb1a7
line wrap: on
line source
package de.intevation.flys.artifacts.model;

import java.io.Serializable;

import gnu.trove.TDoubleArrayList;
import gnu.trove.TIntArrayList;


/**
 * This class represents a pool of data triples that consists of 'W', 'Q' and
 * 'Day' data.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class WQDay implements Serializable {

    protected TIntArrayList days;

    protected TDoubleArrayList ws;

    protected TDoubleArrayList qs;


    public WQDay() {
        days = new TIntArrayList();
        ws   = new TDoubleArrayList();
        qs   = new TDoubleArrayList();
    }


    public WQDay(int capacity) {
        days = new TIntArrayList(capacity);
        ws   = new TDoubleArrayList(capacity);
        qs   = new TDoubleArrayList(capacity);
    }

    public WQDay(int [] days, double [] ws, double [] qs) {
        this.days = new TIntArrayList(days);
        this.ws   = new TDoubleArrayList(ws);
        this.qs   = new TDoubleArrayList(qs);
    }


    public void add(int day, double w, double q) {
        days.add(day);
        ws.add(w);
        qs.add(q);
    }


    public int size() {
        return days.size();
    }


    public int getDay(int idx) {
        return days.getQuick(idx);
    }


    public double getW(int idx) {
        return ws.getQuick(idx);
    }


    public double getQ(int idx) {
        return qs.getQuick(idx);
    }

    public void removeNaNs() {

        int dest = 0;
        int N = ws.size();

        for (int i = 0; i < N; ++i) {
            double w = ws.getQuick(i);
            double q = qs.getQuick(i);

            if (Double.isNaN(w) || Double.isNaN(q)) {
                continue;
            }

            days.setQuick(dest, days.getQuick(i));
            ws.setQuick(dest, w);
            qs.setQuick(dest, q);
            ++dest;
        }

        if (dest < N) {
            days.remove(dest, N-dest);
            ws  .remove(dest, N-dest);
            qs  .remove(dest, N-dest);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org