Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImportRange.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 |
---|---|
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
9 package org.dive4elements.river.importer; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
11 import org.dive4elements.river.model.Range; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
12 import org.dive4elements.river.model.River; |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
13 |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
14 import java.math.BigDecimal; |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
15 |
9726 | 16 import org.apache.logging.log4j.Logger; |
17 import org.apache.logging.log4j.LogManager; | |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
18 |
4713
2c99995395f5
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
500
diff
changeset
|
19 /** A range that is about to be imported. */ |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public class ImportRange |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
21 implements Comparable<ImportRange> |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 { |
8200
9d2e69f971f5
sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7376
diff
changeset
|
23 /** Private log. */ |
9726 | 24 private static Logger log = LogManager.getLogger(ImportRange.class); |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
25 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
26 protected BigDecimal a; |
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
27 protected BigDecimal b; |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
28 |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
29 protected Range peer; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public ImportRange() { |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
8412
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8200
diff
changeset
|
34 public ImportRange(BigDecimal a) { |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8200
diff
changeset
|
35 this.a = a; |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8200
diff
changeset
|
36 this.b = null; |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8200
diff
changeset
|
37 } |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8200
diff
changeset
|
38 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
39 public ImportRange(BigDecimal a, BigDecimal b) { |
7003
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
40 |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7221
diff
changeset
|
41 // enforce a<b and set only a for zero-length ranges |
7003
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
42 if (a != null && b == null) { |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
43 this.a = a; |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
44 this.b = null; |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
45 } |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
46 else if (a == null && b != null) { |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
47 this.a = b; |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
48 this.b = null; |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
49 } |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
50 else if (a == null && b == null) { |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
51 throw new IllegalArgumentException("Both a and b are null."); |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
52 } |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
53 else if (a == b) { |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
54 this.a = a; |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
55 this.b = null; |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
56 } |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
57 else { |
7221
70ab9e8cdefb
Range importer: Do not allow to set invalid a or b.
Tom Gottfried <tom@intevation.de>
parents:
7003
diff
changeset
|
58 if (a.compareTo(b) > 0) { |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7221
diff
changeset
|
59 BigDecimal t = a; a = b; b = t; |
7003
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
60 } |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
61 this.a = a; |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
62 this.b = b; |
3d83a4cf33ba
Range import: enforce a<b not only for WSTs and set only a for zero-length ranges.
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5992
diff
changeset
|
63 } |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
64 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
65 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
66 private static final int compare(BigDecimal a, BigDecimal b) { |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
67 if (a == null && b == null) { |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
68 return 0; |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
69 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
70 if (a == null && b != null) { |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
71 return -1; |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
72 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
73 if (a != null && b == null) { |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
74 return +1; |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
75 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
76 return a.compareTo(b); |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
77 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
78 |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
79 public int compareTo(ImportRange other) { |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
80 int cmp = compare(a, other.a); |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
81 if (cmp != 0) return cmp; |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
82 return compare(b, other.b); |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
85 public BigDecimal getA() { |
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
86 return a; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
89 public void setA(BigDecimal a) { |
7221
70ab9e8cdefb
Range importer: Do not allow to set invalid a or b.
Tom Gottfried <tom@intevation.de>
parents:
7003
diff
changeset
|
90 if (this.b != null && a.compareTo(b) >= 0) { |
8856 | 91 throw new IllegalArgumentException( |
92 "a (" + a + ") must be smaller than b (" + b + ")."); | |
7221
70ab9e8cdefb
Range importer: Do not allow to set invalid a or b.
Tom Gottfried <tom@intevation.de>
parents:
7003
diff
changeset
|
93 } |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7221
diff
changeset
|
94 this.a = a; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
97 public BigDecimal getB() { |
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
98 return b; |
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
99 } |
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
100 |
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
101 public void setB(BigDecimal b) { |
7221
70ab9e8cdefb
Range importer: Do not allow to set invalid a or b.
Tom Gottfried <tom@intevation.de>
parents:
7003
diff
changeset
|
102 if (b != null && b.compareTo(a) <= 0) { |
8856 | 103 throw new IllegalArgumentException( |
104 "b (" + b + ") must be greater than a (" + a + ") or null."); | |
7221
70ab9e8cdefb
Range importer: Do not allow to set invalid a or b.
Tom Gottfried <tom@intevation.de>
parents:
7003
diff
changeset
|
105 } |
7376
4b26fd60105f
Replaced more tabs with spaces + minor cosmetics (removed out commented code from double precision branch).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7221
diff
changeset
|
106 this.b = b; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 } |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
108 |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
109 public Range getPeer(River river) { |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
110 if (peer == null) { |
500
d50cd3a632e0
Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
499
diff
changeset
|
111 peer = ImporterSession.getInstance().getRange(river, a, b); |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
112 } |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
113 return peer; |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
114 } |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |