view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DurationCurveFacet.java @ 3727:b81f328da582

Removed code duplication. flys-artifacts/trunk@5399 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 08 Sep 2012 12:58:58 +0000
parents 5642a83420f2
children
line wrap: on
line source
package de.intevation.flys.artifacts.model;

import java.util.List;
import java.util.ArrayList;

import org.apache.log4j.Logger;

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.artifacts.WINFOArtifact;

import de.intevation.flys.artifacts.states.DefaultState.ComputeType;


/**
 * Data of a duration curve.
 */
public class DurationCurveFacet extends DefaultFacet {

    private static Logger logger = Logger.getLogger(DurationCurveFacet.class);

    /** Blackboard data provider key for durationcurve (wqday) data. */
    public static String BB_DURATIONCURVE = "durationcurve";

    /** Blackboard data provider key for km of durationcurve. */
    public static String BB_DURATIONCURVE_KM = "durationcurve.km";

    public DurationCurveFacet() {
    }

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


    /**
     * Expose state computation from WINFOArtifact.
     */
    public Object getData(Artifact artifact, CallContext context) {
        logger.debug("Get data for duration curve data");

        WINFOArtifact winfo = (WINFOArtifact)artifact;

        CalculationResult cr = (CalculationResult)winfo.compute(
            context, ComputeType.ADVANCE, false);

        return cr.getData();
    }


    @Override
    public List getStaticDataProviderKeys(Artifact art) {
        List list = new ArrayList();
        list.add(BB_DURATIONCURVE);
        list.add(BB_DURATIONCURVE_KM);
        return list;
    }


    /**
     * Can provide whatever getData returns and additionally the location.
     * @param key      will respond on BB_DURATIONCURVE +KM
     * @param param    ignored
     * @param context  ignored
     * @return whatever getData delivers or location.
     */
    @Override
    public Object provideBlackboardData(Artifact artifact,
        Object key,
        Object param,
        CallContext context
    ) {
        if (key.equals(BB_DURATIONCURVE)) {
            return getData(artifact, context);
        }
        else if (key.equals(BB_DURATIONCURVE_KM)) {
            return ((FLYSArtifact)artifact).getDataAsString("ld_locations");
        }
        else {
            return null;
        }
    }


    /** Create a deep copy. */
    @Override
    public Facet deepCopy() {
        DurationCurveFacet copy = new DurationCurveFacet();
        copy.set(this);
        return copy;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org