comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixAnalysisAccess.java @ 3651:06a65baae494

merged flys-artifacts/2.9
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:43 +0200
parents 8160e62bbb3a
children acfd48384835
comparison
equal deleted inserted replaced
3549:6a8f83c538e3 3651:06a65baae494
1 package de.intevation.flys.artifacts.access;
2
3 import de.intevation.artifactdatabase.data.StateData;
4
5 import de.intevation.flys.artifacts.FLYSArtifact;
6
7 import de.intevation.flys.artifacts.model.DateRange;
8
9 import java.util.Arrays;
10 import java.util.Date;
11
12 import org.apache.log4j.Logger;
13
14 public class FixAnalysisAccess
15 extends FixAccess
16 {
17 private static Logger log = Logger.getLogger(FixAnalysisAccess.class);
18
19 protected DateRange referencePeriod;
20 protected DateRange [] analysisPeriods;
21
22 protected double [] qs;
23
24 public FixAnalysisAccess() {
25 }
26
27 public FixAnalysisAccess(FLYSArtifact artifact) {
28 super(artifact);
29 }
30
31 public DateRange getReferencePeriod() {
32 if (referencePeriod == null) {
33 StateData refStart = artifact.getData("ref_start");
34 StateData refEnd = artifact.getData("ref_end");
35
36 if (refStart == null || refEnd == null) {
37 log.warn("missing 'ref_start' or 'ref_start' value");
38 return null;
39 }
40
41 try {
42 long rs = Long.parseLong((String)refStart.getValue());
43 long re = Long.parseLong((String)refEnd .getValue());
44
45 if (rs > re) { long t = rs; rs = re; re = t; }
46
47 Date from = new Date(rs);
48 Date to = new Date(re);
49 referencePeriod = new DateRange(from, to);
50 }
51 catch (NumberFormatException nfe) {
52 log.warn("ref_start or ref_end is not an integer.");
53 }
54 }
55
56 return referencePeriod;
57 }
58
59 public DateRange [] getAnalysisPeriods() {
60 if (analysisPeriods == null) {
61 analysisPeriods = getDateRange("ana_data");
62 }
63
64 return analysisPeriods;
65 }
66
67 /**
68 * @return DateRange object ranging from eldest to youngest date
69 * of analysis and reference periods.
70 */
71 public DateRange getDateRange() {
72 DateRange refP = getReferencePeriod();
73
74 if (refP == null) {
75 return null;
76 }
77
78 Date from = refP.getFrom();
79 Date to = refP.getTo();
80
81 DateRange[] rs = getAnalysisPeriods();
82 for (DateRange r: rs) {
83 if (r.getFrom().before(from)) {
84 from = r.getFrom();
85 }
86 if (r.getTo().after(to)) {
87 to = r.getTo();
88 }
89 }
90
91 return new DateRange(from, to);
92 }
93
94 public double [] getQs() {
95 if (qs == null) {
96 qs = getDoubleArray("qs");
97 }
98
99 if (log.isDebugEnabled() && qs != null) {
100 log.debug("qs: " + Arrays.toString(qs));
101 }
102 return qs;
103 }
104 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org