comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java @ 3028:77b5f5a26700

Added facets for fix analysis. flys-artifacts/trunk@4597 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 06 Jun 2012 08:07:32 +0000
parents
children b388d888330d
comparison
equal deleted inserted replaced
3027:52aac4941d2a 3028:77b5f5a26700
1 package de.intevation.flys.artifacts.model.fixings;
2
3 import org.apache.log4j.Logger;
4
5 import de.intevation.artifacts.Artifact;
6 import de.intevation.artifacts.CallContext;
7
8 import de.intevation.flys.artifacts.FLYSArtifact;
9 import de.intevation.flys.artifacts.FixationArtifactAccess;
10
11 import de.intevation.flys.artifacts.model.FacetTypes;
12 import de.intevation.flys.artifacts.model.DataFacet;
13 import de.intevation.flys.artifacts.model.CalculationResult;
14
15 import de.intevation.flys.utils.KMIndex;
16
17 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
18
19
20 /**
21 * Facet to show average W values for Q sectors.
22 *
23 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
24 */
25 public class FixAvSectorFacet
26 extends DataFacet
27 implements FacetTypes {
28
29 /** House logger. */
30 private static Logger logger = Logger.getLogger(FixAvSectorFacet.class);
31
32 /** Trivial Constructor. */
33 public FixAvSectorFacet() {
34 }
35
36
37 public FixAvSectorFacet(int ndx, String description) {
38 super(
39 ndx,
40 FIX_SECTOR_AVERAGE,
41 description,
42 ComputeType.ADVANCE,
43 null,
44 null);
45 }
46
47
48 /**
49 * Returns the data this facet requires.
50 *
51 * @param artifact the owner artifact.
52 * @param context the CallContext.
53 *
54 * @return the data as QWD array (QWD[]).
55 */
56 @Override
57 public Object getData(Artifact artifact, CallContext context) {
58 logger.debug("FixAvSectorFacet.getData");
59
60 if (artifact instanceof FLYSArtifact) {
61 FLYSArtifact flys = (FLYSArtifact)artifact;
62 FixationArtifactAccess access = new FixationArtifactAccess(flys);
63
64 CalculationResult res =
65 (CalculationResult) flys.compute(context,
66 ComputeType.ADVANCE,
67 false);
68
69 FixResult result = (FixResult) res.getData();
70
71 double km = access.getCurrentKm();
72
73 KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
74 AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue();
75
76 if (periods == null) {
77 return null;
78 }
79 QWD[] qwdData = periods[index].getQSectorAverages();
80 return periods;
81 }
82 else {
83 logger.debug("Not an instance of FixationArtifact.");
84 return null;
85 }
86 }
87
88
89 /**
90 * Create a deep copy of this Facet.
91 * @return a deep copy.
92 */
93 @Override
94 public FixAvSectorFacet deepCopy() {
95 FixAvSectorFacet copy = new FixAvSectorFacet();
96 copy.set(this);
97 return copy;
98 }
99 }
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org