comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthAccess.java @ 8915:d9dbf0b74bc2

Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
author gernotbelger
date Wed, 28 Feb 2018 17:27:15 +0100
parents 7bbfb24e6eec
children 5d5d482da3e9
comparison
equal deleted inserted replaced
8914:e3519c3e7a0a 8915:d9dbf0b74bc2
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde 1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by 2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH 3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt 4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 * 5 *
6 * This file is Free Software under the GNU AGPL (>=v3) 6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
12 12
13 import java.util.ArrayList; 13 import java.util.ArrayList;
14 import java.util.Collection; 14 import java.util.Collection;
15 import java.util.Collections; 15 import java.util.Collections;
16 16
17 import org.apache.commons.lang.math.DoubleRange;
17 import org.dive4elements.river.artifacts.access.RangeAccess; 18 import org.dive4elements.river.artifacts.access.RangeAccess;
18 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; 19 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
19 import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode; 20 import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode;
20 import org.dive4elements.river.backend.utils.StringUtil; 21 import org.dive4elements.river.backend.utils.StringUtil;
21 22
22 /** 23 /**
23 * Access to the flow depth calculation type specific SInfo artifact data. 24 * Access to the flow depth calculation type specific SInfo artifact data.
24 * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent reference to the artifact instance. 25 * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent
26 * reference to the artifact instance.
25 * Hence we do NOT cache any data. 27 * Hence we do NOT cache any data.
26 * 28 *
27 * @author Gernot Belger 29 * @author Gernot Belger
28 */ 30 */
29 public class FlowDepthAccess 31 final class FlowDepthAccess extends RangeAccess {
30 extends RangeAccess 32 public static class DifferencesPair {
31 { 33 private final String wstId;
32 public static class DifferencesPair 34 private final String soundingId;
33 {
34 private final String wstId;
35 private final String soundingId;
36 35
37 public DifferencesPair( final String wstId, final String soundingId ) { 36 public DifferencesPair(final String wstId, final String soundingId) {
38 this.wstId = wstId; 37 this.wstId = wstId;
39 this.soundingId = soundingId; 38 this.soundingId = soundingId;
40 } 39 }
41
42 public String getWstId() {
43 return this.wstId;
44 }
45 40
46 public String getSoundingId() { 41 public String getWstId() {
47 return this.soundingId; 42 return this.wstId;
48 } 43 }
49 }
50 44
51 private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$ 45 public String getSoundingId() {
46 return this.soundingId;
47 }
48 }
52 49
53 public FlowDepthAccess(final SINFOArtifact artifact) { 50 private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$
54 super(artifact);
55 51
56 /* assert calculation mode */ 52 public FlowDepthAccess(final SINFOArtifact artifact) {
57 final SinfoCalcMode calculationMode = artifact.getCalculationMode(); 53 super(artifact);
58 assert(calculationMode == SinfoCalcMode.sinfo_calc_flow_depth);
59 }
60 54
61 public boolean isUseTransportBodies() { 55 /* assert calculation mode */
62 final Boolean useTkh = artifact.getDataAsBoolean( FIELD_USE_TKH ); 56 final SinfoCalcMode calculationMode = artifact.getCalculationMode();
63 return useTkh == null ? false : useTkh; 57 assert (calculationMode == SinfoCalcMode.sinfo_calc_flow_depth);
64 } 58 }
65 59
66 public Collection<DifferencesPair> getDifferencePairs() { 60 public DoubleRange getRange() {
61 final double from = getFrom();
62 final double to = getTo();
63 return new DoubleRange(from, to);
64 }
67 65
68 final Collection<DifferencesPair> diffPairs = new ArrayList<>(); 66 public boolean isUseTransportBodies() {
67 final Boolean useTkh = this.artifact.getDataAsBoolean(FIELD_USE_TKH);
68 return useTkh == null ? false : useTkh;
69 }
69 70
70 final String diffids = super.getString("diffids"); 71 public Collection<DifferencesPair> getDifferencePairs() {
71 if( diffids == null )
72 {
73 // Should never happen as this is handled by the ui
74 return Collections.emptyList();
75 }
76 72
77 // FIXME: this way of parsing the datacage-ids is repeated all over flys! 73 final Collection<DifferencesPair> diffPairs = new ArrayList<>();
78 final String datas[] = diffids.split("#");
79 for(int i = 0; i < datas.length; i+=2) {
80 final String leftId = StringUtil.unbracket( datas[i] );
81 final String rightId = StringUtil.unbracket( datas[i+1] );
82 74
83 diffPairs.add(new DifferencesPair(leftId, rightId)); 75 final String diffids = super.getString("diffids");
84 } 76 if (diffids == null) {
77 // Should never happen as this is handled by the ui
78 return Collections.emptyList();
79 }
85 80
86 return Collections.unmodifiableCollection(diffPairs); 81 // FIXME: this way of parsing the datacage-ids is repeated all over flys!
87 } 82 final String datas[] = diffids.split("#");
83 for (int i = 0; i < datas.length; i += 2) {
84 final String leftId = StringUtil.unbracket(datas[i]);
85 final String rightId = StringUtil.unbracket(datas[i + 1]);
86
87 diffPairs.add(new DifferencesPair(leftId, rightId));
88 }
89
90 return Collections.unmodifiableCollection(diffPairs);
91 }
88 } 92 }

http://dive4elements.wald.intevation.org