annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java @ 676:c501f27c1f71

Added error reporting to 'Dauerzahlen' calculation. flys-artifacts/trunk@2100 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 10 Jun 2011 12:38:08 +0000
parents d5f9ba1d055f
children eab5e5089d77
rev   line source
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import org.w3c.dom.Document;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import org.w3c.dom.Element;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.util.List;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import java.util.ArrayList;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8
676
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
9 import java.io.Serializable;
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
10
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 public class Calculation
676
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
12 implements Serializable
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 {
676
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
14 public static class Problem
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
15 implements Serializable
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
16 {
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 protected Double km;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 protected String msg;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public Problem() {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public Problem(String msg) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 this.msg = msg;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 public Problem(double km, String msg) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 this.km = km;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 this.msg = msg;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 public Element toXML(Document document) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 Element problem = document.createElement("problem");
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 if (km != null) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 problem.setAttribute("km", String.valueOf(km));
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 problem.setTextContent(msg);
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 return problem;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 } // class Problem
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 protected List<Problem> problems;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public Calculation() {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 protected List<Problem> checkProblems() {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 if (problems == null) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 problems = new ArrayList<Problem>();
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 return problems;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public void addProblem(String msg) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 checkProblems().add(new Problem(msg));
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 public void addProblem(double km, String msg) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 checkProblems().add(new Problem(km, msg));
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 public boolean hasProblems() {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 return problems != null && !problems.isEmpty();
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65
676
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
66 public int numProblems() {
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
67 return problems != null ? problems.size() : 0;
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
68 }
c501f27c1f71 Added error reporting to 'Dauerzahlen' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
69
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 public List<Problem> getProblems() {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 return problems;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 public void toXML(Document document) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 Element root = document.createElement("problems");
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 if (hasProblems()) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 for (Problem problem: problems) {
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 root.appendChild(problem.toXML(document));
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 document.appendChild(root);
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 }
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org