comparison 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
comparison
equal deleted inserted replaced
9346:d89976700474 9347:08f46ccd37ba
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.artifacts.common;
10
11 import org.apache.log4j.Logger;
12 import org.dive4elements.artifactdatabase.state.Facet;
13 import org.dive4elements.artifacts.Artifact;
14 import org.dive4elements.artifacts.CallContext;
15 import org.dive4elements.river.artifacts.D4EArtifact;
16 import org.dive4elements.river.artifacts.model.CalculationResult;
17 import org.dive4elements.river.artifacts.model.DataFacet;
18 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
19
20 /**
21 * Facet of one of the S-Info curves.
22 */
23 // TODO: rename: hat nichts mehr mit sinfo zu tun
24 public class ResultFacet extends DataFacet {
25
26 private static final long serialVersionUID = 1L;
27
28 private static Logger log = Logger.getLogger(ResultFacet.class);
29
30 private int resultIndex;
31
32 public ResultFacet() {
33 // required for clone operation deepCopy()
34 }
35
36 public ResultFacet(final int resultIndex, final String name, final String description, final String yAxisLabelKey, final ComputeType type,
37 final String stateId, final String hash) {
38 this(resultIndex, resultIndex, name, description, yAxisLabelKey, type, stateId, hash);
39 }
40
41 public ResultFacet(final int facetIndex, final int resultIndex, final String name, final String description, final String yAxisLabelKey,
42 final ComputeType type, final String stateId, final String hash) {
43 // REMARK: in some cases, we have several data-lines for the same result (which normally determines the facet index) and
44 // facet name. But index and name are used by the client side as unique keys for the chart themes...
45 // So we might have different facet index and result index.
46 super(facetIndex, name, description, type, hash, stateId);
47 this.resultIndex = resultIndex;
48
49 this.metaData.put("X", "sinfo.chart.km.xaxis.label");
50 this.metaData.put("Y", yAxisLabelKey);
51 }
52
53 @Override
54 public final Object getData(final Artifact artifact, final CallContext context) {
55 log.debug("Get data for result at index: " + this.resultIndex);
56
57 final D4EArtifact flys = (D4EArtifact) artifact;
58
59 final CalculationResult res = (CalculationResult) flys.compute(context, this.hash, this.stateId, this.type, false);
60
61 final AbstractCalculationResults<AbstractCalculationResult> data = (AbstractCalculationResults<AbstractCalculationResult>) res.getData();
62
63 return data.getResults().get(this.resultIndex);
64 }
65
66 /** Copy deeply. */
67 @Override
68 public Facet deepCopy() {
69 // FIXME: why not simply use the full constructor instead?
70 final ResultFacet copy = new ResultFacet();
71 // FIXME: why does DataFacet does not override set? Bad access to variables of parent!
72 copy.set(this);
73 copy.type = this.type;
74 copy.hash = this.hash;
75 copy.stateId = this.stateId;
76 return copy;
77 }
78
79 @Override
80 public void set(final Facet other) {
81 this.resultIndex = ((ResultFacet) other).resultIndex;
82 super.set(other);
83 }
84 }

http://dive4elements.wald.intevation.org