Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java @ 4314:8132b1a53539
ExtremeCurveFacet: New Facet to access Extreme Curves at given km.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 30 Oct 2012 06:58:04 +0100 |
parents | |
children | 09993be04c5e |
comparison
equal
deleted
inserted
replaced
4313:c72fc256b368 | 4314:8132b1a53539 |
---|---|
1 package de.intevation.flys.artifacts.model.extreme; | |
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.access.FixAnalysisAccess; | |
9 | |
10 import de.intevation.flys.artifacts.model.CalculationResult; | |
11 import de.intevation.flys.artifacts.model.DataFacet; | |
12 import de.intevation.flys.artifacts.model.FacetTypes; | |
13 import de.intevation.flys.artifacts.model.Parameters; | |
14 | |
15 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | |
16 | |
17 import de.intevation.flys.utils.KMIndex; | |
18 | |
19 import org.apache.log4j.Logger; | |
20 | |
21 /** | |
22 * Facet to show the W|Q values. | |
23 */ | |
24 public class ExtremeCurveFacet | |
25 extends DataFacet | |
26 implements FacetTypes { | |
27 | |
28 /** House logger. */ | |
29 private static Logger logger = Logger.getLogger(ExtremeCurveFacet.class); | |
30 | |
31 | |
32 /** Trivial Constructor. */ | |
33 public ExtremeCurveFacet() { | |
34 } | |
35 | |
36 | |
37 /** | |
38 * @param description Description of the facet. | |
39 */ | |
40 public ExtremeCurveFacet(String description) { | |
41 super(0, EXTREME_WQ_CURVE, description, ComputeType.ADVANCE, null, null); | |
42 } | |
43 | |
44 | |
45 public ExtremeCurveFacet(int index, String description) { | |
46 super(index, EXTREME_WQ_CURVE, description, ComputeType.ADVANCE, null, null); | |
47 } | |
48 | |
49 | |
50 /** | |
51 * Returns the data (a curve/function) this facet provides at km given in context. | |
52 * | |
53 * @param artifact the owner artifact. | |
54 * @param context the CallContext. | |
55 * | |
56 * @return the data. | |
57 */ | |
58 @Override | |
59 public Object getData(Artifact artifact, CallContext context) { | |
60 logger.debug("ExtremeCurveFacet.getData"); | |
61 if (artifact instanceof FLYSArtifact) { | |
62 FLYSArtifact flys = (FLYSArtifact)artifact; | |
63 | |
64 CalculationResult res = | |
65 (CalculationResult) flys.compute(context, | |
66 ComputeType.ADVANCE, | |
67 false); | |
68 | |
69 ExtremeResult result = (ExtremeResult) res.getData(); | |
70 double currentKm = | |
71 ((Double)context.getContextValue("currentKm")).doubleValue(); | |
72 | |
73 KMIndex<Curve> curves = result.getCurves(); | |
74 | |
75 KMIndex.Entry<Curve> curveEntry = curves.search(currentKm); | |
76 | |
77 if (curveEntry != null) { | |
78 logger.debug("A curve at km = " + currentKm); | |
79 return curveEntry.getValue(); | |
80 } | |
81 else { | |
82 logger.debug("No curve at km = " + currentKm); | |
83 return null; | |
84 } | |
85 } | |
86 else { | |
87 logger.debug("Not an instance of FLYSArtifact / WINFOArtifact."); | |
88 return null; | |
89 } | |
90 } | |
91 | |
92 | |
93 /** | |
94 * Create a deep copy of this Facet. | |
95 * @return a deep copy. | |
96 */ | |
97 @Override | |
98 public ExtremeCurveFacet deepCopy() { | |
99 ExtremeCurveFacet copy = new ExtremeCurveFacet(); | |
100 copy.set(this); | |
101 return copy; | |
102 } | |
103 } | |
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |