comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxAccess.java @ 8946:5d5d482da3e9

Implementing SINFO - FlowDepthMinMax calculation
author gernotbelger
date Tue, 13 Mar 2018 18:49:33 +0100
parents
children 0adc6d04de95
comparison
equal deleted inserted replaced
8945:4a6b6a3c279c 8946:5d5d482da3e9
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10
11 package org.dive4elements.river.artifacts.sinfo.flowdepthminmax;
12
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.List;
17
18 import org.apache.commons.lang.math.DoubleRange;
19 import org.dive4elements.river.artifacts.access.RangeAccess;
20 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
21 import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode;
22 import org.dive4elements.river.artifacts.sinfo.flowdepth.WstSoundingIdPair;
23
24 /**
25 * Access to the flow depth calculation type specific SInfo artifact data.
26 * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent
27 * reference to the artifact instance.
28 * Hence we do NOT cache any data.
29 *
30 * @author Gernot Belger
31 */
32 final class FlowDepthMinMaxAccess extends RangeAccess {
33
34 public static class MinMaxIdPair {
35
36 private final String wstId;
37
38 private final String minSoundingId;
39
40 private final String maxSoundingId;
41
42 public MinMaxIdPair(final String wstId, final String minSoundingId, final String maxSoundingId) {
43 this.wstId = wstId;
44 this.minSoundingId = minSoundingId;
45 this.maxSoundingId = maxSoundingId;
46 }
47
48 public String getWstId() {
49 return this.wstId;
50 }
51
52 public String getMinSoundingId() {
53 return this.minSoundingId;
54 }
55
56 public String getMaxSoundingId() {
57 return this.maxSoundingId;
58 }
59 }
60
61 private static final String FIELD_DIFFIDS = "diffids";
62
63 public FlowDepthMinMaxAccess(final SINFOArtifact artifact) {
64 super(artifact);
65
66 /* assert calculation mode */
67 final SinfoCalcMode calculationMode = artifact.getCalculationMode();
68 assert (calculationMode == SinfoCalcMode.sinfo_calc_flow_depth_minmax);
69 }
70
71 public DoubleRange getRange() {
72 final double from = getFrom();
73 final double to = getTo();
74 return new DoubleRange(from, to);
75 }
76
77 public Collection<MinMaxIdPair> getMinMaxPairs() {
78
79 final String diffids = getString(FIELD_DIFFIDS);
80
81 /* fetch the raw configured pairs */
82 final List<WstSoundingIdPair> diffPairs = WstSoundingIdPair.parsePairs(diffids);
83
84 /* now sort eleemnts into pairs of TL/KL */
85 // FIXME: use sounding-ids to determine how pairs fit together
86 // or, let the ui already enforce it somehow
87
88 final List<MinMaxIdPair> minMaxPairs = new ArrayList<>(diffPairs.size());
89 // FIXME: at the moment, we simply pair by order
90 for (int i = 0; i < diffPairs.size(); i++) {
91
92 final WstSoundingIdPair minPair = diffPairs.get(i);
93
94 if (i < diffPairs.size() - 1) {
95 final WstSoundingIdPair maxPair = diffPairs.get(i + 1);
96 minMaxPairs.add(new MinMaxIdPair(minPair.getWstId(), minPair.getSoundingId(), maxPair.getSoundingId()));
97 i++;
98 } else {
99 minMaxPairs.add(new MinMaxIdPair(minPair.getWstId(), minPair.getSoundingId(), null));
100 }
101 }
102
103 return Collections.unmodifiableCollection(minMaxPairs);
104 }
105 }

http://dive4elements.wald.intevation.org