Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java @ 9415:9744ce3c3853
Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
The facets also put the valid station range into their xml-metadata
author | gernotbelger |
---|---|
date | Thu, 16 Aug 2018 16:27:53 +0200 |
parents | 1e97d2e95410 |
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:
5636
diff
changeset
|
9 package org.dive4elements.river.artifacts.model; |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.io.Serializable; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
4334
048b3c3acd01
Range: Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3743
diff
changeset
|
13 /** A range from ... to .*/ |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 public class Range implements Serializable { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
5636
f7208c190e4a
Whitespace cosmetic.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4334
diff
changeset
|
16 public static final double EPSILON = 1e-5; |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
9415
9744ce3c3853
Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents:
6494
diff
changeset
|
18 private double start; |
9744ce3c3853
Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents:
6494
diff
changeset
|
19 private double end; |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 public Range() { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
3401
086326be721c
FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3138
diff
changeset
|
24 public Range(Range other) { |
086326be721c
FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3138
diff
changeset
|
25 start = other.start; |
086326be721c
FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3138
diff
changeset
|
26 end = other.end; |
086326be721c
FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3138
diff
changeset
|
27 } |
086326be721c
FixA: Overview: classify Q ranges by intersecting gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3138
diff
changeset
|
28 |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public Range(double start, double end) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 this.start = start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 this.end = end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
6380
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
34 public void setStart(double start) { |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
35 this.start = start; |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
36 } |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
37 |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public double getStart() { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 return start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
6380
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
42 |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
43 public void setEnd(double end) { |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
44 this.end = end; |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
45 } |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
46 |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 public double getEnd() { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 return end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
3743
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3401
diff
changeset
|
51 public boolean disjoint(double ostart, double oend) { |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3401
diff
changeset
|
52 return start > oend || ostart > end; |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3401
diff
changeset
|
53 } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3401
diff
changeset
|
54 |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 public boolean disjoint(Range other) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 return start > other.end || other.start > end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 public boolean intersects(Range other) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 return !disjoint(other); |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 public void extend(Range other) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 if (other.start < start) start = other.start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 if (other.end > end ) end = other.end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 public boolean clip(Range other) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 if (disjoint(other)) return false; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 if (other.start > start) start = other.start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 if (other.end < end ) end = other.end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 return true; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
4334
048b3c3acd01
Range: Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3743
diff
changeset
|
77 /** True if start>x<end (+ some epsilon) . */ |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 public boolean inside(double x) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 return x > start-EPSILON && x < end+EPSILON; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 } |
6372
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
81 |
6380
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
82 public boolean contains(double x) { |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
83 return inside(x); |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
84 } |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
85 |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
86 |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
87 /** Hash Code. */ |
6372
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
88 @Override |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
89 public int hashCode() { |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
90 return new Double(this.start).hashCode() ^ |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
91 new Double(this.end).hashCode(); |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
92 } |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
93 |
6380
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
94 |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
95 /** |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
96 * Compares start and end values with some epsilon. |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
97 */ |
6372
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
98 @Override |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
99 public boolean equals(Object otherRange) { |
6378
2ad7f3ada1dc
Artifacts: instanceof null == false, so extra null check needed.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6372
diff
changeset
|
100 if (otherRange instanceof Range) { |
6372
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
101 Range oRange = (Range) otherRange; |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
102 return |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
103 Math.abs(oRange.start - this.start) <= EPSILON |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
104 && Math.abs(oRange.end - this.end) <= EPSILON; |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
105 } |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
106 return false; |
01073acf6735
Add hashCode and equals implementation to Range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
107 } |
6380
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
108 |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
109 /** Returns clone with same start and end values. */ |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
110 @Override |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
111 public Object clone() { |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
112 return new Range(this.start, this.end); |
dc23ffb9d82c
Range: Add start and end setters, doc, clone function.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6378
diff
changeset
|
113 } |
6494
1e97d2e95410
Amtl. Linien: Fixed problem that only a random official line is detect.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6380
diff
changeset
|
114 |
1e97d2e95410
Amtl. Linien: Fixed problem that only a random official line is detect.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6380
diff
changeset
|
115 public String toString() { |
1e97d2e95410
Amtl. Linien: Fixed problem that only a random official line is detect.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6380
diff
changeset
|
116 return "[Range: start=" + start + " end=" + end + "]"; |
1e97d2e95410
Amtl. Linien: Fixed problem that only a random official line is detect.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6380
diff
changeset
|
117 } |
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |