# HG changeset patch # User Björn Ricks # Date 1352293563 -3600 # Node ID 26774405c88403ead0941430ea48b2af09496f2b # Parent 093f9333f66b24886f9401ce42dd9ff9db76afc3 Introduce a new FixingsFacet to add save access to the current Km Values which are accessed by a String like a map must be checked for null. The new FixingsFacet adds a getCurrentKm method that abstracts the direct access to the CallContext and always returns a valid double value. diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -8,8 +8,8 @@ import de.intevation.flys.artifacts.access.ExtremeAccess; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.fixings.FixingsFacet; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; @@ -22,7 +22,7 @@ * Facet to show the W|Q values. */ public class ExtremeCurveFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -77,8 +77,7 @@ false); ExtremeResult result = (ExtremeResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); KMIndex curves = result.getCurves(); diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -6,7 +6,6 @@ import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; @@ -21,7 +20,7 @@ * @author Raimund Renkert */ public class FixAnalysisEventsFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -66,8 +65,7 @@ false); FixAnalysisResult result = (FixAnalysisResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); KMIndex kmPeriods = result.getAnalysisPeriods(); KMIndex.Entry kmPeriodsEntry = diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -8,7 +8,6 @@ import de.intevation.flys.artifacts.access.FixAnalysisAccess; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.DateRange; import de.intevation.flys.artifacts.model.FacetTypes; @@ -24,7 +23,7 @@ * @author Raimund Renkert */ public class FixAnalysisPeriodsFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -70,8 +69,7 @@ false); FixAnalysisResult result = (FixAnalysisResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); KMIndex kmPeriods = result.getAnalysisPeriods(); KMIndex.Entry kmPeriodsEntry = diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -8,7 +8,6 @@ import de.intevation.flys.artifacts.access.FixAnalysisAccess; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.QWDDateRange; @@ -26,7 +25,7 @@ * @author Raimund Renkert */ public class FixAvSectorFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -71,8 +70,7 @@ FixAnalysisResult result = (FixAnalysisResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); KMIndex kmPeriods = result.getAnalysisPeriods(); KMIndex.Entry kmPeriodsEntry = kmPeriods.binarySearch(currentKm); diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -11,7 +11,6 @@ import de.intevation.flys.artifacts.math.fitting.FunctionFactory; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.Parameters; @@ -26,7 +25,7 @@ * @author Raimund Renkert */ public class FixDerivateFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -76,8 +75,7 @@ false); FixAnalysisResult result = (FixAnalysisResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); String function = access.getFunction(); Function ff = FunctionFactory.getInstance().getFunction(function); diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDeviationFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -7,7 +7,6 @@ import de.intevation.flys.artifacts.access.FixAnalysisAccess; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.Parameters; @@ -22,7 +21,7 @@ * @author Raimund Renkert */ public class FixDeviationFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -68,8 +67,7 @@ false); FixAnalysisResult result = (FixAnalysisResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); Parameters params = result.getParameters(); diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -6,7 +6,6 @@ import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; import de.intevation.flys.utils.KMIndex; @@ -17,7 +16,7 @@ * @author Raimund Renkert */ public class FixOutlierFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -62,8 +61,7 @@ false); FixResult result = (FixResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); KMIndex kmQWs = result.getOutliers(); KMIndex.Entry qwsEntry = kmQWs.binarySearch(currentKm); diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -6,7 +6,6 @@ import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; import de.intevation.flys.utils.KMIndex; @@ -18,7 +17,7 @@ * @author Raimund Renkert */ public class FixReferenceEventsFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -63,8 +62,7 @@ false); FixResult result = (FixResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); KMIndex kmQWs = result.getReferenced(); KMIndex.Entry kmQWsEntry = kmQWs.binarySearch(currentKm); diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java Wed Nov 07 13:54:49 2012 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -11,7 +11,6 @@ import de.intevation.flys.artifacts.math.fitting.FunctionFactory; import de.intevation.flys.artifacts.model.CalculationResult; -import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.Parameters; @@ -25,7 +24,7 @@ * @author Raimund Renkert */ public class FixWQCurveFacet -extends DataFacet +extends FixingsFacet implements FacetTypes { /** House logger. */ @@ -70,8 +69,7 @@ false); FixResult result = (FixResult) res.getData(); - double currentKm = - ((Double)context.getContextValue("currentKm")).doubleValue(); + double currentKm = getCurrentKm(context); logger.debug("getData: km = " + currentKm); diff -r 093f9333f66b -r 26774405c884 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixingsFacet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixingsFacet.java Wed Nov 07 14:06:03 2012 +0100 @@ -0,0 +1,52 @@ +package de.intevation.flys.artifacts.model.fixings; + +import de.intevation.artifacts.CallContext; +import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; + +/** + * Facet to access the current Km from the context safely + * + * @author Björn Ricks + */ +public class FixingsFacet extends DataFacet { + + public static final Double INVALID_KM = Double.valueOf(-1d); + public static final String CURRENT_KM = "currentKm"; + + public FixingsFacet() { + } + + public FixingsFacet(String name, String description) { + super(0, name, description, ComputeType.ADVANCE, null, null); + } + + public FixingsFacet( + int index, + String name, + String description, + ComputeType type, + String hash, + String stateId + ) { + super(index, name, description, type, hash, stateId); + } + + /** + * Returns the current km from the context. + * If the context is null or doesn't contain a currentKm then a double value of -1 will + * be returned. + * @param context The CallContext instance + * @return the current km as double + */ + protected double getCurrentKm(CallContext context) { + if (context == null) { + return INVALID_KM; + } + Double dkm = (Double)context.getContextValue(CURRENT_KM); + if (dkm == null) { + return INVALID_KM; + } + return dkm.doubleValue(); + } +}