view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FastCrossSectionChunk.java @ 2121:70ef5fdc7414

Cosmetics, added new DataFacet constructor. flys-artifacts/trunk@3691 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 17 Jan 2012 07:55:12 +0000
parents dc28ea60b53d
children d626ae185305
line wrap: on
line source
package de.intevation.flys.artifacts.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

import java.io.Serializable;

import de.intevation.flys.model.CrossSectionLine;
import de.intevation.flys.model.CrossSection;

public class FastCrossSectionChunk
implements   Serializable
{
    public static final String PREFIX = "FCSC:";
    public static final double KM_RANGE = 1.0;

    protected double startKm;
    protected int    crossSectionId;

    protected List<FastCrossSectionLine> crossSectionLines;

    public FastCrossSectionChunk() {
    }

    public FastCrossSectionChunk(CrossSection cs, double km) {

        crossSectionId = cs.getId();
        startKm = Math.floor(km);
        double stopKm = startKm + KM_RANGE;

        List<CrossSectionLine> csls = cs.getLines(startKm, stopKm);

        crossSectionLines = new ArrayList
            <FastCrossSectionLine>(csls.size());

        for (CrossSectionLine csl: csls) {
            crossSectionLines.add(new FastCrossSectionLine(csl));
        }
    }

    public FastCrossSectionLine getCrossSectionLine(double km) {
        FastCrossSectionLine key = new FastCrossSectionLine(km);
        int pos = Collections.binarySearch(
            crossSectionLines, key, FastCrossSectionLine.KM_CMP);
        return pos < 0 ? null : crossSectionLines.get(pos);
    }

    public static String createHashKey(CrossSection cs, double km) {
        return PREFIX + cs.getId() + ":" + (int)Math.floor(km);
    }

    public String getHashKey() {
        return PREFIX + crossSectionId + ":" + (int)Math.floor(startKm);
    }

    public double getStartKm() {
        return startKm;
    }

    public void setStartKm(double startKm) {
        this.startKm = startKm;
    }

    public double getStopKm() {
        return startKm + KM_RANGE;
    }

    public int getCrossSectionId() {
        return crossSectionId;
    }

    public void setCrossSectionId(int crossSectionId) {
        this.crossSectionId = crossSectionId;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org