diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java @ 3818:dc18457b1cef

merged flys-artifacts/pre2.7-2012-03-16
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:59 +0200
parents dce0cc856357
children ba15eb120a02
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/ReferenceCurveFacet.java	Fri Sep 28 12:14:59 2012 +0200
@@ -0,0 +1,96 @@
+package de.intevation.flys.artifacts.model;
+
+import java.util.List;
+import java.util.Collections;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+import org.apache.log4j.Logger;
+
+/** Facet for W-over-Ws. */
+public class ReferenceCurveFacet 
+extends      DataFacet
+{
+    private static Logger log = Logger.getLogger(ReferenceCurveFacet.class);
+
+    public static final String CONTEXT_KEY = "reference.curve.axis.scale";
+
+    public ReferenceCurveFacet() {
+    }
+
+    public ReferenceCurveFacet(int index, String name, String description) {
+        super(index, name, description, ComputeType.ADVANCE, null, null);
+    }
+
+    public ReferenceCurveFacet(
+        int         index,
+        String      name,
+        String      description,
+        ComputeType type,
+        String      stateID,
+        String      hash
+    ) {
+        super(index, name, description, type, hash, stateID);
+    }
+
+    public Object getData(Artifact artifact, CallContext context) {
+
+        if (log.isDebugEnabled()) {
+            log.debug("Get data for reference curve at index: " + index +
+                " /stateId: " + stateId);
+        }
+
+        return getWWQQ(artifact, context);
+    }
+
+    protected WWQQ getWWQQ(Artifact artifact, CallContext context) {
+        FLYSArtifact winfo = (FLYSArtifact)artifact;
+
+        CalculationResult res = (CalculationResult)
+            winfo.compute(context, hash, stateId, type, false);
+
+        return ((WWQQ [])res.getData())[index];
+    }
+
+    @Override
+    public void set(Facet other) {
+        super.set(other);
+        ReferenceCurveFacet o = (ReferenceCurveFacet)other;
+        type                  = o.type;
+        hash                  = o.hash;
+        stateId               = o.stateId;
+    }
+
+    /** Copy deeply. */
+    @Override
+    public Facet deepCopy() {
+        ReferenceCurveFacet copy = new ReferenceCurveFacet();
+        copy.set(this);
+        return copy;
+    }
+
+    @Override
+    public List getDataProviderKeys(Artifact art, CallContext context) {
+
+        // compute / get data
+        Object obj = context.getContextValue(CONTEXT_KEY);
+
+        if (!(obj instanceof WWAxisTypes)) {
+            obj = new WWAxisTypes(getWWQQ(art, context));
+            context.putContextValue(CONTEXT_KEY, obj);
+        }
+        else {
+            ((WWAxisTypes)obj).classify(getWWQQ(art, context));
+        }
+
+        return Collections.emptyList();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org