[PATCH 1 of 3] Refactoring: Let RiverAccess.getRiver return an River

Wald Commits scm-commit at wald.intevation.org
Tue Oct 8 15:13:48 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1381236658 -7200
# Node ID a56fe3bc670082f567470af6995a15f65bb8cbbd
# Parent  0b32f8980fed666fe8f915021eb04e8613112ff5
Refactoring: Let RiverAccess.getRiver return an River.
Renamed getRiver in getRiverName. Update Callers.

diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RiverAccess.java	Tue Oct 08 14:50:58 2013 +0200
@@ -10,6 +10,10 @@
 
 import org.dive4elements.river.artifacts.D4EArtifact;
 
+import org.dive4elements.river.artifacts.model.RiverFactory;
+
+import org.dive4elements.river.model.River;
+
 import org.apache.log4j.Logger;
 
 /** Access to river data of an artifact. */
@@ -32,7 +36,7 @@
 
 
     /** Get River name. */
-    public String getRiver() {
+    public String getRiverName() {
         if (river == null) {
             river = getString("river");
         }
@@ -41,5 +45,13 @@
         }
         return river;
     }
+
+    public River getRiver() {
+        getRiverName();
+
+        return (river != null)
+            ? RiverFactory.getRiver(river)
+            : null;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SQRelationAccess.java	Tue Oct 08 14:50:58 2013 +0200
@@ -100,7 +100,7 @@
             return measurementStation;
         }
         List<MeasurementStation> candidates = MeasurementStation.getStationsAtKM(
-                getRiver(), getLocation());
+                getRiverName(), getLocation());
         if (candidates != null) {
             // Just take the first one as we only use the name
             // and that "should" be unique at the location
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation4.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation4.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation4.java	Tue Oct 08 14:50:58 2013 +0200
@@ -47,7 +47,7 @@
 
     public Calculation4(Calculation4Access access) {
         logger.debug("Calculation4Access.cnst");
-        String        river    = access.getRiver();
+        String        river    = access.getRiverName();
         List<Segment> segments = access.getSegments();
         double []     range    = access.getFromToStep();
         boolean       isQ      = access.isQ();
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java	Tue Oct 08 14:50:58 2013 +0200
@@ -46,7 +46,7 @@
         double [] vs = mode != null && mode == EvaluationMode.W
             ? access.getWs()
             : access.getQs();
-        riverName = access.getRiver();
+        riverName = access.getRiverName();
 
         Long officialGaugeNumber = access.getOfficialGaugeNumber();
 
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityCalculation.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityCalculation.java	Tue Oct 08 14:50:58 2013 +0200
@@ -98,7 +98,7 @@
         FlowVelocityAccess  access,
         List<DischargeZone> zones
     ) {
-        String riverName = access.getRiver();
+        String riverName = access.getRiverName();
         if (riverName == null) {
             logger.warn("No river name found");
             return Collections.<FlowVelocityModel>emptyList();
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityFilterFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityFilterFacet.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityFilterFacet.java	Tue Oct 08 14:50:58 2013 +0200
@@ -62,7 +62,7 @@
             RiverContext fc = (RiverContext)context.globalContext();
             ZoomScale scales = (ZoomScale)fc.get("zoomscale");
             RiverAccess access = new RiverAccess((D4EArtifact)artifact);
-            String river = access.getRiver();
+            String river = access.getRiverName();
 
             double radius = scales.getRadius(river, start, end);
             FlowVelocityData oldData = data[index];
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/extreme/ExtremeCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/extreme/ExtremeCalculation.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/extreme/ExtremeCalculation.java	Tue Oct 08 14:50:58 2013 +0200
@@ -63,7 +63,7 @@
     }
 
     public ExtremeCalculation(ExtremeAccess access) {
-        String                river    = access.getRiver();
+        String                river    = access.getRiverName();
         String                function = access.getFunction();
         Double                from     = access.getFrom();
         Double                to       = access.getTo();
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java	Tue Oct 08 14:50:58 2013 +0200
@@ -178,7 +178,7 @@
     }
 
     public FixCalculation(FixAccess access) {
-        String  river         = access.getRiver();
+        String  river         = access.getRiverName();
         Double  from          = access.getFrom();
         Double  to            = access.getTo();
         Double  step          = access.getStep();
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiameterDataFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiameterDataFacet.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiameterDataFacet.java	Tue Oct 08 14:50:58 2013 +0200
@@ -59,7 +59,7 @@
 
         QualityMeasurements measurements =
             QualityMeasurementFactory.getBedMeasurements(
-                access.getRiver(),
+                access.getRiverName(),
                 access.getFrom(),
                 access.getTo(),
                 access.getDateRanges().get(ndx).getFrom(),
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffCalculation.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffCalculation.java	Tue Oct 08 14:50:58 2013 +0200
@@ -38,7 +38,7 @@
     public CalculationResult calculate(BedDifferencesAccess access, CallContext context) {
         logger.info("BedDiffCalculation.calculate");
 
-        String river       = access.getRiver();
+        String river       = access.getRiverName();
         String yearEpoch   = access.getYearEpoch();
         int [][] heightIds = access.extractHeightIds(context);
 
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffEpochFilterFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffEpochFilterFacet.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffEpochFilterFacet.java	Tue Oct 08 14:50:58 2013 +0200
@@ -53,7 +53,7 @@
             RiverContext fc = (RiverContext)context.globalContext();
             ZoomScale scales = (ZoomScale)fc.get("zoomscale");
             RiverAccess access = new RiverAccess((D4EArtifact)artifact);
-            String river = access.getRiver();
+            String river = access.getRiverName();
 
             double radius = scales.getRadius(river, start, end);
             BedDiffEpochResult oldData = data[index];
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffYearFilterFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffYearFilterFacet.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffYearFilterFacet.java	Tue Oct 08 14:50:58 2013 +0200
@@ -53,7 +53,7 @@
             // Adaptive smoothing, based on zoom factor/diagram extents.
             ZoomScale scales = (ZoomScale)fc.get("zoomscale");
             RiverAccess access = new RiverAccess((D4EArtifact)artifact);
-            String river = access.getRiver();
+            String river = access.getRiverName();
 
             double radius = scales.getRadius(river, start, end);
             BedDiffYearResult oldData = data[index];
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityCalculation.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityCalculation.java	Tue Oct 08 14:50:58 2013 +0200
@@ -41,7 +41,7 @@
     public CalculationResult calculate(BedQualityAccess access) {
         logger.info("BedQualityCalculation.calculate");
 
-        String river = access.getRiver();
+        String river = access.getRiverName();
         Double from = access.getFrom();
         Double to = access.getTo();
         List<String> bedDiameter = access.getBedDiameter();
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedloadDiameterDataFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedloadDiameterDataFacet.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedloadDiameterDataFacet.java	Tue Oct 08 14:50:58 2013 +0200
@@ -59,7 +59,7 @@
 
         QualityMeasurements measurements =
             QualityMeasurementFactory.getBedloadMeasurements(
-                access.getRiver(),
+                access.getRiverName(),
                 access.getFrom(),
                 access.getTo(),
                 access.getDateRanges().get(ndx).getFrom(),
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Tue Oct 08 14:50:58 2013 +0200
@@ -46,7 +46,7 @@
     public CalculationResult calculate(SedimentLoadAccess access) {
         logger.info("SedimentLoadCalculation.calculate");
 
-        String river = access.getRiver();
+        String river = access.getRiverName();
         String yearEpoch = access.getYearEpoch();
         String unit = access.getUnit();
         int[] period = null;
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadUnknownFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadUnknownFacet.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadUnknownFacet.java	Tue Oct 08 14:50:58 2013 +0200
@@ -32,7 +32,7 @@
         D4EArtifact flys = (D4EArtifact) artifact;
 
         SedimentLoadAccess access = new SedimentLoadAccess(flys);
-        String river = access.getRiver();
+        String river = access.getRiverName();
         String unit  = access.getUnit();
         SedimentLoad[] unknown =
             SedimentLoadFactory.getSedimentLoadUnknown(
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQRelationCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQRelationCalculation.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQRelationCalculation.java	Tue Oct 08 14:50:58 2013 +0200
@@ -58,7 +58,7 @@
 
     public SQRelationCalculation(SQRelationAccess access) {
 
-        String    river    = access.getRiver();
+        String    river    = access.getRiverName();
         Double    location = access.getLocation();
         DateRange period   = access.getPeriod();
         Double    outliers = access.getOutliers();
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java	Tue Oct 08 14:50:58 2013 +0200
@@ -752,7 +752,7 @@
 
     protected void setAxis(D4EArtifact artifact, File dir, WSPLGENJob job) {
         DGMAccess access = new DGMAccess(artifact);
-        String river = access.getRiver();
+        String river = access.getRiverName();
         String srid  = String.valueOf(access.getDGM().getSrid());
         String srs   = "EPSG:" + srid;
 
@@ -799,7 +799,7 @@
 
     protected void setPro(D4EArtifact artifact, File dir, WSPLGENJob job) {
         DGMAccess access = new DGMAccess(artifact);
-        String river = access.getRiver();
+        String river = access.getRiverName();
         String srid  = String.valueOf(access.getDGM().getSrid());
         String srs   = "EPSG:" + srid;
 
@@ -874,7 +874,7 @@
         }
 
         DGMAccess access = new DGMAccess(artifact);
-        String river = access.getRiver();
+        String river = access.getRiverName();
         String srid  = String.valueOf(access.getDGM().getSrid());
         String srs   = "EPSG:" + srid;
 
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/states/HWSBarriersState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/HWSBarriersState.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/HWSBarriersState.java	Tue Oct 08 14:50:58 2013 +0200
@@ -88,7 +88,7 @@
         }
 
         MapAccess access = new MapAccess(artifact);
-        String river = access.getRiver();
+        String river = access.getRiverName();
         HWSContainer hwsLines = HWSFactory.getHWSLines(river);
         HWSContainer hwsPoints = HWSFactory.getHWSPoints(river);
         List<String> selected = access.getHWS();
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/states/extreme/ExtremeQInput.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/extreme/ExtremeQInput.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/extreme/ExtremeQInput.java	Tue Oct 08 14:50:58 2013 +0200
@@ -87,7 +87,7 @@
         D4EArtifact flysArtifact = (D4EArtifact) artifact;
 
         ExtremeAccess access = new ExtremeAccess(flysArtifact);
-        River river = RiverFactory.getRiver(access.getRiver());
+        River river = access.getRiver();
         WstValueTable wstValueTable = WstValueTableFactory.getTable(river);
 
         List<Range> ranges   = wstValueTable.findSegments(access.getFrom(),
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java	Tue Oct 08 14:50:58 2013 +0200
@@ -152,7 +152,7 @@
         }
         logger.debug("Created " + newFacets.size() + " new Facets.");
 
-        String river = access.getRiver();
+        String river = access.getRiverName();
         SedimentLoad[] unknown =
             SedimentLoadFactory.getSedimentLoadUnknown(river,
                 access.getUnit().replace("_per_","/"), type);
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java	Tue Oct 08 14:50:58 2013 +0200
@@ -72,7 +72,7 @@
             log.debug("Got a distinct relation" + sqRelations);
         } else {
             StaticSQRelationAccess access = new StaticSQRelationAccess(artifact);
-            String river = access.getRiver();
+            String river = access.getRiverName();
             String measurementStation = access.getMeasurementStation();
 
             int ms = -1;
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/exports/IsKmUpEvaluator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/IsKmUpEvaluator.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/IsKmUpEvaluator.java	Tue Oct 08 14:50:58 2013 +0200
@@ -23,7 +23,7 @@
     @Override
     public Object evaluate(D4EArtifact artifact, CallContext context) {
         RiverAccess access = new RiverAccess(artifact);
-        River river = RiverFactory.getRiver(access.getRiver());
+        River river = access.getRiver();
         return river == null
             ? Boolean.FALSE
             : river.getKmUp();
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/exports/extreme/ExtremeWQCurveGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/extreme/ExtremeWQCurveGenerator.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/extreme/ExtremeWQCurveGenerator.java	Tue Oct 08 14:50:58 2013 +0200
@@ -197,7 +197,7 @@
                     context.getMeta(),
                     I18N_CHART_SUBTITLE,
                     "",
-                    access.getRiver(),
+                    access.getRiverName(),
                     dateRange.getFrom(),
                     dateRange.getTo(),
                     refRange.getFrom(),
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixDeltaWtGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixDeltaWtGenerator.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixDeltaWtGenerator.java	Tue Oct 08 14:50:58 2013 +0200
@@ -130,7 +130,7 @@
                 context.getMeta(),
                 I18N_CHART_SUBTITLE,
                 "",
-                access.getRiver(),
+                access.getRiverName(),
                 dateRange.getFrom(),
                 dateRange.getTo(),
                 refRange.getFrom(),
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java	Tue Oct 08 14:50:58 2013 +0200
@@ -706,7 +706,7 @@
                     context.getMeta(),
                     I18N_CHART_SUBTITLE,
                     "",
-                    access.getRiver(),
+                    access.getRiverName(),
                     dateRange.getFrom(),
                     dateRange.getTo(),
                     refRange.getFrom(),
diff -r 0b32f8980fed -r a56fe3bc6700 artifacts/src/main/java/org/dive4elements/river/utils/ArtifactMapfileGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/ArtifactMapfileGenerator.java	Tue Oct 08 12:07:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/ArtifactMapfileGenerator.java	Tue Oct 08 14:50:58 2013 +0200
@@ -94,7 +94,7 @@
         layerinfo.setDirectory(identifier);
         layerinfo.setData(WSPLGEN_RESULT_SHAPE);
 
-        String river = access.getRiver();
+        String river = access.getRiverName();
 
         double from = access.hasFrom() ? access.getFrom() : 0d;
         double to   = access.hasTo()   ? access.getTo()   : 0d;


More information about the Dive4elements-commits mailing list