changeset 4442:26774405c884

Introduce a new FixingsFacet to add save access to the current Km Values which are accessed by a String like a map must be checked for null. The new FixingsFacet adds a getCurrentKm method that abstracts the direct access to the CallContext and always returns a valid double value.
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 07 Nov 2012 14:06:03 +0100
parents 093f9333f66b
children af728a5e0329
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixingsFacet.java
diffstat 10 files changed, 71 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -8,8 +8,8 @@
 import de.intevation.flys.artifacts.access.ExtremeAccess;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.fixings.FixingsFacet;
 
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 
@@ -22,7 +22,7 @@
  * Facet to show the W|Q values.
  */
 public class ExtremeCurveFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -77,8 +77,7 @@
                                                  false);
 
             ExtremeResult result = (ExtremeResult) res.getData();
-            double currentKm =
-                ((Double)context.getContextValue("currentKm")).doubleValue();
+            double currentKm = getCurrentKm(context);
 
             KMIndex<Curve> curves = result.getCurves();
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -6,7 +6,6 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
@@ -21,7 +20,7 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FixAnalysisEventsFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -66,8 +65,7 @@
                                                  false);
 
             FixAnalysisResult result = (FixAnalysisResult) res.getData();
-            double currentKm =
-                ((Double)context.getContextValue("currentKm")).doubleValue();
+            double currentKm = getCurrentKm(context);
 
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
             KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -8,7 +8,6 @@
 import de.intevation.flys.artifacts.access.FixAnalysisAccess;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.DateRange;
 import de.intevation.flys.artifacts.model.FacetTypes;
 
@@ -24,7 +23,7 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FixAnalysisPeriodsFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -70,8 +69,7 @@
                                                  false);
 
             FixAnalysisResult result = (FixAnalysisResult) res.getData();
-            double currentKm =
-                ((Double)context.getContextValue("currentKm")).doubleValue();
+            double currentKm = getCurrentKm(context);
 
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
             KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -8,7 +8,6 @@
 import de.intevation.flys.artifacts.access.FixAnalysisAccess;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 
 import de.intevation.flys.artifacts.model.QWDDateRange;
@@ -26,7 +25,7 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FixAvSectorFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -71,8 +70,7 @@
 
             FixAnalysisResult result = (FixAnalysisResult) res.getData();
 
-            double currentKm =
-                ((Double)context.getContextValue("currentKm")).doubleValue();
+            double currentKm = getCurrentKm(context);
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
             KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
                 kmPeriods.binarySearch(currentKm);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -11,7 +11,6 @@
 import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.Parameters;
 
@@ -26,7 +25,7 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FixDerivateFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -76,8 +75,7 @@
                                              false);
 
         FixAnalysisResult result = (FixAnalysisResult) res.getData();
-        double currentKm =
-            ((Double)context.getContextValue("currentKm")).doubleValue();
+        double currentKm = getCurrentKm(context);
 
         String function = access.getFunction();
         Function ff = FunctionFactory.getInstance().getFunction(function);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -7,7 +7,6 @@
 import de.intevation.flys.artifacts.access.FixAnalysisAccess;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.Parameters;
 
@@ -22,7 +21,7 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FixDeviationFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -68,8 +67,7 @@
                                                  false);
 
             FixAnalysisResult result = (FixAnalysisResult) res.getData();
-            double currentKm =
-                ((Double)context.getContextValue("currentKm")).doubleValue();
+            double currentKm = getCurrentKm(context);
 
             Parameters params = result.getParameters();
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -6,7 +6,6 @@
 import de.intevation.artifacts.CallContext;
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 import de.intevation.flys.utils.KMIndex;
@@ -17,7 +16,7 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FixOutlierFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -62,8 +61,7 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
-            double currentKm =
-                ((Double)context.getContextValue("currentKm")).doubleValue();
+            double currentKm = getCurrentKm(context);
 
             KMIndex<QWI []>       kmQWs    = result.getOutliers();
             KMIndex.Entry<QWI []> qwsEntry = kmQWs.binarySearch(currentKm);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -6,7 +6,6 @@
 import de.intevation.artifacts.CallContext;
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 import de.intevation.flys.utils.KMIndex;
@@ -18,7 +17,7 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FixReferenceEventsFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -63,8 +62,7 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
-            double currentKm =
-                ((Double)context.getContextValue("currentKm")).doubleValue();
+            double currentKm = getCurrentKm(context);
 
             KMIndex<QWD []> kmQWs = result.getReferenced();
             KMIndex.Entry<QWD []> kmQWsEntry = kmQWs.binarySearch(currentKm);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Wed Nov 07 13:54:49 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -11,7 +11,6 @@
 import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
-import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.Parameters;
 
@@ -25,7 +24,7 @@
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class FixWQCurveFacet
-extends      DataFacet
+extends      FixingsFacet
 implements   FacetTypes {
 
     /** House logger. */
@@ -70,8 +69,7 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
-            double currentKm =
-                ((Double)context.getContextValue("currentKm")).doubleValue();
+            double currentKm = getCurrentKm(context);
 
             logger.debug("getData: km = " + currentKm);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixingsFacet.java	Wed Nov 07 14:06:03 2012 +0100
@@ -0,0 +1,52 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import de.intevation.artifacts.CallContext;
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+/**
+ * Facet to access the current Km from the context safely
+ * 
+ * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
+ */
+public class FixingsFacet extends DataFacet {
+
+    public static final Double INVALID_KM = Double.valueOf(-1d);
+    public static final String CURRENT_KM = "currentKm";
+
+    public FixingsFacet() {
+    }
+
+    public  FixingsFacet(String name, String description) {
+        super(0, name, description, ComputeType.ADVANCE, null, null);
+    }
+
+    public FixingsFacet(
+            int         index,
+            String      name,
+            String      description,
+            ComputeType type,
+            String      hash,
+            String      stateId
+            ) {
+        super(index, name, description, type, hash, stateId);
+    }
+
+    /**
+     * Returns the current km from the context.
+     * If the context is null or doesn't contain a currentKm then a double value of -1 will
+     *  be returned.
+     * @param context The CallContext instance
+     * @return the current km as double
+     */
+    protected double getCurrentKm(CallContext context) {
+        if (context == null) {
+            return INVALID_KM;
+        }
+        Double dkm = (Double)context.getContextValue(CURRENT_KM);
+        if (dkm == null) {
+            return INVALID_KM;
+        }
+        return dkm.doubleValue();
+    }
+}

http://dive4elements.wald.intevation.org