changeset 6868:08e3c22500f3

Fix Analysis: Code simplification in facets.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 19 Aug 2013 16:29:28 +0200
parents 0f3dad5d74a2
children 68fd84c474b7
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/Fitting.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisEventsFacet.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixReferenceEventsFacet.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java
diffstat 5 files changed, 135 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/Fitting.java	Mon Aug 19 16:02:48 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/Fitting.java	Mon Aug 19 16:29:28 2013 +0200
@@ -121,8 +121,9 @@
         double maxQ = -Double.MAX_VALUE;
         if (referenced != null) {
             for (QWI qw: referenced) {
-                if (qw.getQ() > maxQ) {
-                    maxQ = qw.getQ();
+                double q = qw.getQ();
+                if (q > maxQ) {
+                    maxQ = q;
                 }
             }
         }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisEventsFacet.java	Mon Aug 19 16:02:48 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisEventsFacet.java	Mon Aug 19 16:29:28 2013 +0200
@@ -64,48 +64,47 @@
     public Object getData(Artifact artifact, CallContext context) {
         logger.debug("FixAnalysisEventsFacet.getData");
 
-        if (artifact instanceof D4EArtifact) {
-            D4EArtifact flys = (D4EArtifact)artifact;
-
-            CalculationResult res =
-                (CalculationResult) flys.compute(context,
-                                                 ComputeType.ADVANCE,
-                                                 false);
-
-            FixAnalysisResult result = (FixAnalysisResult) res.getData();
-            double currentKm = getCurrentKm(context);
-
-            KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
-            KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
-                kmPeriods.binarySearch(currentKm);
-
-            if(kmPeriodsEntry == null) {
-                logger.debug("getData: kmPeriodsEntry == null");
-                return null;
-            }
-
-            AnalysisPeriod[] periods = kmPeriodsEntry.getValue();
-            if (periods == null) {
-                logger.debug("getData: periods == null");
-                return null;
-            }
-            int ndx = index >> 8;
-            QWD[] qwdData = periods[ndx].getQWDs();
-            if (qwdData == null) {
-                return null;
-            }
-            int ndy = index & 255;
-            for (int i = 0; i < qwdData.length; i++) {
-                if (qwdData[i].getIndex() == ndy) {
-                    return qwdData[i];
-                }
-            }
-            return null;
-        }
-        else {
+        if (!(artifact instanceof D4EArtifact)) {
             logger.debug("Not an instance of FixationArtifact.");
             return null;
         }
+        D4EArtifact flys = (D4EArtifact)artifact;
+
+        CalculationResult res =
+            (CalculationResult) flys.compute(context,
+                                             ComputeType.ADVANCE,
+                                             false);
+
+        FixAnalysisResult result = (FixAnalysisResult) res.getData();
+        double currentKm = getCurrentKm(context);
+
+        KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
+        KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
+            kmPeriods.binarySearch(currentKm);
+
+        if (kmPeriodsEntry == null) {
+            logger.debug("getData: kmPeriodsEntry == null");
+            return null;
+        }
+
+        AnalysisPeriod[] periods = kmPeriodsEntry.getValue();
+        if (periods == null) {
+            logger.debug("getData: periods == null");
+            return null;
+        }
+        int ndx = index >> 8;
+        QWD[] qwdData = periods[ndx].getQWDs();
+        if (qwdData == null) {
+            return null;
+        }
+        int ndy = index & 255;
+
+        for (QWD qwd: qwdData) {
+            if (qwd.getIndex() == ndy) {
+                return qwd;
+            }
+        }
+        return null;
     }
 
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixReferenceEventsFacet.java	Mon Aug 19 16:02:48 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixReferenceEventsFacet.java	Mon Aug 19 16:29:28 2013 +0200
@@ -61,38 +61,34 @@
     public Object getData(Artifact artifact, CallContext context) {
         logger.debug("FixReferenceEventsFacet.getData");
 
-        if (artifact instanceof D4EArtifact) {
-            D4EArtifact flys = (D4EArtifact)artifact;
-
-            CalculationResult res =
-                (CalculationResult) flys.compute(context,
-                                                 ComputeType.ADVANCE,
-                                                 false);
-
-            FixResult result = (FixResult) res.getData();
-            double currentKm = getCurrentKm(context);
-
-            logger.debug("current km in FRE: " + currentKm);
-
-            KMIndex<QWD []> kmQWs = result.getReferenced();
-            KMIndex.Entry<QWD []> kmQWsEntry = kmQWs.binarySearch(currentKm);
-            QWD[] qwds = null;
-            if (kmQWsEntry != null) {
-                int ndx = index & 255;
-                qwds = kmQWsEntry.getValue();
-                for (int i = 0; i < qwds.length; i++) {
-                    if (qwds[i].getIndex() == ndx) {
-                        return qwds[i];
-                    }
-                }
-                return null;
-            }
-            return null;
-        }
-        else {
+        if (!(artifact instanceof D4EArtifact)) {
             logger.debug("Not an instance of FixationArtifact.");
             return null;
         }
+
+        D4EArtifact flys = (D4EArtifact)artifact;
+
+        CalculationResult res =
+            (CalculationResult) flys.compute(context,
+                                             ComputeType.ADVANCE,
+                                             false);
+
+        FixResult result = (FixResult) res.getData();
+        double currentKm = getCurrentKm(context);
+
+        logger.debug("current km in FRE: " + currentKm);
+
+        KMIndex<QWD []> kmQWs = result.getReferenced();
+        KMIndex.Entry<QWD []> kmQWsEntry = kmQWs.binarySearch(currentKm);
+        if (kmQWsEntry != null) {
+            int ndx = index & 255;
+            for (QWD qwd: kmQWsEntry.getValue()) {
+                if (qwd.getIndex() == ndx) {
+                    return qwd;
+                }
+            }
+        }
+        return null;
     }
 
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java	Mon Aug 19 16:02:48 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java	Mon Aug 19 16:29:28 2013 +0200
@@ -66,57 +66,57 @@
      */
     @Override
     public Object getData(Artifact artifact, CallContext context) {
-        logger.debug("getData");
-        if (artifact instanceof D4EArtifact) {
-            D4EArtifact flys = (D4EArtifact)artifact;
-            FixAnalysisAccess access = new FixAnalysisAccess(flys);
-
-            CalculationResult res =
-                (CalculationResult) flys.compute(context,
-                                                 ComputeType.ADVANCE,
-                                                 false);
-
-            FixResult result = (FixResult) res.getData();
-            double currentKm = getCurrentKm(context);
-
-            logger.debug("getData: km = " + currentKm);
-
-            String function = access.getFunction();
-            Function ff = FunctionFactory.getInstance().getFunction(function);
-
-            if (ff == null) {
-                logger.warn("getData: ff == null");
-                return null;
-            }
 
-            Parameters params = result.getParameters();
-            String[] paramNames = ff.getParameterNames();
-
-            double [] coeffs = params.interpolate("km", currentKm, paramNames);
-
-            if (coeffs == null) {
-                logger.warn("getData: coeffs == null");
-                return null;
-            }
-
-            org.dive4elements.river.artifacts.math.Function mf =
-                ff.instantiate(coeffs);
-
-            double maxQ = FixFacetUtils.getMaxQ(params, currentKm);
-            logger.debug("getData: maxQ = " + maxQ);
-
-            FixFunction fix = new FixFunction(
-                ff.getName(),
-                ff.getDescription(),
-                mf,
-                maxQ);
-
-            return fix;
-        }
-        else {
+        logger.debug("getData");
+        if (!(artifact instanceof D4EArtifact)) {
             logger.debug("Not an instance of D4EArtifact / FixationArtifact.");
             return null;
         }
+
+        D4EArtifact flys = (D4EArtifact)artifact;
+        FixAnalysisAccess access = new FixAnalysisAccess(flys);
+
+        CalculationResult res =
+            (CalculationResult) flys.compute(context,
+                                             ComputeType.ADVANCE,
+                                             false);
+
+        FixResult result = (FixResult) res.getData();
+        double currentKm = getCurrentKm(context);
+
+        logger.debug("getData: km = " + currentKm);
+
+        String function = access.getFunction();
+        Function ff = FunctionFactory.getInstance().getFunction(function);
+
+        if (ff == null) {
+            logger.warn("getData: ff == null");
+            return null;
+        }
+
+        Parameters params = result.getParameters();
+        String[] paramNames = ff.getParameterNames();
+
+        double [] coeffs = params.interpolate("km", currentKm, paramNames);
+
+        if (coeffs == null) {
+            logger.warn("getData: coeffs == null");
+            return null;
+        }
+
+        org.dive4elements.river.artifacts.math.Function mf =
+            ff.instantiate(coeffs);
+
+        double maxQ = FixFacetUtils.getMaxQ(params, currentKm);
+        logger.debug("getData: maxQ = " + maxQ);
+
+        FixFunction fix = new FixFunction(
+            ff.getName(),
+            ff.getDescription(),
+            mf,
+            maxQ);
+
+        return fix;
     }
 
     /**
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java	Mon Aug 19 16:02:48 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java	Mon Aug 19 16:29:28 2013 +0200
@@ -309,30 +309,30 @@
         logger.debug("doReferenceEventsOut");
 
         QWI qwd = (QWI)aaf.getData(context);
-        if(qwd != null) {
-            XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
-            List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
-
-            DateFormat dateFormat = DateFormat.getDateInstance(
-                    DateFormat.SHORT);
-
-            series.add(qwd.getQ(), qwd.getW());
+        if (qwd == null) {
+            logger.debug("doReferenceEventsOut: qwds == null");
+            return;
+        }
 
-            XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
-                    dateFormat.format(qwd.getDate()),
-                    qwd.getQ(),
-                    qwd.getW());
-            textAnnos.add(anno);
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+        List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>();
 
-            addAxisSeries(series, YAXIS.W.idx, visible);
-            if(visible && ThemeUtil.parseShowPointLabel(doc)) {
-                RiverAnnotation flysAnno = new RiverAnnotation(null, null, null, doc);
-                flysAnno.setTextAnnotations(textAnnos);
-                addAnnotations(flysAnno);
-            }
-        }
-        else {
-            logger.debug("doReferenceEventsOut: qwds == null");
+        DateFormat dateFormat = DateFormat.getDateInstance(
+                DateFormat.SHORT);
+
+        series.add(qwd.getQ(), qwd.getW());
+
+        XYTextAnnotation anno = new CollisionFreeXYTextAnnotation(
+                dateFormat.format(qwd.getDate()),
+                qwd.getQ(),
+                qwd.getW());
+        textAnnos.add(anno);
+
+        addAxisSeries(series, YAXIS.W.idx, visible);
+        if(visible && ThemeUtil.parseShowPointLabel(doc)) {
+            RiverAnnotation flysAnno = new RiverAnnotation(null, null, null, doc);
+            flysAnno.setTextAnnotations(textAnnos);
+            addAnnotations(flysAnno);
         }
     }
 

http://dive4elements.wald.intevation.org