diff 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
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java	Tue Apr 23 18:47:57 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java	Wed Apr 24 08:17:18 2013 +0200
@@ -10,6 +10,7 @@
 import de.intevation.artifacts.DataProvider;
 
 import de.intevation.flys.artifacts.StaticWKmsArtifact;
+import de.intevation.flys.artifacts.StaticWQKmsArtifact;
 import de.intevation.flys.artifacts.math.Linear;
 
 /**
@@ -36,7 +37,7 @@
 
 
     protected Point2D calculateDurationCurvePoint(CallContext context,
-        StaticWKmsArtifact artifact)
+        WKms wKms)
     {
         // TODO here and in reference curve calc: Do warn if more than 1
         // provider found or (way better) handle it.
@@ -69,7 +70,7 @@
 
         if (wqdays != null) {
             // Which W at this km?
-            double w = artifact.getWAtKmLin(artifact.getWKms(0), km);
+            double w = StaticWKmsArtifact.getWAtKmLin(wKms, km);
             if (w == -1) {
                 logger.warn("w is -1, already bad sign!");
             }
@@ -110,7 +111,8 @@
      * the Ws from start and end km param of the reference curve.
      */
     public Point2D calculateReferenceCurvePoint(CallContext context,
-        StaticWKmsArtifact artifact) {
+        WKms wKms) {
+
         List<DataProvider> providers = context.
             getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM);
         if (providers.size() < 1) {
@@ -129,9 +131,10 @@
             provideData(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS, null, context);
 
         logger.debug("Got s " + start + " e " + ends);
-        double startW = artifact.getWAtKmLin(artifact.getWKms(0), start.doubleValue());
+
+        double startW = StaticWKmsArtifact.getWAtKmLin(wKms, start.doubleValue());
         // TODO handle multiple ends.
-        double endW = artifact.getWAtKmLin(artifact.getWKms(0), ends[0]);
+        double endW = StaticWKmsArtifact.getWAtKmLin(wKms, ends[0]);
         logger.debug("Gotw s " + startW + " e " + endW);
         return new Point2D.Double(startW, endW);
     }
@@ -147,17 +150,28 @@
      */
     @Override
     public Object getData(Artifact artifact, CallContext context) {
-        StaticWKmsArtifact staticData = (StaticWKmsArtifact) artifact;
+        WKms wKms = null;
+        if (artifact instanceof StaticWKmsArtifact) {
+            wKms = ((StaticWKmsArtifact) artifact).getWKms(0);
+        }
+        else if (artifact instanceof StaticWQKmsArtifact) {
+            wKms = ((StaticWQKmsArtifact) artifact).getWQKms();
+        }
+        else {
+            logger.error("Cannot handle Artifact to create relative point.");
+            return null;
+        }
+
         // Find out whether we live in a duration curve context, there we would
         // provide only a single point.
 
         if (context.getDataProvider(
             DurationCurveFacet.BB_DURATIONCURVE_KM).size() > 0) {
-            return calculateDurationCurvePoint(context, staticData);
+            return calculateDurationCurvePoint(context, wKms);
         }
         else if (context.getDataProvider(
             ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM).size() > 0) {
-            return calculateReferenceCurvePoint(context, staticData);
+            return calculateReferenceCurvePoint(context, wKms);
         }
 
         // TODO better signal failure.

http://dive4elements.wald.intevation.org