Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java @ 686:3dc61e00385e facets-slt
Merged with trunk and introduced hashing of computed values.
flys-artifacts/branches/facets-slt@2126 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 15 Jun 2011 15:28:54 +0000 |
parents | |
children | eab5e5089d77 |
comparison
equal
deleted
inserted
replaced
667:434146596838 | 686:3dc61e00385e |
---|---|
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 import java.io.Serializable; | |
10 | |
11 public class Calculation | |
12 implements Serializable | |
13 { | |
14 public static class Problem | |
15 implements Serializable | |
16 { | |
17 protected Double km; | |
18 protected String msg; | |
19 | |
20 public Problem() { | |
21 } | |
22 | |
23 public Problem(String msg) { | |
24 this.msg = msg; | |
25 } | |
26 | |
27 public Problem(double km, String msg) { | |
28 this.km = km; | |
29 this.msg = msg; | |
30 } | |
31 | |
32 public Element toXML(Document document) { | |
33 Element problem = document.createElement("problem"); | |
34 if (km != null) { | |
35 problem.setAttribute("km", String.valueOf(km)); | |
36 } | |
37 problem.setTextContent(msg); | |
38 return problem; | |
39 } | |
40 } // class Problem | |
41 | |
42 protected List<Problem> problems; | |
43 | |
44 public Calculation() { | |
45 } | |
46 | |
47 protected List<Problem> checkProblems() { | |
48 if (problems == null) { | |
49 problems = new ArrayList<Problem>(); | |
50 } | |
51 return problems; | |
52 } | |
53 | |
54 public void addProblem(String msg) { | |
55 checkProblems().add(new Problem(msg)); | |
56 } | |
57 | |
58 public void addProblem(double km, String msg) { | |
59 checkProblems().add(new Problem(km, msg)); | |
60 } | |
61 | |
62 public boolean hasProblems() { | |
63 return problems != null && !problems.isEmpty(); | |
64 } | |
65 | |
66 public int numProblems() { | |
67 return problems != null ? problems.size() : 0; | |
68 } | |
69 | |
70 public List<Problem> getProblems() { | |
71 return problems; | |
72 } | |
73 | |
74 public void toXML(Document document) { | |
75 | |
76 Element root = document.createElement("problems"); | |
77 | |
78 if (hasProblems()) { | |
79 for (Problem problem: problems) { | |
80 root.appendChild(problem.toXML(document)); | |
81 } | |
82 } | |
83 | |
84 document.appendChild(root); | |
85 } | |
86 } | |
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |