annotate artifacts/src/main/java/org/dive4elements/river/artifacts/access/ExtremeAccess.java @ 8755:30b1ddadf275

(issue1801) Unify reference gauge finding code The basic way as described in the method comment of the determineRefGauge method is now used in the WINFOArtifact, MainValuesService and RiverUtils.getGauge method. RiverUtils.getGauge previously just returned the first gauge found. While this is now a behavior change I believe that it is always more correct then the undeterministic behavior of the previous implmenentation.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 24 Jun 2015 14:07:26 +0200
parents e4606eae8ea5
children 5e38e2924c07
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: 5867
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: 5867
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: 4825
diff changeset
9 package org.dive4elements.river.artifacts.access;
4825
f8217f1fef2e ExtremeAccess, RangeAccess and callers: Refactored, moved getStep to RangeAccess.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4333
diff changeset
10
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
11 import org.dive4elements.river.artifacts.D4EArtifact;
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
12
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4825
diff changeset
13 import org.dive4elements.river.artifacts.model.RangeWithValues;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4825
diff changeset
14
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4825
diff changeset
15 import org.dive4elements.river.utils.DoubleUtil;
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
16
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
17 import java.util.ArrayList;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
18 import java.util.List;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
19
3775
d52c4ca93ffb More infrastructure stuff for the "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import org.apache.log4j.Logger;
d52c4ca93ffb More infrastructure stuff for the "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
4040
363445873737 Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3777
diff changeset
22 /** Access data used for extreme value analysis. */
3775
d52c4ca93ffb More infrastructure stuff for the "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public class ExtremeAccess
4825
f8217f1fef2e ExtremeAccess, RangeAccess and callers: Refactored, moved getStep to RangeAccess.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4333
diff changeset
24 extends RangeAccess
3775
d52c4ca93ffb More infrastructure stuff for the "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
26 /** Our private log. */
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
27 private static Logger log = Logger.getLogger(ExtremeAccess.class);
3775
d52c4ca93ffb More infrastructure stuff for the "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
29 protected Long start;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
30 protected Long end;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
31
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
32 protected Double percent;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
33
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
34 protected String function;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
35
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
36 protected List<RangeWithValues> ranges;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
37
4052
6d8c7a00e74e Do cumentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4040
diff changeset
38
6101
a0078e5e3b39 Removed unused context from RangeAccess and subclasses leading to some dead code removal.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
39 public ExtremeAccess(D4EArtifact artifact) {
a0078e5e3b39 Removed unused context from RangeAccess and subclasses leading to some dead code removal.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
40 super(artifact);
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
41 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
42
4332
0545002e112c ExtremeAccess: Renamed log to logger, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4272
diff changeset
43
0545002e112c ExtremeAccess: Renamed log to logger, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4272
diff changeset
44 /** Returns the percent given. */
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
45 public Double getPercent() {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
46
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
47 if (percent == null) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
48 percent = getDouble("percent");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
49 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
50
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
51 if (log.isDebugEnabled()) {
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
52 log.debug("percent: '" + percent + "'");
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
53 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
54
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
55 return percent;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
56 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
57
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
58 public String getFunction() {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
59 if (function == null) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
60 function = getString("function");
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
61 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
62
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
63 if (log.isDebugEnabled()) {
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
64 log.debug("function: '" + function + "'");
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
65 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
66
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
67 return function;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
68 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
69
4333
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
70
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
71 /** Find first RangeWithValues for which the given location
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
72 * is within the range and return its values.
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
73 * @return values of first suitable rangewithvalues or null.
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
74 */
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
75 public double[] getValuesForRange(double location) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
76 log.debug("ExtemeAcces.getValuesForRange");
4333
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
77 for (RangeWithValues rangeValues: getRanges()) {
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
78 if (rangeValues.inside(location)) {
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
79 return rangeValues.getValues();
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
80 }
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
81 }
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
82 return null;
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
83 }
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
84
2d3f8af87b7b ExtremeAccess: Added helper method to find the values for (the range of) a km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4332
diff changeset
85
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
86 public List<RangeWithValues> getRanges() {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
87
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
88 if (ranges == null) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
89 String rangesS = getString("ranges");
4272
270f3ac8a82e In ExtremeAccess, fix typo that lead to incorrect null-check.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4052
diff changeset
90 if (rangesS == null) {
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
91 return null;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
92 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
93 ranges = new ArrayList<RangeWithValues>();
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
94 DoubleUtil.parseSegments(rangesS, new DoubleUtil.SegmentCallback() {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
95 @Override
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
96 public void newSegment(double from, double to, double [] values) {
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
97 ranges.add(new RangeWithValues(from, to, values));
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
98 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
99 });
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
100 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
101
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
102 if (log.isDebugEnabled()) {
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6102
diff changeset
103 log.debug("ranges: " + ranges);
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
104 }
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
105
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
106 return ranges;
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3775
diff changeset
107 }
3775
d52c4ca93ffb More infrastructure stuff for the "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 }
d52c4ca93ffb More infrastructure stuff for the "Auslagerung extremer Wasserspiegellagen".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org