sascha@2119: package de.intevation.flys.artifacts.model; sascha@2119: 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.CrossSection; sascha@2119: sascha@2126: import de.intevation.flys.model.FastCrossSectionLine; sascha@2126: sascha@2126: import org.apache.log4j.Logger; sascha@2126: sascha@2119: public class FastCrossSectionChunk sascha@2119: implements Serializable sascha@2119: { sascha@2126: private static Logger log = Logger.getLogger(FastCrossSectionChunk.class); sascha@2126: 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@2126: long startTime = System.currentTimeMillis(); sascha@2119: sascha@2126: crossSectionLines = cs.getFastLines(startKm, stopKm); sascha@2119: sascha@2126: long stopTime = System.currentTimeMillis(); sascha@2126: sascha@2126: if (log.isDebugEnabled()) { sascha@2126: log.debug("Fetching cross section lines took " + sascha@2126: (float)(stopTime-startTime)/1000f + " secs."); 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 :