comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java @ 674:d5f9ba1d055f

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

http://dive4elements.wald.intevation.org