view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQDay.java @ 697:b972eba2ed8a facets-slt

Removed ComputeCallback because this was thought too complicated. Fixed issue with facets not be re-generated if same state is entered again. flys-artifacts/branches/facets-slt@2143 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Jun 2011 10:40:54 +0000
parents 3dc61e00385e
children eab5e5089d77
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