Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FastCrossSectionChunk.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 5642a83420f2 |
children |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts.model; | |
2 | |
3 import java.util.List; | |
4 import java.util.Collections; | |
5 | |
6 import java.io.Serializable; | |
7 | |
8 import de.intevation.flys.model.CrossSection; | |
9 | |
10 import de.intevation.flys.model.FastCrossSectionLine; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 | |
14 public class FastCrossSectionChunk | |
15 implements Serializable | |
16 { | |
17 private static Logger log = Logger.getLogger(FastCrossSectionChunk.class); | |
18 | |
19 public static final String PREFIX = "FCSC:"; | |
20 public static final double KM_RANGE = 1.0; | |
21 | |
22 protected double startKm; | |
23 protected int crossSectionId; | |
24 | |
25 protected List<FastCrossSectionLine> crossSectionLines; | |
26 | |
27 public FastCrossSectionChunk() { | |
28 } | |
29 | |
30 public FastCrossSectionChunk(CrossSection cs, double km) { | |
31 | |
32 crossSectionId = cs.getId(); | |
33 startKm = Math.floor(km); | |
34 double stopKm = startKm + KM_RANGE; | |
35 | |
36 long startTime = System.currentTimeMillis(); | |
37 | |
38 crossSectionLines = cs.getFastLines(startKm, stopKm); | |
39 | |
40 long stopTime = System.currentTimeMillis(); | |
41 | |
42 if (log.isDebugEnabled()) { | |
43 log.debug("Fetching cross section lines took " + | |
44 (float)(stopTime-startTime)/1000f + " secs."); | |
45 } | |
46 } | |
47 | |
48 public FastCrossSectionLine getCrossSectionLine(double km) { | |
49 FastCrossSectionLine key = new FastCrossSectionLine(km); | |
50 int pos = Collections.binarySearch( | |
51 crossSectionLines, key, FastCrossSectionLine.KM_CMP); | |
52 return pos < 0 ? null : crossSectionLines.get(pos); | |
53 } | |
54 | |
55 public static String createHashKey(CrossSection cs, double km) { | |
56 return PREFIX + cs.getId() + ":" + (int)Math.floor(km); | |
57 } | |
58 | |
59 public String getHashKey() { | |
60 return PREFIX + crossSectionId + ":" + (int)Math.floor(startKm); | |
61 } | |
62 | |
63 public double getStartKm() { | |
64 return startKm; | |
65 } | |
66 | |
67 public void setStartKm(double startKm) { | |
68 this.startKm = startKm; | |
69 } | |
70 | |
71 public double getStopKm() { | |
72 return startKm + KM_RANGE; | |
73 } | |
74 | |
75 public int getCrossSectionId() { | |
76 return crossSectionId; | |
77 } | |
78 | |
79 public void setCrossSectionId(int crossSectionId) { | |
80 this.crossSectionId = crossSectionId; | |
81 } | |
82 } | |
83 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |