comparison 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
comparison
equal deleted inserted replaced
4811:a06e443f159a 4812:65bfb6faa538
3 import de.intevation.flys.artifacts.math.BackJumpCorrector; 3 import de.intevation.flys.artifacts.math.BackJumpCorrector;
4 import de.intevation.flys.artifacts.math.Function; 4 import de.intevation.flys.artifacts.math.Function;
5 import de.intevation.flys.artifacts.math.Identity; 5 import de.intevation.flys.artifacts.math.Identity;
6 import de.intevation.flys.artifacts.math.Linear; 6 import de.intevation.flys.artifacts.math.Linear;
7 7
8 import de.intevation.flys.artifacts.model.RiverFactory;
8 import de.intevation.flys.artifacts.model.WstValueTable.QPosition; 9 import de.intevation.flys.artifacts.model.WstValueTable.QPosition;
9 10
10 import de.intevation.flys.model.River; 11 import de.intevation.flys.model.River;
11 12
12 import de.intevation.flys.utils.DoubleUtil; 13 import de.intevation.flys.utils.DoubleUtil;
14
15 import de.intevation.flys.artifacts.access.Calculation4Access;
13 16
14 import java.util.ArrayList; 17 import java.util.ArrayList;
15 import java.util.Arrays; 18 import java.util.Arrays;
16 import java.util.List; 19 import java.util.List;
17 20
24 27
25 public static final double MINIMAL_STEP_WIDTH = 1e-5; 28 public static final double MINIMAL_STEP_WIDTH = 1e-5;
26 29
27 protected List<Segment> segments; 30 protected List<Segment> segments;
28 31
29 protected boolean isQ; 32 protected boolean isQ;
33 protected double from;
34 protected double to;
35 protected double step;
36 protected String river;
30 37
31 public Calculation4() { 38 public Calculation4() {
32 } 39 }
33 40
34 public Calculation4(List<Segment> segments, River river, boolean isQ) { 41 public Calculation4(Calculation4Access access) {
35 42 String river = access.getRiver();
36 this.segments = segments; 43 List<Segment> segments = access.getSegments();
37 this.isQ = isQ; 44 double [] range = access.getFromToStep();
38 45 boolean isQ = access.isQ();
39 Segment.setReferencePointConvertQ(segments, river, isQ, this); 46
40 } 47 if (river == null) {
41 48 addProblem("no.river.selected");
42 public CalculationResult calculate( 49 }
43 WstValueTable table, 50
44 double from, double to, double step 51 if (range == null) {
45 ) { 52 addProblem("no.range.found");
53 }
54
55 if (segments == null || segments.isEmpty()) {
56 addProblem("cannot.create.segments");
57 }
58
59 if (!hasProblems()) {
60 this.river = river;
61 this.segments = segments;
62 this.from = range[0];
63 this.to = range[1];
64 this.step = range[2];
65 this.isQ = isQ;
66 }
67 }
68
69 public CalculationResult calculate() {
70 if (hasProblems()) {
71 return new CalculationResult(new WQKms[0], this);
72 }
73
74 WstValueTable table = null;
75 River r = RiverFactory.getRiver(river);
76 if (r == null) {
77 addProblem("no.river.found");
78 }
79 else {
80 table = WstValueTableFactory.getTable(r);
81 if (table == null) {
82 addProblem("no.wst.for.river");
83 }
84 else {
85 Segment.setReferencePointConvertQ(segments, r, isQ, this);
86 }
87 }
88
89 return hasProblems()
90 ? new CalculationResult(new WQKms[0], this)
91 : innerCalculate(table);
92 }
93
94 protected CalculationResult innerCalculate(WstValueTable table) {
46 boolean debug = logger.isDebugEnabled(); 95 boolean debug = logger.isDebugEnabled();
47 96
48 if (debug) { 97 if (debug) {
49 logger.debug( 98 logger.debug(
50 "calculate from " + from + " to " + to + " step " + step); 99 "calculate from " + from + " to " + to + " step " + step);
51 logger.debug("# segments: " + segments.size()); 100 logger.debug("# segments: " + segments.size());
52 for (Segment segment: segments) { 101 for (Segment segment: segments) {
53 logger.debug(" " + segment); 102 logger.debug(" " + segment);
54 } 103 }
55 }
56
57 if (segments.isEmpty()) {
58 logger.debug("no segments found");
59 addProblem("no.segments.found");
60 return new CalculationResult(new WQKms[0], this);
61 } 104 }
62 105
63 int numResults = segments.get(0).values.length; 106 int numResults = segments.get(0).values.length;
64 107
65 if (numResults < 1) { 108 if (numResults < 1) {

http://dive4elements.wald.intevation.org