changeset 3419:da7cf0e3ccaa

FixA: Created a common base class for the fixing related calculations. flys-artifacts/trunk@5072 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 19 Jul 2012 16:35:14 +0000
parents 21c1d1d25919
children 7f7ab030a4e3
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixRealizingAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java
diffstat 7 files changed, 184 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Jul 19 15:44:14 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Jul 19 16:35:14 2012 +0000
@@ -1,3 +1,28 @@
+2012-07-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
+	  New. Common base class for Fix*Calculations.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java:
+	  Moved common stuff to base class FixCalculation.
+
+	 * src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java:
+	   Inherit from FixCalculation.
+
+	* src/main/java/de/intevation/flys/artifacts/access/FixRealizingAccess.java:
+	  Extract parameters that are only relevant for the
+	  'Ausgelagerte Wasserspiegellagen' calculation.
+
+	  isQ():         Must we convert the given values from W to Q first?
+	                 Used data field: 'fix_isq'
+	  getSegments(): Segments same semantics as WINFO's 
+	                 'W fuer ungleichwertige Abfluesse.'
+	                 Used data field: 'fix_segments'
+
+	* src/main/java/de/intevation/flys/artifacts/model/Segment.java,
+	  src/main/java/de/intevation/flys/artifacts/access/FixAccess.java:
+	  Cosmetics.
+
 2012-07-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/access/FixAccess.java:
@@ -17067,7 +17092,7 @@
 	  Made getExplodedValues static.
 
 	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
-	  Use new logic to calculate "W für ungleichwertige Abfluesse".
+	  Use new logic to calculate "W fuer ungleichwertige Abfluesse".
 	  Not working, yet.
 
 	* ChangeLog: Fixed former entry.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixAccess.java	Thu Jul 19 15:44:14 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixAccess.java	Thu Jul 19 16:35:14 2012 +0000
@@ -166,7 +166,5 @@
         }
         return function;
     }
-
-
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixRealizingAccess.java	Thu Jul 19 15:44:14 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixRealizingAccess.java	Thu Jul 19 16:35:14 2012 +0000
@@ -2,6 +2,10 @@
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 
+import de.intevation.flys.artifacts.model.Segment;
+
+import java.util.List;
+
 import org.apache.log4j.Logger;
 
 public class FixRealizingAccess
@@ -9,11 +13,41 @@
 {
     private static Logger log = Logger.getLogger(FixRealizingAccess.class);
 
+    protected Boolean isQ;
+
+    protected List<Segment> segments;
+
     public FixRealizingAccess() {
     }
 
     public FixRealizingAccess(FLYSArtifact artifact) {
         super(artifact);
     }
+
+    public Boolean isQ() {
+        if (isQ == null) {
+            isQ = getBoolean("fix_isq");
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("isQ: " + isQ);
+        }
+
+        return isQ;
+    }
+
+    public List<Segment> getSegments() {
+        if (segments == null) {
+            String segmentsS = getString("fix_segments");
+            if (segmentsS != null) {
+                segments = Segment.parseSegments(segmentsS);
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("segments: " + segments);
+        }
+
+        return segments;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java	Thu Jul 19 15:44:14 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java	Thu Jul 19 16:35:14 2012 +0000
@@ -1,15 +1,15 @@
 package de.intevation.flys.artifacts.model;
 
-import java.util.List;
-import java.util.ArrayList;
+import de.intevation.flys.utils.DoubleUtil;
+
+import gnu.trove.TDoubleArrayList;
 
 import java.io.Serializable;
 
-import org.apache.log4j.Logger;
+import java.util.ArrayList;
+import java.util.List;
 
-import gnu.trove.TDoubleArrayList;
-
-import de.intevation.flys.utils.DoubleUtil;
+import org.apache.log4j.Logger;
 
 public class Segment
 implements   Serializable
@@ -39,6 +39,7 @@
         return from < to;
     }
 
+    @Override
     public String toString() {
         StringBuilder sb = new StringBuilder("Segment: [");
         sb.append("from: ").append(from).append("; to: ")
@@ -58,7 +59,9 @@
     }
 
     public void backup() {
-        backup = (double [])values.clone();
+        backup = values != null
+            ? (double [])values.clone()
+            : null;
     }
 
     public double getFrom() {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java	Thu Jul 19 15:44:14 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java	Thu Jul 19 16:35:14 2012 +0000
@@ -5,7 +5,6 @@
 import de.intevation.flys.artifacts.math.fitting.Function;
 import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
 
-import de.intevation.flys.artifacts.model.Calculation;
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.DateRange;
 import de.intevation.flys.artifacts.model.FixingsColumn;
@@ -42,64 +41,23 @@
 import org.apache.log4j.Logger;
 
 public class FixAnalysisCalculation
-extends      Calculation
+extends      FixCalculation
 {
     private static Logger log = Logger.getLogger(FixAnalysisCalculation.class);
 
     public static final double EPSILON = 1e-4;
 
-    protected String       river;
-    protected double       from;
-    protected double       to;
-    protected double       step;
-    protected boolean      preprocessing;
-    protected String       function;
-    protected int []       events;
     protected DateRange    referencePeriod;
     protected DateRange [] analysisPeriods;
-    protected int          qSectorStart;
-    protected int          qSectorEnd;
 
     public FixAnalysisCalculation() {
     }
 
     public FixAnalysisCalculation(FixAnalysisAccess access) {
+        super(access);
 
-        String       river           = access.getRiver();
-        Double       from            = access.getFrom();
-        Double       to              = access.getTo();
-        Double       step            = access.getStep();
-        String       function        = access.getFunction();
-        int []       events          = access.getEvents();
         DateRange    referencePeriod = access.getReferencePeriod();
         DateRange [] analysisPeriods = access.getAnalysisPeriods();
-        Integer      qSectorStart    = access.getQSectorStart();
-        Integer      qSectorEnd      = access.getQSectorEnd();
-        Boolean      preprocessing   = access.getPreprocessing();
-
-        if (river == null) {
-            addProblem("fix.missing.river");
-        }
-
-        if (from == null) {
-            addProblem("fix.missing.from");
-        }
-
-        if (to == null) {
-            addProblem("fix.missing.to");
-        }
-
-        if (step == null) {
-            addProblem("fix.missing.step");
-        }
-
-        if (function == null) {
-            addProblem("fix.missing.function");
-        }
-
-        if (events == null || events.length < 1) {
-            addProblem("fix.missing.events");
-        }
 
         if (referencePeriod == null) {
             addProblem("fix.missing.reference.period");
@@ -109,30 +67,9 @@
             addProblem("fix.missing.analysis.periods");
         }
 
-        if (qSectorStart == null) {
-            addProblem("fix.missing.qstart.sector");
-        }
-
-        if (qSectorEnd == null) {
-            addProblem("fix.missing.qend.sector");
-        }
-
-        if (preprocessing == null) {
-            addProblem("fix.missing.preprocessing");
-        }
-
         if (!hasProblems()) {
-            this.river           = river;
-            this.from            = from;
-            this.to              = to;
-            this.step            = step;
-            this.function        = function;
-            this.events          = events;
             this.referencePeriod = referencePeriod;
             this.analysisPeriods = analysisPeriods;
-            this.qSectorStart    = qSectorStart;
-            this.qSectorEnd      = qSectorEnd;
-            this.preprocessing   = preprocessing;
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Thu Jul 19 16:35:14 2012 +0000
@@ -0,0 +1,88 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import de.intevation.flys.artifacts.access.FixAccess;
+
+import de.intevation.flys.artifacts.model.Calculation;
+
+import org.apache.log4j.Logger;
+
+public class FixCalculation
+extends      Calculation
+{
+    private static Logger log = Logger.getLogger(FixCalculation.class);
+
+    protected String  river;
+    protected double  from;
+    protected double  to;
+    protected double  step;
+    protected boolean preprocessing;
+    protected String  function;
+    protected int []  events;
+    protected int     qSectorStart;
+    protected int     qSectorEnd;
+
+    public FixCalculation() {
+    }
+
+    public FixCalculation(FixAccess access) {
+        String       river           = access.getRiver();
+        Double       from            = access.getFrom();
+        Double       to              = access.getTo();
+        Double       step            = access.getStep();
+        String       function        = access.getFunction();
+        int []       events          = access.getEvents();
+        Integer      qSectorStart    = access.getQSectorStart();
+        Integer      qSectorEnd      = access.getQSectorEnd();
+        Boolean      preprocessing   = access.getPreprocessing();
+
+        if (river == null) {
+            addProblem("fix.missing.river");
+        }
+
+        if (from == null) {
+            addProblem("fix.missing.from");
+        }
+
+        if (to == null) {
+            addProblem("fix.missing.to");
+        }
+
+        if (step == null) {
+            addProblem("fix.missing.step");
+        }
+
+        if (function == null) {
+            addProblem("fix.missing.function");
+        }
+
+        if (events == null || events.length < 1) {
+            addProblem("fix.missing.events");
+        }
+
+        if (qSectorStart == null) {
+            addProblem("fix.missing.qstart.sector");
+        }
+
+        if (qSectorEnd == null) {
+            addProblem("fix.missing.qend.sector");
+        }
+
+        if (preprocessing == null) {
+            addProblem("fix.missing.preprocessing");
+        }
+
+        if (!hasProblems()) {
+            this.river         = river;
+            this.from          = from;
+            this.to            = to;
+            this.step          = step;
+            this.function      = function;
+            this.events        = events;
+            this.qSectorStart  = qSectorStart;
+            this.qSectorEnd    = qSectorEnd;
+            this.preprocessing = preprocessing;
+        }
+
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java	Thu Jul 19 15:44:14 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java	Thu Jul 19 16:35:14 2012 +0000
@@ -2,22 +2,43 @@
 
 import de.intevation.flys.artifacts.access.FixRealizingAccess;
 
-import de.intevation.flys.artifacts.model.Calculation;
 import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.Segment;
+
+import java.util.List;
 
 import org.apache.log4j.Logger;
 
 public class FixRealizingCalculation
-extends      Calculation
+extends      FixCalculation
 {
     private static Logger log =
         Logger.getLogger(FixRealizingCalculation.class);
 
+    protected boolean       isQ;
+    protected List<Segment> segments;
+
     public FixRealizingCalculation() {
     }
 
     public FixRealizingCalculation(FixRealizingAccess access) {
-        // TODO: Implement me!
+        Boolean       isQ      = access.isQ();
+        List<Segment> segments = access.getSegments();
+
+        if (isQ == null) {
+            // TODO: i18n
+            addProblem("fix.realize.missing.is.q");
+        }
+
+        if (segments == null || segments.isEmpty()) {
+            // TODO: i18n
+            addProblem("fix.realize.missing.segments");
+        }
+
+        if (!hasProblems()) {
+            this.isQ      = isQ;
+            this.segments = segments;
+        }
     }
 
     public CalculationResult calculate() {

http://dive4elements.wald.intevation.org