comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java @ 3003:e5e6363e6cba

FixA: Explicit model for date ranges. flys-artifacts/trunk@4559 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 30 May 2012 14:45:36 +0000
parents 619fe13e2397
children 5d286d7e54cd
comparison
equal deleted inserted replaced
3002:e54dd69d306f 3003:e5e6363e6cba
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2
3 import de.intevation.artifactdatabase.data.StateData;
4
5 import de.intevation.flys.artifacts.model.fixings.DateRange;
6
7 import de.intevation.flys.utils.FLYSUtils;
8
9 import gnu.trove.TDoubleArrayList;
2 10
3 import java.util.ArrayList; 11 import java.util.ArrayList;
4 import java.util.Arrays; 12 import java.util.Arrays;
5 13 import java.util.Date;
6 import de.intevation.artifactdatabase.data.StateData;
7
8 import gnu.trove.TDoubleArrayList;
9
10 import de.intevation.flys.utils.FLYSUtils;
11 14
12 import org.apache.log4j.Logger; 15 import org.apache.log4j.Logger;
13 16
14 public class FixationArtifactAccess 17 public class FixationArtifactAccess
15 { 18 {
32 protected Integer qSectorEnd; 35 protected Integer qSectorEnd;
33 36
34 protected Long referenceStart; 37 protected Long referenceStart;
35 protected Long referenceEnd; 38 protected Long referenceEnd;
36 39
37 protected long [][] analysisPeriods; 40 protected DateRange [] analysisPeriods;
38 41
39 protected int [] events; 42 protected int [] events;
40 43
41 protected Boolean preprocessing; 44 protected Boolean preprocessing;
42 45
295 } 298 }
296 299
297 return referenceEnd; 300 return referenceEnd;
298 } 301 }
299 302
300 public long [][] getAnalysisPeriods() { 303 public DateRange [] getAnalysisPeriods() {
301 if (analysisPeriods == null) { 304 if (analysisPeriods == null) {
302 StateData sd = artifact.getData("ana_data"); 305 StateData sd = artifact.getData("ana_data");
303 306
304 if (sd == null) { 307 if (sd == null) {
305 log.warn("missing 'ana_data'"); 308 log.warn("missing 'ana_data'");
306 return null; 309 return null;
307 } 310 }
308 311
309 String data = (String)sd.getValue(); 312 String data = (String)sd.getValue();
310 String[] pairs = data.split(";"); 313 String[] pairs = data.split("\\s*;\\s*");
311 314
312 ArrayList<long[]> aPs = new ArrayList<long[]>(pairs.length); 315 ArrayList<DateRange> aPs = new ArrayList<DateRange>(pairs.length);
313 316
314 for (int i = 0; i < pairs.length; i++) { 317 for (int i = 0; i < pairs.length; i++) {
315 String[] fromTo = pairs[i].split(","); 318 String[] fromTo = pairs[i].split("\\s*,\\s*");
316 if (fromTo.length >= 2) { 319 if (fromTo.length >= 2) {
317 try { 320 try {
318 aPs.add(new long [] { 321 Date from = new Date(Long.parseLong(fromTo[0]));
319 Long.parseLong(fromTo[0]), 322 Date to = new Date(Long.parseLong(fromTo[1]));
320 Long.parseLong(fromTo[1]) 323 aPs.add(new DateRange(from, to));
321 });
322 } 324 }
323 catch (NumberFormatException nfe) { 325 catch (NumberFormatException nfe) {
324 log.warn("ana_data contains no long values.", nfe); 326 log.warn("ana_data contains no long values.", nfe);
325 } 327 }
326 } 328 }
327 } 329 }
328 330
329 analysisPeriods = aPs.toArray(new long[aPs.size()][]); 331 analysisPeriods = aPs.toArray(new DateRange[aPs.size()]);
330 } 332 }
331 333
332 if (log.isDebugEnabled()) { 334 if (log.isDebugEnabled()) {
333 for (int i = 0; i < analysisPeriods.length; ++i) { 335 for (int i = 0; i < analysisPeriods.length; ++i) {
334 long [] ap = analysisPeriods[i]; 336 DateRange ap = analysisPeriods[i];
335 log.debug("analysis period " + ap[0] + " - " + ap[1]); 337 log.debug("analysis period " +
338 ap.getFrom() + " - " + ap.getTo());
336 } 339 }
337 } 340 }
338 341
339 return analysisPeriods; 342 return analysisPeriods;
340 } 343 }

http://dive4elements.wald.intevation.org