view flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/RangeAccess.java @ 4850:c9a27912840d

RangeAccess: Add accidentally omitted implementation of getLocations from FLYSUtils.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 23 Jan 2013 12:10:47 +0100
parents 15e55fdbb402
children 9790a284246c
line wrap: on
line source
package de.intevation.flys.artifacts.access;

import org.apache.log4j.Logger;

import gnu.trove.TDoubleArrayList;

import de.intevation.artifacts.CallContext;
import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.WINFOArtifact;

import de.intevation.flys.utils.FLYSUtils;


/** For the moment, light-weight wrapper around FLYSUtils. */
// TODO employ 'Caching' like other Accesses, remove usage of FLYSUtils.
public class RangeAccess
extends RiverAccess
{
    private static Logger logger = Logger.getLogger(RangeAccess.class);

    private CallContext context;

    Double from;

    Double to;

    Double step;


    public RangeAccess(FLYSArtifact artifact, CallContext context) {
        super(artifact);
        this.context = context;
    }


    /**
     * Return sorted array of locations at which stuff was calculated
     * (from ld_locations data), null if not parameterized this way.
     */
    public double[] getLocations() {
        String locationStr = getString("ld_locations");

        if (locationStr == null || locationStr.length() == 0) {
            if (getArtifact() instanceof WINFOArtifact) {
                WINFOArtifact winfo = (WINFOArtifact) getArtifact();
                if (winfo.getReferenceStartKm() != null && winfo.getReferenceEndKms() != null) {
                    return new double[]
                        {
                            winfo.getReferenceStartKm().doubleValue(),
                            winfo.getReferenceEndKms()[0]
                        };
                }
            }
            return null;
        }

        String[] tmp               = locationStr.split(" ");
        TDoubleArrayList locations = new TDoubleArrayList();

        for (String l: tmp) {
            try {
                locations.add(Double.parseDouble(l));
            }
            catch (NumberFormatException nfe) {
                logger.debug(nfe.getLocalizedMessage(), nfe);
            }
        }

        locations.sort();

        return locations.toNativeArray();
    }


    /** Return ld_from data (in km). */
    public double getFrom() {
        if (from == null) {
            from = getDouble("ld_from");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("from: '" + from + "'");
        }

        return from.doubleValue();
    }


    /** Return ld_to data (in km). */
    public double getTo() {
        if (to == null) {
            to = getDouble("ld_to");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("to: '" + to + "'");
        }

        return to.doubleValue();
    }


    /** Step width for calculation. */
    public Double getStep() {

        if (step == null) {
            step = getDouble("ld_step");
        }

        if (logger.isDebugEnabled()) {
            logger.debug("step: '" + step + "'");
        }

        return step;
    }


    /**
     * Get min and max kilometer, independent of parametization
     * (ld_from/to vs ld_locations).
     */
    public double[] getKmRange() {
        return FLYSUtils.getKmRange(this.getArtifact());
    }


    public double[] getKmFromTo() {
         return FLYSUtils.getKmFromTo(this.getArtifact());
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org