Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java @ 4240:4774902b0389
Use static String from FacetTypes.ChartType instead of literal.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 24 Oct 2012 14:35:59 +0200 |
parents | 7fa38f8bcd8d |
children | d5d2faf14522 |
rev | line source |
---|---|
3749
3dcc4feff243
Created the initial structure for MINFO bed quality chart generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.access; |
3dcc4feff243
Created the initial structure for MINFO bed quality chart generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
3760
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
3 import java.util.Date; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
4 import java.util.LinkedList; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
5 import java.util.List; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
6 |
3768
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
7 import org.apache.log4j.Logger; |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
8 |
3749
3dcc4feff243
Created the initial structure for MINFO bed quality chart generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.flys.artifacts.FLYSArtifact; |
3760
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
10 import de.intevation.flys.artifacts.model.DateRange; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
11 |
3749
3dcc4feff243
Created the initial structure for MINFO bed quality chart generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
3777
048a02e29808
Added base class RiverAccess to dense code to access the river name.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3768
diff
changeset
|
13 public class BedQualityAccess extends RiverAccess { |
3750
e560a9a10eb1
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3749
diff
changeset
|
14 |
3768
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
15 private static final Logger logger = Logger |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
16 .getLogger(BedQualityAccess.class); |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
17 |
3760
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
18 private Double from; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
19 private Double to; |
3768
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
20 private List<String> bedDiameter; |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
21 private List<String> bedloadDiameter; |
3760
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
22 private List<DateRange> ranges; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
23 |
3749
3dcc4feff243
Created the initial structure for MINFO bed quality chart generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 public BedQualityAccess(FLYSArtifact artifact) { |
3dcc4feff243
Created the initial structure for MINFO bed quality chart generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 super(artifact); |
3dcc4feff243
Created the initial structure for MINFO bed quality chart generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 } |
3760
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
27 |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
28 public double getFrom() { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
29 if (from == null) { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
30 from = getDouble("ld_from"); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
31 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
32 return from.doubleValue(); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
33 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
34 |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
35 public double getTo() { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
36 if (to == null) { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
37 to = getDouble("ld_to"); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
38 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
39 return to.doubleValue(); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
40 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
41 |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
42 public List<DateRange> getDateRanges() { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
43 if (ranges == null) { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
44 ranges = extractRanges(getString("periods")); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
45 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
46 return ranges; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
47 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
48 |
3768
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
49 public List<String> getBedDiameter() { |
3780
7fa38f8bcd8d
Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3777
diff
changeset
|
50 String value = getString("bed_diameter"); |
7fa38f8bcd8d
Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3777
diff
changeset
|
51 if (bedDiameter == null && value != null) { |
7fa38f8bcd8d
Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3777
diff
changeset
|
52 bedDiameter = extractDiameter(value); |
3768
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
53 } |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
54 return bedDiameter; |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
55 } |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
56 |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
57 public List<String> getBedloadDiameter() { |
3780
7fa38f8bcd8d
Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3777
diff
changeset
|
58 String value = getString("load_diameter"); |
7fa38f8bcd8d
Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3777
diff
changeset
|
59 if (bedloadDiameter == null && value != null) { |
7fa38f8bcd8d
Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3777
diff
changeset
|
60 bedloadDiameter = extractDiameter(value); |
3768
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
61 } |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
62 return bedloadDiameter; |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
63 } |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
64 |
3760
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
65 private List<DateRange> extractRanges(String dateString) { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
66 List<DateRange> list = new LinkedList<DateRange>(); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
67 String[] dates = dateString.split(";"); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
68 for (String s : dates) { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
69 String[] pair = s.split(","); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
70 try { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
71 long l1 = Long.parseLong(pair[0]); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
72 long l2 = Long.parseLong(pair[1]); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
73 Date first = new Date(l1); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
74 Date second = new Date(l2); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
75 DateRange dr = new DateRange(first, second); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
76 list.add(dr); |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
77 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
78 catch (NumberFormatException nfe) { |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
79 continue; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
80 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
81 } |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
82 return list; |
312870fded7e
Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3750
diff
changeset
|
83 } |
3768
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
84 |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
85 private List<String> extractDiameter(String value) { |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
86 List<String> result = new LinkedList<String>(); |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
87 String[] diameter = value.split(";"); |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
88 for (String v : diameter) { |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
89 logger.debug("diameter: " + v); |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
90 String[] parts = v.split("\\."); |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
91 result.add(parts[parts.length - 1]); |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
92 logger.debug(parts[parts.length-1]); |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
93 } |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
94 return result; |
00aafe1fedd7
Added getter for characteristic diameter in bed quality access.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3760
diff
changeset
|
95 } |
3749
3dcc4feff243
Created the initial structure for MINFO bed quality chart generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 } |
3777
048a02e29808
Added base class RiverAccess to dense code to access the river name.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3768
diff
changeset
|
97 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |