diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java @ 4812:65bfb6faa538

Bring Access pattern to "W fuer ungleichwertige Abflusslaengsschnitte".
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 18 Jan 2013 19:33:26 +0100
parents e3532c7850b9
children bcf25d8c183e
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java	Fri Jan 18 10:30:09 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java	Fri Jan 18 19:33:26 2013 +0100
@@ -5,12 +5,15 @@
 import de.intevation.flys.artifacts.math.Identity;
 import de.intevation.flys.artifacts.math.Linear;
 
+import de.intevation.flys.artifacts.model.RiverFactory;
 import de.intevation.flys.artifacts.model.WstValueTable.QPosition;
 
 import de.intevation.flys.model.River;
 
 import de.intevation.flys.utils.DoubleUtil;
 
+import de.intevation.flys.artifacts.access.Calculation4Access;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -26,23 +29,69 @@
 
     protected List<Segment> segments;
 
-    protected boolean       isQ;
+    protected boolean isQ;
+    protected double  from;
+    protected double  to;
+    protected double  step;
+    protected String  river;
 
     public Calculation4() {
     }
 
-    public Calculation4(List<Segment> segments, River river, boolean isQ) {
+    public Calculation4(Calculation4Access access) {
+        String        river    = access.getRiver();
+        List<Segment> segments = access.getSegments();
+        double []     range    = access.getFromToStep();
+        boolean       isQ      = access.isQ();
 
-        this.segments = segments;
-        this.isQ      = isQ;
+        if (river == null) {
+            addProblem("no.river.selected");
+        }
 
-        Segment.setReferencePointConvertQ(segments, river, isQ, this);
+        if (range == null) {
+            addProblem("no.range.found");
+        }
+
+        if (segments == null || segments.isEmpty()) {
+            addProblem("cannot.create.segments");
+        }
+
+        if (!hasProblems()) {
+            this.river    = river;
+            this.segments = segments;
+            this.from     = range[0];
+            this.to       = range[1];
+            this.step     = range[2];
+            this.isQ      = isQ;
+        }
     }
 
-    public CalculationResult calculate(
-        WstValueTable table,
-        double from, double to, double step
-    ) {
+    public CalculationResult calculate() {
+        if (hasProblems()) {
+            return new CalculationResult(new WQKms[0], this);
+        }
+
+        WstValueTable table = null;
+        River r = RiverFactory.getRiver(river);
+        if (r == null) {
+            addProblem("no.river.found");
+        }
+        else {
+            table = WstValueTableFactory.getTable(r);
+            if (table == null) {
+                addProblem("no.wst.for.river");
+            }
+            else {
+                Segment.setReferencePointConvertQ(segments, r, isQ, this);
+            }
+        }
+
+        return hasProblems()
+            ? new CalculationResult(new WQKms[0], this)
+            : innerCalculate(table);
+    }
+
+    protected CalculationResult innerCalculate(WstValueTable table) {
         boolean debug = logger.isDebugEnabled();
 
         if (debug) {
@@ -54,12 +103,6 @@
             }
         }
 
-        if (segments.isEmpty()) {
-            logger.debug("no segments found");
-            addProblem("no.segments.found");
-            return new CalculationResult(new WQKms[0], this);
-        }
-
         int numResults = segments.get(0).values.length;
 
         if (numResults < 1) {

http://dive4elements.wald.intevation.org