Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/extreme/ExtremeCurveFacet.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java@f8217f1fef2e |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.model.extreme; | |
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.ExtremeAccess; | |
9 | |
10 import org.dive4elements.river.artifacts.model.CalculationResult; | |
11 import org.dive4elements.river.artifacts.model.FacetTypes; | |
12 import org.dive4elements.river.artifacts.model.fixings.FixingsFacet; | |
13 | |
14 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
15 | |
16 import org.dive4elements.river.utils.KMIndex; | |
17 import org.dive4elements.river.utils.DoubleUtil; | |
18 | |
19 import org.apache.log4j.Logger; | |
20 | |
21 /** | |
22 * Facet to show the W|Q values. | |
23 */ | |
24 public class ExtremeCurveFacet | |
25 extends FixingsFacet | |
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 * @param description Description of the facet. | |
46 * @param showBase if true, gimme different name. | |
47 */ | |
48 public ExtremeCurveFacet(String description, boolean showBase) { | |
49 super(0, EXTREME_WQ_CURVE_BASE, description, ComputeType.ADVANCE, null, null); | |
50 if (!showBase) { | |
51 this.name = EXTREME_WQ_CURVE; | |
52 } | |
53 } | |
54 | |
55 | |
56 public ExtremeCurveFacet(int index, String description) { | |
57 super(index, EXTREME_WQ_CURVE, description, ComputeType.ADVANCE, null, null); | |
58 } | |
59 | |
60 | |
61 /** | |
62 * Returns the data (a curve/function) this facet provides at km given in context. | |
63 * | |
64 * @param artifact the owner artifact. | |
65 * @param context the CallContext. | |
66 * | |
67 * @return the data. | |
68 */ | |
69 @Override | |
70 public Object getData(Artifact artifact, CallContext context) { | |
71 logger.debug("ExtremeCurveFacet.getData"); | |
72 if (artifact instanceof FLYSArtifact) { | |
73 FLYSArtifact flys = (FLYSArtifact)artifact; | |
74 CalculationResult res = | |
75 (CalculationResult) flys.compute(context, | |
76 ComputeType.ADVANCE, | |
77 false); | |
78 | |
79 ExtremeResult result = (ExtremeResult) res.getData(); | |
80 double currentKm = getCurrentKm(context); | |
81 | |
82 KMIndex<Curve> curves = result.getCurves(); | |
83 | |
84 KMIndex.Entry<Curve> curveEntry = curves.search(currentKm); | |
85 | |
86 if (curveEntry != null) { | |
87 logger.debug("A curve at km = " + currentKm); | |
88 Curve c = curveEntry.getValue(); | |
89 // Find segment in which the curr. km is located. | |
90 ExtremeAccess access = new ExtremeAccess(flys, context); | |
91 | |
92 double[] ds = access.getValuesForRange(currentKm); | |
93 | |
94 if (ds != null) { | |
95 double m = DoubleUtil.maxInArray(ds); | |
96 // Add 5 percent. | |
97 m *= 1.05d; | |
98 c.setSuggestedMaxQ(m); | |
99 } | |
100 | |
101 return c; | |
102 } | |
103 else { | |
104 logger.debug("No curve at km = " + currentKm); | |
105 return null; | |
106 } | |
107 } | |
108 else { | |
109 logger.debug("Not an instance of FLYSArtifact / WINFOArtifact."); | |
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 ExtremeCurveFacet deepCopy() { | |
121 ExtremeCurveFacet copy = new ExtremeCurveFacet(); | |
122 copy.set(this); | |
123 return copy; | |
124 } | |
125 } | |
126 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |