Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAvSectorFacet.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAvSectorFacet.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.artifacts.model.fixings; | |
2 | |
3 import org.dive4elements.artifacts.Artifact; | |
4 import org.dive4elements.artifacts.CallContext; | |
5 | |
6 import org.dive4elements.river.artifacts.FLYSArtifact; | |
7 | |
8 import org.dive4elements.river.artifacts.access.FixAnalysisAccess; | |
9 | |
10 import org.dive4elements.river.artifacts.model.CalculationResult; | |
11 import org.dive4elements.river.artifacts.model.FacetTypes; | |
12 | |
13 import org.dive4elements.river.artifacts.model.QWDDateRange; | |
14 | |
15 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
16 | |
17 import org.dive4elements.river.utils.KMIndex; | |
18 | |
19 import org.apache.log4j.Logger; | |
20 | |
21 | |
22 /** | |
23 * Facet to show average W values for Q sectors. | |
24 * | |
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
26 */ | |
27 public class FixAvSectorFacet | |
28 extends FixingsFacet | |
29 implements FacetTypes { | |
30 | |
31 /** House logger. */ | |
32 private static Logger logger = Logger.getLogger(FixAvSectorFacet.class); | |
33 | |
34 /** Trivial Constructor. */ | |
35 public FixAvSectorFacet() { | |
36 } | |
37 | |
38 | |
39 public FixAvSectorFacet(int ndx, String name, String description) { | |
40 super( | |
41 ndx, | |
42 name, | |
43 description, | |
44 ComputeType.ADVANCE, | |
45 null, | |
46 null); | |
47 } | |
48 | |
49 | |
50 /** | |
51 * Returns the data this facet requires. | |
52 * | |
53 * @param artifact the owner artifact. | |
54 * @param context the CallContext. | |
55 * | |
56 * @return the data as QWD array (QWD[]). | |
57 */ | |
58 @Override | |
59 public Object getData(Artifact artifact, CallContext context) { | |
60 logger.debug("FixAvSectorFacet.getData"); | |
61 | |
62 if (artifact instanceof FLYSArtifact) { | |
63 FLYSArtifact flys = (FLYSArtifact)artifact; | |
64 FixAnalysisAccess access = new FixAnalysisAccess(flys, context); | |
65 | |
66 CalculationResult res = | |
67 (CalculationResult) flys.compute(context, | |
68 ComputeType.ADVANCE, | |
69 false); | |
70 | |
71 FixAnalysisResult result = (FixAnalysisResult) res.getData(); | |
72 | |
73 double currentKm = getCurrentKm(context); | |
74 KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods(); | |
75 KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry = | |
76 kmPeriods.binarySearch(currentKm); | |
77 | |
78 if (kmPeriodsEntry == null) { | |
79 logger.warn("No analysis periods found for km '" + currentKm + "'"); | |
80 return null; | |
81 } | |
82 | |
83 AnalysisPeriod[] periods = kmPeriodsEntry.getValue(); | |
84 | |
85 if (periods == null) { | |
86 logger.warn("No analysis periods specified!"); | |
87 return null; | |
88 } | |
89 | |
90 QWD[] qwdData = null; | |
91 int sectorNdx = index & 3; | |
92 int periodNdx = index >> 2; | |
93 | |
94 if (periodNdx < periods.length) { | |
95 qwdData = periods[periodNdx].getQSectorAverages(); | |
96 } | |
97 | |
98 if (logger.isDebugEnabled()) { | |
99 int resSize = qwdData != null ? qwdData.length : -1; | |
100 logger.debug("Found " + resSize + " result elements."); | |
101 } | |
102 | |
103 if (qwdData == null) { | |
104 return null; | |
105 } | |
106 return new QWDDateRange(qwdData[sectorNdx], periods[periodNdx].getDateRange()); | |
107 } | |
108 else { | |
109 logger.warn("Artifact is no instance of FLYSArtifact."); | |
110 return null; | |
111 } | |
112 } | |
113 | |
114 | |
115 /** | |
116 * Create a deep copy of this Facet. | |
117 * @return a deep copy. | |
118 */ | |
119 @Override | |
120 public FixAvSectorFacet deepCopy() { | |
121 FixAvSectorFacet copy = new FixAvSectorFacet(); | |
122 copy.set(this); | |
123 return copy; | |
124 } | |
125 } | |
126 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |