annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java @ 709:3b7e9ddf6bb1

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

http://dive4elements.wald.intevation.org