Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FastCrossSectionChunk.java @ 2122:81312f84689a
Refactored to easier enjoy benefits of caching.
flys-artifacts/trunk@3692 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 17 Jan 2012 08:01:22 +0000 |
parents | dc28ea60b53d |
children | d626ae185305 |
rev | line source |
---|---|
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.util.Collections; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.io.Serializable; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.flys.model.CrossSectionLine; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.flys.model.CrossSection; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 public class FastCrossSectionChunk |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 implements Serializable |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public static final String PREFIX = "FCSC:"; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 public static final double KM_RANGE = 1.0; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 protected double startKm; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 protected int crossSectionId; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 protected List<FastCrossSectionLine> crossSectionLines; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 public FastCrossSectionChunk() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 public FastCrossSectionChunk(CrossSection cs, double km) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 crossSectionId = cs.getId(); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 startKm = Math.floor(km); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 double stopKm = startKm + KM_RANGE; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 List<CrossSectionLine> csls = cs.getLines(startKm, stopKm); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 crossSectionLines = new ArrayList |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 <FastCrossSectionLine>(csls.size()); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 for (CrossSectionLine csl: csls) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 crossSectionLines.add(new FastCrossSectionLine(csl)); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 public FastCrossSectionLine getCrossSectionLine(double km) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 FastCrossSectionLine key = new FastCrossSectionLine(km); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 int pos = Collections.binarySearch( |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 crossSectionLines, key, FastCrossSectionLine.KM_CMP); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 return pos < 0 ? null : crossSectionLines.get(pos); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 public static String createHashKey(CrossSection cs, double km) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 return PREFIX + cs.getId() + ":" + (int)Math.floor(km); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 public String getHashKey() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 return PREFIX + crossSectionId + ":" + (int)Math.floor(startKm); |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 public double getStartKm() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 return startKm; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 public void setStartKm(double startKm) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 this.startKm = startKm; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 public double getStopKm() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 return startKm + KM_RANGE; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 public int getCrossSectionId() { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return crossSectionId; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 public void setCrossSectionId(int crossSectionId) { |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 this.crossSectionId = crossSectionId; |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |