annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/FastCrossSectionChunk.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
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
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 6515
diff changeset
20 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 6515
diff changeset
21 import org.apache.logging.log4j.LogManager;
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
22
6515
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6270
diff changeset
23 /**
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6270
diff changeset
24 * Number of FastCrossSectionLines, e.g. to store in cache and retrieve
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6270
diff changeset
25 * a single contain CrossSectionLine by its km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6270
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 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
28 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
29 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 6515
diff changeset
30 private static Logger log = LogManager.getLogger(FastCrossSectionChunk.class);
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
31
2119
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 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
33 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
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 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
36 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
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 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
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 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
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
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 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
44
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 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
46 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
47 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
48
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
49 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
50
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
51 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
52
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
53 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
54
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2119
diff changeset
55 if (log.isDebugEnabled()) {
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2126
diff changeset
56 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
57 (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
58 }
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
6265
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
61 /** 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
62 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
63 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
64 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
65 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
66 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
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 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
70 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
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 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
74 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
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 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
78 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
79 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 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
82 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
83 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 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
86 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
87 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 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
90 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
91 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 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
94 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
95 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 }
dc28ea60b53d Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org