diff artifacts/src/main/java/org/dive4elements/river/artifacts/common/ResultFacet.java @ 9347:08f46ccd37ba

salix.regional refactoring
author gernotbelger
date Tue, 31 Jul 2018 16:04:01 +0200
parents artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultFacet.java@0fc9c82e744e
children f8308db94634
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/ResultFacet.java	Tue Jul 31 16:04:01 2018 +0200
@@ -0,0 +1,84 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.common;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.DataFacet;
+import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
+
+/**
+ * Facet of one of the S-Info curves.
+ */
+// TODO: rename: hat nichts mehr mit sinfo zu tun
+public class ResultFacet extends DataFacet {
+
+    private static final long serialVersionUID = 1L;
+
+    private static Logger log = Logger.getLogger(ResultFacet.class);
+
+    private int resultIndex;
+
+    public ResultFacet() {
+        // required for clone operation deepCopy()
+    }
+
+    public ResultFacet(final int resultIndex, final String name, final String description, final String yAxisLabelKey, final ComputeType type,
+            final String stateId, final String hash) {
+        this(resultIndex, resultIndex, name, description, yAxisLabelKey, type, stateId, hash);
+    }
+
+    public ResultFacet(final int facetIndex, final int resultIndex, final String name, final String description, final String yAxisLabelKey,
+            final ComputeType type, final String stateId, final String hash) {
+        // REMARK: in some cases, we have several data-lines for the same result (which normally determines the facet index) and
+        // facet name. But index and name are used by the client side as unique keys for the chart themes...
+        // So we might have different facet index and result index.
+        super(facetIndex, name, description, type, hash, stateId);
+        this.resultIndex = resultIndex;
+
+        this.metaData.put("X", "sinfo.chart.km.xaxis.label");
+        this.metaData.put("Y", yAxisLabelKey);
+    }
+
+    @Override
+    public final Object getData(final Artifact artifact, final CallContext context) {
+        log.debug("Get data for result at index: " + this.resultIndex);
+
+        final D4EArtifact flys = (D4EArtifact) artifact;
+
+        final CalculationResult res = (CalculationResult) flys.compute(context, this.hash, this.stateId, this.type, false);
+
+        final AbstractCalculationResults<AbstractCalculationResult> data = (AbstractCalculationResults<AbstractCalculationResult>) res.getData();
+
+        return data.getResults().get(this.resultIndex);
+    }
+
+    /** Copy deeply. */
+    @Override
+    public Facet deepCopy() {
+        // FIXME: why not simply use the full constructor instead?
+        final ResultFacet copy = new ResultFacet();
+        // FIXME: why does DataFacet does not override set? Bad access to variables of parent!
+        copy.set(this);
+        copy.type = this.type;
+        copy.hash = this.hash;
+        copy.stateId = this.stateId;
+        return copy;
+    }
+
+    @Override
+    public void set(final Facet other) {
+        this.resultIndex = ((ResultFacet) other).resultIndex;
+        super.set(other);
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org