Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DurationCurveFacet.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 5642a83420f2 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DurationCurveFacet.java Fri Sep 28 12:14:39 2012 +0200 @@ -0,0 +1,98 @@ +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 :