diff 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
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthAccess.java	Tue Feb 27 18:06:52 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthAccess.java	Wed Feb 28 17:27:15 2018 +0100
@@ -1,6 +1,6 @@
 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
- * Software engineering by 
- *  Björnsen Beratende Ingenieure GmbH 
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
  *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
  *
  * This file is Free Software under the GNU AGPL (>=v3)
@@ -14,6 +14,7 @@
 import java.util.Collection;
 import java.util.Collections;
 
+import org.apache.commons.lang.math.DoubleRange;
 import org.dive4elements.river.artifacts.access.RangeAccess;
 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
 import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode;
@@ -21,68 +22,71 @@
 
 /**
  * Access to the flow depth calculation type specific SInfo artifact data.
- * 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. 
+ * 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.
  * Hence we do NOT cache any data.
- * 
+ *
  * @author Gernot Belger
  */
-public class FlowDepthAccess
-extends      RangeAccess
-{
-	public static class DifferencesPair
-	{
-		private final String wstId;
-		private final String soundingId;
-
-		public DifferencesPair( final String wstId, final String soundingId ) {
-			this.wstId = wstId;
-			this.soundingId = soundingId;
-		}
-		
-		public String getWstId() {
-			return this.wstId;
-		}
-
-		public String getSoundingId() {
-			return this.soundingId;
-		}
-	}
-
-	private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$
-
-	public FlowDepthAccess(final SINFOArtifact artifact) {
-		super(artifact);
+final class FlowDepthAccess extends RangeAccess {
+    public static class DifferencesPair {
+        private final String wstId;
+        private final String soundingId;
 
-		/* assert calculation mode */
-		final SinfoCalcMode calculationMode = artifact.getCalculationMode();
-		assert(calculationMode == SinfoCalcMode.sinfo_calc_flow_depth);
-	}
-
-	public boolean isUseTransportBodies() {
-		final Boolean useTkh = artifact.getDataAsBoolean( FIELD_USE_TKH );
-		return useTkh == null ? false : useTkh;
-	}
-
-	public Collection<DifferencesPair> getDifferencePairs() {
-
-		final Collection<DifferencesPair> diffPairs = new ArrayList<>();
+        public DifferencesPair(final String wstId, final String soundingId) {
+            this.wstId = wstId;
+            this.soundingId = soundingId;
+        }
 
-		 final String diffids = super.getString("diffids");
-		 if( diffids == null )
-		 {
-			 // Should never happen as this is handled by the ui
-			 return Collections.emptyList();
-		 }
+        public String getWstId() {
+            return this.wstId;
+        }
 
-		 // FIXME: this way of parsing the datacage-ids is repeated all over flys!
-		 final String datas[] = diffids.split("#");
-		 for(int i = 0; i < datas.length; i+=2) {
-			 final String leftId = StringUtil.unbracket( datas[i] );
-			 final String rightId = StringUtil.unbracket( datas[i+1] );
+        public String getSoundingId() {
+            return this.soundingId;
+        }
+    }
 
-			 diffPairs.add(new DifferencesPair(leftId, rightId));
-		 }
+    private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$
 
-		return Collections.unmodifiableCollection(diffPairs);
-	}
+    public FlowDepthAccess(final SINFOArtifact artifact) {
+        super(artifact);
+
+        /* assert calculation mode */
+        final SinfoCalcMode calculationMode = artifact.getCalculationMode();
+        assert (calculationMode == SinfoCalcMode.sinfo_calc_flow_depth);
+    }
+
+    public DoubleRange getRange() {
+        final double from = getFrom();
+        final double to = getTo();
+        return new DoubleRange(from, to);
+    }
+
+    public boolean isUseTransportBodies() {
+        final Boolean useTkh = this.artifact.getDataAsBoolean(FIELD_USE_TKH);
+        return useTkh == null ? false : useTkh;
+    }
+
+    public Collection<DifferencesPair> getDifferencePairs() {
+
+        final Collection<DifferencesPair> diffPairs = new ArrayList<>();
+
+        final String diffids = super.getString("diffids");
+        if (diffids == null) {
+            // Should never happen as this is handled by the ui
+            return Collections.emptyList();
+        }
+
+        // FIXME: this way of parsing the datacage-ids is repeated all over flys!
+        final String datas[] = diffids.split("#");
+        for (int i = 0; i < datas.length; i += 2) {
+            final String leftId = StringUtil.unbracket(datas[i]);
+            final String rightId = StringUtil.unbracket(datas[i + 1]);
+
+            diffPairs.add(new DifferencesPair(leftId, rightId));
+        }
+
+        return Collections.unmodifiableCollection(diffPairs);
+    }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org