changeset 4314:8132b1a53539

ExtremeCurveFacet: New Facet to access Extreme Curves at given km.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 30 Oct 2012 06:58:04 +0100
parents c72fc256b368
children e7b923cf3a9c
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java
diffstat 1 files changed, 104 insertions(+), 0 deletions(-) [+]
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/extreme/ExtremeCurveFacet.java	Tue Oct 30 06:58:04 2012 +0100
@@ -0,0 +1,104 @@
+package de.intevation.flys.artifacts.model.extreme;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+import de.intevation.flys.artifacts.access.FixAnalysisAccess;
+
+import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.Parameters;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+import de.intevation.flys.utils.KMIndex;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Facet to show the W|Q values.
+ */
+public class ExtremeCurveFacet
+extends      DataFacet
+implements   FacetTypes {
+
+    /** House logger. */
+    private static Logger logger = Logger.getLogger(ExtremeCurveFacet.class);
+
+
+    /** Trivial Constructor. */
+    public ExtremeCurveFacet() {
+    }
+
+
+    /**
+     * @param description Description of the facet.
+     */
+    public ExtremeCurveFacet(String description) {
+        super(0, EXTREME_WQ_CURVE, description, ComputeType.ADVANCE, null, null);
+    }
+
+
+    public ExtremeCurveFacet(int index, String description) {
+        super(index, EXTREME_WQ_CURVE, description, ComputeType.ADVANCE, null, null);
+    }
+
+
+    /**
+     * Returns the data (a curve/function) this facet provides at km given in context.
+     *
+     * @param artifact the owner artifact.
+     * @param context  the CallContext.
+     *
+     * @return the data.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("ExtremeCurveFacet.getData");
+        if (artifact instanceof FLYSArtifact) {
+            FLYSArtifact flys = (FLYSArtifact)artifact;
+
+            CalculationResult res =
+                (CalculationResult) flys.compute(context,
+                                                 ComputeType.ADVANCE,
+                                                 false);
+
+            ExtremeResult result = (ExtremeResult) res.getData();
+            double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
+
+            KMIndex<Curve> curves = result.getCurves();
+
+            KMIndex.Entry<Curve> curveEntry = curves.search(currentKm);
+
+            if (curveEntry != null) {
+                logger.debug("A curve at km = " + currentKm);
+                return curveEntry.getValue();
+            }
+            else {
+                logger.debug("No curve at km = " + currentKm);
+                return null;
+            }
+        }
+        else {
+            logger.debug("Not an instance of FLYSArtifact / WINFOArtifact.");
+            return null;
+        }
+    }
+
+
+    /**
+     * Create a deep copy of this Facet.
+     * @return a deep copy.
+     */
+    @Override
+    public ExtremeCurveFacet deepCopy() {
+        ExtremeCurveFacet copy = new ExtremeCurveFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org