Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImportRange.java @ 9709:b74f817435fe
comment removed
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 27 Jan 2021 11:47:38 +0100 |
parents | e541938dd3ab |
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 |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
11 import java.math.BigDecimal; |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
12 |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
13 import org.apache.log4j.Logger; |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
14 import org.dive4elements.river.model.Range; |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
15 import org.dive4elements.river.model.River; |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
16 |
4713
2c99995395f5
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
500
diff
changeset
|
17 /** 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
|
18 public class ImportRange |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
19 implements Comparable<ImportRange> |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 { |
8200
9d2e69f971f5
sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7376
diff
changeset
|
21 /** Private log. */ |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
22 private static Logger log = Logger.getLogger(ImportRange.class); |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
23 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
24 protected BigDecimal a; |
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
25 protected BigDecimal b; |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
26 |
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
27 protected Range peer; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public ImportRange() { |
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 |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
32 public ImportRange(final BigDecimal a) { |
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
|
33 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
|
34 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
|
35 } |
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 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
37 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
|
38 |
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
|
39 // 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
|
40 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
|
41 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
|
42 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
|
43 } |
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 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
|
45 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
|
46 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
|
47 } |
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 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
|
49 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
|
50 } |
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 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
|
52 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
|
53 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
|
54 } |
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 else { |
7221
70ab9e8cdefb
Range importer: Do not allow to set invalid a or b.
Tom Gottfried <tom@intevation.de>
parents:
7003
diff
changeset
|
56 if (a.compareTo(b) > 0) { |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
57 final 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
|
58 } |
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
|
59 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
|
60 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
|
61 } |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
62 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
63 |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
64 private static final int compare(final BigDecimal a, final BigDecimal b) { |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
65 if (a == null && b == null) { |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
66 return 0; |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
67 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
68 if (a == null && b != null) { |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
69 return -1; |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
70 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
71 if (a != null && b == null) { |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
72 return +1; |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
73 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
74 return a.compareTo(b); |
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 |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
77 @Override |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
78 public int compareTo(final ImportRange other) { |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
79 final int cmp = compare(this.a, other.a); |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
80 if (cmp != 0) return cmp; |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
81 return compare(this.b, other.b); |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
84 public BigDecimal getA() { |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
85 return this.a; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
88 public void setA(final BigDecimal a) { |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
89 if (this.b != null && a.compareTo(this.b) >= 0) { |
8856 | 90 throw new IllegalArgumentException( |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
91 "a (" + a + ") must be smaller than b (" + this.b + ")."); |
7221
70ab9e8cdefb
Range importer: Do not allow to set invalid a or b.
Tom Gottfried <tom@intevation.de>
parents:
7003
diff
changeset
|
92 } |
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
|
93 this.a = a; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
96 public BigDecimal getB() { |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
97 return this.b; |
189
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
98 } |
bc3747a371cc
First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
99 |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
100 public void setB(final BigDecimal b) { |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
101 if (b != null && b.compareTo(this.a) <= 0) { |
8856 | 102 throw new IllegalArgumentException( |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
103 "b (" + b + ") must be greater than a (" + this.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
|
104 } |
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
|
105 this.b = b; |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
107 |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
108 /** |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
109 * Difference of a and b |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
110 * |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
111 * @return b - a, or NaN if a or b null |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
112 */ |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
113 public double difference() { |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
114 if ((this.a != null) && (this.b != null)) |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
115 return this.b.subtract(this.a).doubleValue(); |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
116 else |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
117 return Double.NaN; |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
118 } |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
119 |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
120 public Range getPeer(final River river) { |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
121 if (this.peer == null) { |
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
122 this.peer = ImporterSession.getInstance().getRange(river, this.a, this.b); |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
123 } |
8976
e541938dd3ab
Range data handled consistently as BigDecimal to minimize the fractional part of a and b
mschaefer
parents:
8856
diff
changeset
|
124 return this.peer; |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
125 } |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |