view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeCurveFacet.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents 21f4e4b79121
children 5d19a291bd9f
line wrap: on
line source
package de.intevation.flys.artifacts.model;

import java.util.Arrays;
import java.util.Map;

import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.CallContext;

import de.intevation.artifactdatabase.state.DefaultFacet;
import de.intevation.artifactdatabase.state.Facet;

import de.intevation.flys.artifacts.FLYSArtifact;

import de.intevation.flys.model.Gauge;

import de.intevation.flys.utils.FLYSUtils;

import org.apache.log4j.Logger;

/**
 * A Facet that returns discharge curve data at a gauge
 *
 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
 */
public class GaugeDischargeCurveFacet
extends      DefaultFacet
implements FacetTypes
{
    private static final Logger log =
        Logger.getLogger(GaugeDischargeCurveFacet.class);

    public GaugeDischargeCurveFacet(String name, String description) {
        super(0, name, description);
    }

    @Override
    public Object getData(Artifact art, CallContext context) {

        if (!(art instanceof FLYSArtifact)) {
            log.warn("Invalid artifact type");
            return null;
        }

        FLYSArtifact flys = (FLYSArtifact)art;

        String river = flys.getDataAsString("river");

        Gauge gauge = FLYSUtils.getReferenceGauge(flys);

        if (river == null || gauge == null) {
            log.warn("Unknown river or gauge");
            return null;
        }

        String name = gauge.getName();

        DischargeTables dt = new DischargeTables(river, name);

        Map<String, double [][]> map = dt.getValues(100d);

        double [][] values = map.get(name);
        if (values == null) {
            return null;
        }
        double [] kms = new double[values[0].length];
        Arrays.fill(kms, gauge.getStation().doubleValue());
        return new WQKms(kms, values[0], values[1], name);
    }

    @Override
    public Facet deepCopy() {
        GaugeDischargeCurveFacet copy = new GaugeDischargeCurveFacet(
                this.name,
                this.description);
        copy.set(this);
        return copy;
    }
}

http://dive4elements.wald.intevation.org