Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixLongitudinalReferenceFacet.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/FixLongitudinalReferenceFacet.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.DataFacet; | |
12 import org.dive4elements.river.artifacts.model.FacetTypes; | |
13 | |
14 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
15 | |
16 import org.dive4elements.river.utils.KMIndex; | |
17 | |
18 import org.apache.log4j.Logger; | |
19 | |
20 | |
21 /** | |
22 * Facet to show average W values for Q sectors. | |
23 * | |
24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
25 */ | |
26 public class FixLongitudinalReferenceFacet | |
27 extends DataFacet | |
28 implements FacetTypes { | |
29 | |
30 /** House logger. */ | |
31 private static Logger logger = Logger.getLogger(FixLongitudinalReferenceFacet.class); | |
32 | |
33 /** Trivial Constructor. */ | |
34 public FixLongitudinalReferenceFacet() { | |
35 } | |
36 | |
37 | |
38 public FixLongitudinalReferenceFacet( | |
39 int ndx, | |
40 String name, | |
41 String description) | |
42 { | |
43 super( | |
44 ndx, | |
45 name, | |
46 description, | |
47 ComputeType.ADVANCE, | |
48 null, | |
49 null); | |
50 } | |
51 | |
52 | |
53 /** | |
54 * Returns the data this facet requires. | |
55 * | |
56 * @param artifact the owner artifact. | |
57 * @param context the CallContext. | |
58 * | |
59 * @return the data as KMIndex. | |
60 */ | |
61 @Override | |
62 public Object getData(Artifact artifact, CallContext context) { | |
63 logger.debug("FixLongitudinalReferenceFacet.getData"); | |
64 | |
65 if (artifact instanceof FLYSArtifact) { | |
66 FLYSArtifact flys = (FLYSArtifact)artifact; | |
67 FixAnalysisAccess access = new FixAnalysisAccess(flys, context); | |
68 | |
69 CalculationResult res = | |
70 (CalculationResult) flys.compute(context, | |
71 ComputeType.ADVANCE, | |
72 false); | |
73 | |
74 FixAnalysisResult result = (FixAnalysisResult) res.getData(); | |
75 | |
76 KMIndex<QWD []> kmReference = result.getReferenced(); | |
77 | |
78 if (kmReference == null) { | |
79 logger.warn("No references found."); | |
80 return null; | |
81 } | |
82 | |
83 int qwdNdx = index & 255; | |
84 KMIndex<QWD> resReference = | |
85 new KMIndex<QWD>(); | |
86 for (KMIndex.Entry<QWD[]> entry: kmReference) { | |
87 QWD[] qwds = entry.getValue(); | |
88 for(int i = 0; i < qwds.length; i++) { | |
89 if(qwds[i].getIndex() == qwdNdx) { | |
90 resReference.add(entry.getKm(), qwds[i]); | |
91 } | |
92 } | |
93 } | |
94 return resReference; | |
95 } | |
96 else { | |
97 logger.warn("Artifact is no instance of FLYSArtifact."); | |
98 return null; | |
99 } | |
100 } | |
101 | |
102 | |
103 /** | |
104 * Create a deep copy of this Facet. | |
105 * @return a deep copy. | |
106 */ | |
107 @Override | |
108 public FixLongitudinalReferenceFacet deepCopy() { | |
109 FixLongitudinalReferenceFacet copy = | |
110 new FixLongitudinalReferenceFacet(); | |
111 copy.set(this); | |
112 return copy; | |
113 } | |
114 } | |
115 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |