# HG changeset patch # User Sascha L. Teichmann # Date 1376922568 -7200 # Node ID 08e3c22500f32c6a0785fdd1ee1c47b7a71054e3 # Parent 0f3dad5d74a2a5013b11bcc43afcdbb883e4998a Fix Analysis: Code simplification in facets. diff -r 0f3dad5d74a2 -r 08e3c22500f3 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/Fitting.java --- 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; } } } diff -r 0f3dad5d74a2 -r 08e3c22500f3 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisEventsFacet.java --- 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 kmPeriods = result.getAnalysisPeriods(); - KMIndex.Entry 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 kmPeriods = result.getAnalysisPeriods(); + KMIndex.Entry 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; } diff -r 0f3dad5d74a2 -r 08e3c22500f3 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixReferenceEventsFacet.java --- 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 kmQWs = result.getReferenced(); - KMIndex.Entry 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 kmQWs = result.getReferenced(); + KMIndex.Entry kmQWsEntry = kmQWs.binarySearch(currentKm); + if (kmQWsEntry != null) { + int ndx = index & 255; + for (QWD qwd: kmQWsEntry.getValue()) { + if (qwd.getIndex() == ndx) { + return qwd; + } + } + } + return null; } diff -r 0f3dad5d74a2 -r 08e3c22500f3 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java --- 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; } /** diff -r 0f3dad5d74a2 -r 08e3c22500f3 artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java --- 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 textAnnos = new ArrayList(); - - 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 textAnnos = new ArrayList(); - 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); } }