Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java @ 5798:febeb4bb10a5
StaticWQKmsArtifact: implement WaterLineArtifact .
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 24 Apr 2013 08:21:52 +0200 |
parents | 37112235a946 |
children |
line wrap: on
line source
package de.intevation.flys.artifacts.access; import java.util.Date; import java.util.LinkedList; import java.util.List; import org.apache.log4j.Logger; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.DateRange; /** Access data of artifact used in BedQuality calculations. */ public class BedQualityAccess extends RangeAccess { private static final Logger logger = Logger .getLogger(BedQualityAccess.class); private List<String> bedDiameter; private List<String> bedloadDiameter; private List<DateRange> ranges; public BedQualityAccess(FLYSArtifact artifact, CallContext context) { super(artifact, context); } public List<DateRange> getDateRanges() { if (ranges == null) { ranges = extractRanges(getString("periods")); } return ranges; } public List<String> getBedDiameter() { String value = getString("bed_diameter"); if (bedDiameter == null && value != null) { bedDiameter = extractDiameter(value); } return bedDiameter; } public List<String> getBedloadDiameter() { String value = getString("load_diameter"); if (bedloadDiameter == null && value != null) { bedloadDiameter = extractDiameter(value); } return bedloadDiameter; } private List<DateRange> extractRanges(String dateString) { List<DateRange> list = new LinkedList<DateRange>(); String[] dates = dateString.split(";"); for (String s : dates) { String[] pair = s.split(","); try { long l1 = Long.parseLong(pair[0]); long l2 = Long.parseLong(pair[1]); Date first = new Date(l1); Date second = new Date(l2); DateRange dr = new DateRange(first, second); list.add(dr); } catch (NumberFormatException nfe) { continue; } } return list; } private List<String> extractDiameter(String value) { List<String> result = new LinkedList<String>(); String[] diameter = value.split(";"); for (String v : diameter) { logger.debug("diameter: " + v); String[] parts = v.split("\\."); result.add(parts[parts.length - 1]); logger.debug(parts[parts.length-1]); } return result; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :