Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/FastCrossSectionChunk.java @ 6267:484a19628b1e
Added TODO about braindead code.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 11 Jun 2013 12:00:57 +0200 |
parents | c297a61115d0 |
children | 44ee7d26eb18 |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
9 package org.dive4elements.river.artifacts.model; |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 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
|
12 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
|
13 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 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
|
15 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
16 import org.dive4elements.river.model.CrossSection; |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
18 import org.dive4elements.river.model.FastCrossSectionLine; |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
19 |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
20 import org.apache.log4j.Logger; |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
21 |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 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
|
23 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
|
24 { |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
25 private static Logger log = Logger.getLogger(FastCrossSectionChunk.class); |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
26 |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 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
|
28 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
|
29 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 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
|
31 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
|
32 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 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
|
34 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 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
|
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 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 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
|
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 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
|
41 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
|
42 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
|
43 |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
44 long startTime = System.currentTimeMillis(); |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
46 crossSectionLines = cs.getFastLines(startKm, stopKm); |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
48 long stopTime = System.currentTimeMillis(); |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
49 |
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
50 if (log.isDebugEnabled()) { |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2126
diff
changeset
|
51 log.debug("Fetching cross section lines took " + |
2126
d626ae185305
Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2119
diff
changeset
|
52 (float)(stopTime-startTime)/1000f + " secs."); |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
6265 | 56 /** Finds the FastCrossSectionLine at km (null if not found). */ |
2119
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 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
|
58 FastCrossSectionLine key = new FastCrossSectionLine(km); |
6267
484a19628b1e
Added TODO about braindead code.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6266
diff
changeset
|
59 // TODO follwing is braindead. Create the list in sorted fashion |
484a19628b1e
Added TODO about braindead code.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6266
diff
changeset
|
60 // instead and remove sorting here. |
6266
c297a61115d0
issue1267: Sort the list of FastCrossSections before binarySearching it.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6265
diff
changeset
|
61 Collections.sort(crossSectionLines, FastCrossSectionLine.KM_CMP); |
2119
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 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
|
68 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
|
69 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 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
|
72 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
|
73 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 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
|
76 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
|
77 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 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
|
80 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
|
81 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 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
|
84 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
|
85 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 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
|
88 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
|
89 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 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
|
92 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
|
93 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |