Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java @ 5797:cce12c06466f
RelativePointFacet: Through minor refactoring prepared to used StaticWQKmsArtifact.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 24 Apr 2013 08:17:18 +0200 |
parents | cd5eb8f5f6f1 |
children |
comparison
equal
deleted
inserted
replaced
5796:53cff50918b1 | 5797:cce12c06466f |
---|---|
8 import de.intevation.artifacts.Artifact; | 8 import de.intevation.artifacts.Artifact; |
9 import de.intevation.artifacts.CallContext; | 9 import de.intevation.artifacts.CallContext; |
10 import de.intevation.artifacts.DataProvider; | 10 import de.intevation.artifacts.DataProvider; |
11 | 11 |
12 import de.intevation.flys.artifacts.StaticWKmsArtifact; | 12 import de.intevation.flys.artifacts.StaticWKmsArtifact; |
13 import de.intevation.flys.artifacts.StaticWQKmsArtifact; | |
13 import de.intevation.flys.artifacts.math.Linear; | 14 import de.intevation.flys.artifacts.math.Linear; |
14 | 15 |
15 /** | 16 /** |
16 * Facet to access a point. | 17 * Facet to access a point. |
17 */ | 18 */ |
34 this.index = 0; | 35 this.index = 0; |
35 } | 36 } |
36 | 37 |
37 | 38 |
38 protected Point2D calculateDurationCurvePoint(CallContext context, | 39 protected Point2D calculateDurationCurvePoint(CallContext context, |
39 StaticWKmsArtifact artifact) | 40 WKms wKms) |
40 { | 41 { |
41 // TODO here and in reference curve calc: Do warn if more than 1 | 42 // TODO here and in reference curve calc: Do warn if more than 1 |
42 // provider found or (way better) handle it. | 43 // provider found or (way better) handle it. |
43 Object wqdays = null; | 44 Object wqdays = null; |
44 double km = 0d; | 45 double km = 0d; |
67 km = Double.valueOf(dckm); | 68 km = Double.valueOf(dckm); |
68 } | 69 } |
69 | 70 |
70 if (wqdays != null) { | 71 if (wqdays != null) { |
71 // Which W at this km? | 72 // Which W at this km? |
72 double w = artifact.getWAtKmLin(artifact.getWKms(0), km); | 73 double w = StaticWKmsArtifact.getWAtKmLin(wKms, km); |
73 if (w == -1) { | 74 if (w == -1) { |
74 logger.warn("w is -1, already bad sign!"); | 75 logger.warn("w is -1, already bad sign!"); |
75 } | 76 } |
76 // Where is this W passed by in the wq-curve? | 77 // Where is this W passed by in the wq-curve? |
77 WQDay wqday = (WQDay) wqdays; | 78 WQDay wqday = (WQDay) wqdays; |
108 /** | 109 /** |
109 * Calculate a reference curve point, that is, a point made of | 110 * Calculate a reference curve point, that is, a point made of |
110 * the Ws from start and end km param of the reference curve. | 111 * the Ws from start and end km param of the reference curve. |
111 */ | 112 */ |
112 public Point2D calculateReferenceCurvePoint(CallContext context, | 113 public Point2D calculateReferenceCurvePoint(CallContext context, |
113 StaticWKmsArtifact artifact) { | 114 WKms wKms) { |
115 | |
114 List<DataProvider> providers = context. | 116 List<DataProvider> providers = context. |
115 getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM); | 117 getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM); |
116 if (providers.size() < 1) { | 118 if (providers.size() < 1) { |
117 logger.warn("Could not find reference curve startkm data provider."); | 119 logger.warn("Could not find reference curve startkm data provider."); |
118 } | 120 } |
127 } | 129 } |
128 double[] ends = (double[]) providers.get(0). | 130 double[] ends = (double[]) providers.get(0). |
129 provideData(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS, null, context); | 131 provideData(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS, null, context); |
130 | 132 |
131 logger.debug("Got s " + start + " e " + ends); | 133 logger.debug("Got s " + start + " e " + ends); |
132 double startW = artifact.getWAtKmLin(artifact.getWKms(0), start.doubleValue()); | 134 |
135 double startW = StaticWKmsArtifact.getWAtKmLin(wKms, start.doubleValue()); | |
133 // TODO handle multiple ends. | 136 // TODO handle multiple ends. |
134 double endW = artifact.getWAtKmLin(artifact.getWKms(0), ends[0]); | 137 double endW = StaticWKmsArtifact.getWAtKmLin(wKms, ends[0]); |
135 logger.debug("Gotw s " + startW + " e " + endW); | 138 logger.debug("Gotw s " + startW + " e " + endW); |
136 return new Point2D.Double(startW, endW); | 139 return new Point2D.Double(startW, endW); |
137 } | 140 } |
138 | 141 |
139 | 142 |
145 * | 148 * |
146 * @return the data. | 149 * @return the data. |
147 */ | 150 */ |
148 @Override | 151 @Override |
149 public Object getData(Artifact artifact, CallContext context) { | 152 public Object getData(Artifact artifact, CallContext context) { |
150 StaticWKmsArtifact staticData = (StaticWKmsArtifact) artifact; | 153 WKms wKms = null; |
154 if (artifact instanceof StaticWKmsArtifact) { | |
155 wKms = ((StaticWKmsArtifact) artifact).getWKms(0); | |
156 } | |
157 else if (artifact instanceof StaticWQKmsArtifact) { | |
158 wKms = ((StaticWQKmsArtifact) artifact).getWQKms(); | |
159 } | |
160 else { | |
161 logger.error("Cannot handle Artifact to create relative point."); | |
162 return null; | |
163 } | |
164 | |
151 // Find out whether we live in a duration curve context, there we would | 165 // Find out whether we live in a duration curve context, there we would |
152 // provide only a single point. | 166 // provide only a single point. |
153 | 167 |
154 if (context.getDataProvider( | 168 if (context.getDataProvider( |
155 DurationCurveFacet.BB_DURATIONCURVE_KM).size() > 0) { | 169 DurationCurveFacet.BB_DURATIONCURVE_KM).size() > 0) { |
156 return calculateDurationCurvePoint(context, staticData); | 170 return calculateDurationCurvePoint(context, wKms); |
157 } | 171 } |
158 else if (context.getDataProvider( | 172 else if (context.getDataProvider( |
159 ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM).size() > 0) { | 173 ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM).size() > 0) { |
160 return calculateReferenceCurvePoint(context, staticData); | 174 return calculateReferenceCurvePoint(context, wKms); |
161 } | 175 } |
162 | 176 |
163 // TODO better signal failure. | 177 // TODO better signal failure. |
164 return new Point2D.Double(0d, 0d); | 178 return new Point2D.Double(0d, 0d); |
165 } | 179 } |