annotate backend/src/main/java/org/dive4elements/river/importer/ImportRange.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents 17db08570637
children e541938dd3ab 0a5239a1e46e
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
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
16 import org.apache.log4j.Logger;
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
17
4713
2c99995395f5 Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 500
diff changeset
18 /** 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
19 public class ImportRange
186
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
20 implements Comparable<ImportRange>
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 {
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7376
diff changeset
22 /** Private log. */
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
23 private static Logger log = Logger.getLogger(ImportRange.class);
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
24
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
25 protected BigDecimal a;
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
26 protected BigDecimal b;
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
27
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
28 protected Range peer;
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 public ImportRange() {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
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 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
34 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
35 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
36 }
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
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
38 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
39
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
40 // 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
41 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
42 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
43 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
44 }
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 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
46 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
47 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
48 }
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 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
50 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
51 }
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 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
53 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
54 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
55 }
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 else {
7221
70ab9e8cdefb Range importer: Do not allow to set invalid a or b.
Tom Gottfried <tom@intevation.de>
parents: 7003
diff changeset
57 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
58 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
59 }
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.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
61 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
62 }
186
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
63 }
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
64
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
65 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
66 if (a == null && b == null) {
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
67 return 0;
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
68 }
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
69 if (a == null && b != null) {
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
70 return -1;
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
71 }
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
72 if (a != null && b == null) {
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
73 return +1;
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
74 }
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
75 return a.compareTo(b);
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
76 }
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 public int compareTo(ImportRange other) {
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
79 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
80 if (cmp != 0) return cmp;
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
81 return compare(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() {
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
85 return 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
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
88 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
89 if (this.b != null && a.compareTo(b) >= 0) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
90 throw new IllegalArgumentException(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
91 "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
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() {
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
97 return b;
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
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
100 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
101 if (b != null && b.compareTo(a) <= 0) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
102 throw new IllegalArgumentException(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
103 "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
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
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
108 public Range getPeer(River river) {
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
109 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
110 peer = ImporterSession.getInstance().getRange(river, a, b);
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
111 }
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
112 return peer;
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
113 }
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org