[Dive4elements-commits] [PATCH 08 of 11] ExtremeCurveFacet: New Facet to access Extreme Curves at given km

Wald Commits scm-commit at wald.intevation.org
Tue Oct 30 06:55:33 CET 2012


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1351576684 -3600
# Node ID 8132b1a53539a09cfd50fd3cbb21b70cda8bd49e
# Parent  c72fc256b368ec1f7917e6600488981e796233be
ExtremeCurveFacet: New Facet to access Extreme Curves at given km.

diff -r c72fc256b368 -r 8132b1a53539 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java
--- /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 :


More information about the Dive4elements-commits mailing list