Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java @ 3786:4adc35aa655c
merged flys-artifacts/2.9.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:47 +0200 |
parents | 66f539df4e8b |
children | 26774405c884 |
comparison
equal
deleted
inserted
replaced
3719:e82acd5c86f7 | 3786:4adc35aa655c |
---|---|
1 package de.intevation.flys.artifacts.model.fixings; | |
2 | |
3 import de.intevation.artifacts.Artifact; | |
4 import de.intevation.artifacts.CallContext; | |
5 | |
6 import de.intevation.flys.artifacts.FLYSArtifact; | |
7 | |
8 import de.intevation.flys.artifacts.model.CalculationResult; | |
9 import de.intevation.flys.artifacts.model.DataFacet; | |
10 import de.intevation.flys.artifacts.model.FacetTypes; | |
11 | |
12 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | |
13 | |
14 import de.intevation.flys.utils.KMIndex; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 | |
18 /** | |
19 * Facet to show W values for Q values at km for a date. | |
20 * | |
21 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
22 */ | |
23 public class FixAnalysisEventsFacet | |
24 extends DataFacet | |
25 implements FacetTypes { | |
26 | |
27 /** House logger. */ | |
28 private static Logger logger = Logger.getLogger(FixAnalysisEventsFacet.class); | |
29 | |
30 /** Trivial Constructor. */ | |
31 public FixAnalysisEventsFacet() { | |
32 } | |
33 | |
34 | |
35 /** | |
36 * @param name | |
37 */ | |
38 public FixAnalysisEventsFacet(int index, String name, String description) { | |
39 super(index, | |
40 name, | |
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 (ignored). | |
53 * | |
54 * @return the data. | |
55 */ | |
56 @Override | |
57 public Object getData(Artifact artifact, CallContext context) { | |
58 logger.debug("FixAnalysisEventsFacet.getData"); | |
59 | |
60 if (artifact instanceof FLYSArtifact) { | |
61 FLYSArtifact flys = (FLYSArtifact)artifact; | |
62 | |
63 CalculationResult res = | |
64 (CalculationResult) flys.compute(context, | |
65 ComputeType.ADVANCE, | |
66 false); | |
67 | |
68 FixAnalysisResult result = (FixAnalysisResult) res.getData(); | |
69 double currentKm = | |
70 ((Double)context.getContextValue("currentKm")).doubleValue(); | |
71 | |
72 KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods(); | |
73 KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry = | |
74 kmPeriods.binarySearch(currentKm); | |
75 | |
76 if(kmPeriodsEntry == null) { | |
77 logger.debug("getData: kmPeriodsEntry == null"); | |
78 return null; | |
79 } | |
80 | |
81 AnalysisPeriod[] periods = kmPeriodsEntry.getValue(); | |
82 if (periods == null) { | |
83 logger.debug("getData: periods == null"); | |
84 return null; | |
85 } | |
86 int ndx = index >> 8; | |
87 QWD[] qwdData = periods[ndx].getQWDs(); | |
88 if (qwdData == null) { | |
89 return null; | |
90 } | |
91 int ndy = index & 255; | |
92 for (int i = 0; i < qwdData.length; i++) { | |
93 if (qwdData[i].getIndex() == ndy) { | |
94 return qwdData[i]; | |
95 } | |
96 } | |
97 return null; | |
98 } | |
99 else { | |
100 logger.debug("Not an instance of FixationArtifact."); | |
101 return null; | |
102 } | |
103 } | |
104 | |
105 | |
106 /** | |
107 * Create a deep copy of this Facet. | |
108 * @return a deep copy. | |
109 */ | |
110 @Override | |
111 public FixAnalysisEventsFacet deepCopy() { | |
112 FixAnalysisEventsFacet copy = new FixAnalysisEventsFacet(); | |
113 copy.set(this); | |
114 return copy; | |
115 } | |
116 } | |
117 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |