view flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedQualityAccess.java @ 4118:116464587b51

Documentation.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 12 Oct 2012 15:14:29 +0200
parents 7fa38f8bcd8d
children d5d2faf14522
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.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.model.DateRange;


public class BedQualityAccess extends RiverAccess {

    private static final Logger logger = Logger
        .getLogger(BedQualityAccess.class);

    private Double from;
    private Double to;
    private List<String> bedDiameter;
    private List<String> bedloadDiameter;
    private List<DateRange> ranges;

    public BedQualityAccess(FLYSArtifact artifact) {
        super(artifact);
    }

    public double getFrom() {
        if (from == null) {
            from = getDouble("ld_from");
        }
        return from.doubleValue();
    }

    public double getTo() {
        if (to == null) {
            to = getDouble("ld_to");
        }
        return to.doubleValue();
    }

    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