sascha@2119: package de.intevation.flys.artifacts.model; sascha@2119: sascha@2119: import java.util.ArrayList; sascha@2119: import java.util.List; sascha@2119: import java.util.Collections; sascha@2119: sascha@2119: import java.io.Serializable; sascha@2119: sascha@2119: import de.intevation.flys.model.CrossSectionLine; sascha@2119: import de.intevation.flys.model.CrossSection; sascha@2119: sascha@2119: public class FastCrossSectionChunk sascha@2119: implements Serializable sascha@2119: { sascha@2119: public static final String PREFIX = "FCSC:"; sascha@2119: public static final double KM_RANGE = 1.0; sascha@2119: sascha@2119: protected double startKm; sascha@2119: protected int crossSectionId; sascha@2119: sascha@2119: protected List crossSectionLines; sascha@2119: sascha@2119: public FastCrossSectionChunk() { sascha@2119: } sascha@2119: sascha@2119: public FastCrossSectionChunk(CrossSection cs, double km) { sascha@2119: sascha@2119: crossSectionId = cs.getId(); sascha@2119: startKm = Math.floor(km); sascha@2119: double stopKm = startKm + KM_RANGE; sascha@2119: sascha@2119: List csls = cs.getLines(startKm, stopKm); sascha@2119: sascha@2119: crossSectionLines = new ArrayList sascha@2119: (csls.size()); sascha@2119: sascha@2119: for (CrossSectionLine csl: csls) { sascha@2119: crossSectionLines.add(new FastCrossSectionLine(csl)); sascha@2119: } sascha@2119: } sascha@2119: sascha@2119: public FastCrossSectionLine getCrossSectionLine(double km) { sascha@2119: FastCrossSectionLine key = new FastCrossSectionLine(km); sascha@2119: int pos = Collections.binarySearch( sascha@2119: crossSectionLines, key, FastCrossSectionLine.KM_CMP); sascha@2119: return pos < 0 ? null : crossSectionLines.get(pos); sascha@2119: } sascha@2119: sascha@2119: public static String createHashKey(CrossSection cs, double km) { sascha@2119: return PREFIX + cs.getId() + ":" + (int)Math.floor(km); sascha@2119: } sascha@2119: sascha@2119: public String getHashKey() { sascha@2119: return PREFIX + crossSectionId + ":" + (int)Math.floor(startKm); sascha@2119: } sascha@2119: sascha@2119: public double getStartKm() { sascha@2119: return startKm; sascha@2119: } sascha@2119: sascha@2119: public void setStartKm(double startKm) { sascha@2119: this.startKm = startKm; sascha@2119: } sascha@2119: sascha@2119: public double getStopKm() { sascha@2119: return startKm + KM_RANGE; sascha@2119: } sascha@2119: sascha@2119: public int getCrossSectionId() { sascha@2119: return crossSectionId; sascha@2119: } sascha@2119: sascha@2119: public void setCrossSectionId(int crossSectionId) { sascha@2119: this.crossSectionId = crossSectionId; sascha@2119: } sascha@2119: } sascha@2119: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :