view flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java @ 4828:cb4cc6414447

BedHeightAccess: Use getFrom/getTo.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 21 Jan 2013 17:35:26 +0100
parents d5d2faf14522
children 37112235a946
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;


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 :

http://dive4elements.wald.intevation.org