Mercurial > dive4elements > river
changeset 2552:c7dbe696286c
Refactored the wq data fields.
flys-artifacts/trunk@4065 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 16 Feb 2012 12:36:25 +0000 |
parents | a0d9a99a5d17 |
children | c7b0dfa6a52c |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java |
diffstat | 5 files changed, 91 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Feb 16 12:30:33 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Feb 16 12:36:25 2012 +0000 @@ -1,3 +1,16 @@ +2012-02-16 Raimund Renkert <raimund.renkert@intevation.de> + + Refactored the wq data fields. + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java, + src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java, + src/main/java/de/intevation/flys/artifacts/states/WQSelect.java: + Changed the wq data fields to boolean values. + + * src/main/java/de/intevation/flys/utils/FLYSUtils.java: + Changed the wq data fields to boolean values and added method that + returns the km input mode. + 2012-02-16 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/Calculation4.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Thu Feb 16 12:30:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Thu Feb 16 12:36:25 2012 +0000 @@ -1119,11 +1119,12 @@ StateData dMode = getData("wq_mode"); StateData dSelection = getData("wq_selection"); - String mode = dMode != null ? (String) dMode.getValue() : ""; - String sel = dSelection != null ? (String)dSelection.getValue() : null; + boolean isRange = dSelection != null + ? Boolean.valueOf((String)dSelection.getValue()) + : false; - if (mode.equals("Q")) { - if (sel != null && sel.equals("single")) { + if (isQ()) { + if (!isRange) { return getSingleWQValues(); } else { @@ -1139,12 +1140,24 @@ public boolean isQ() { StateData mode = getData("wq_mode"); - return mode != null && mode.getValue().equals("Q"); + String value = (mode != null) ? (String) mode.getValue() : null; + return value != null ? Boolean.valueOf(value) : false; + } + + public boolean isW() { + StateData mode = getData("wq_mode"); + String value = (mode != null) ? (String) mode.getValue() : null; + return value != null ? !Boolean.valueOf(value) : false; } public boolean isFreeW() { - StateData mode = getData("wq_mode"); - return mode != null && mode.getValue().equals("WFREE"); + if(!isW()) { + return false; + } + StateData mode = getData("wq_free"); + String value = (mode != null) ? (String) mode.getValue() : null; + + return value != null ? Boolean.valueOf(value) : false; } @@ -1157,6 +1170,9 @@ * false and the calculation is bound to a gauge. */ public boolean isFreeQ() { + if(!isQ()) { + return false; + } StateData mode = getData("wq_free"); String value = (mode != null) ? (String) mode.getValue() : null; @@ -1175,11 +1191,8 @@ */ public double[] getQs(double[] range) { StateData dMode = getData("wq_mode"); - StateData dValues = getData("wq_values"); - String mode = (dMode != null) ? (String) dMode.getValue() : ""; - - if (mode.equals("Q")) { + if (isQ()) { return getWQForDist(range); } @@ -1196,12 +1209,7 @@ * @return an array of W values. */ public double[] getWs(double[] range) { - StateData dMode = getData("wq_mode"); - StateData dValues = getData("wq_values"); - - String mode = (dMode != null) ? (String) dMode.getValue() : ""; - - if (mode.equals("W")) { + if (isW()) { return getWQForDist(range); } @@ -1216,12 +1224,9 @@ * @return the selected W values or null, if no W values are selected. */ public double[] getWs() { - StateData dMode = getData("wq_mode"); StateData dSingle = getData("wq_single"); - String mode = (dMode != null) ? (String) dMode.getValue() : ""; - - if (mode.equals("W") || mode.equals("WFREE")) { + if (isW()) { if (dSingle != null) { return getSingleWQValues(); } @@ -1230,7 +1235,7 @@ } } else { - logger.warn("You try to get Qs, but W has been inserted."); + logger.warn("You try to get Ws, but Q has been inserted."); return null; } }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java Thu Feb 16 12:30:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java Thu Feb 16 12:36:25 2012 +0000 @@ -282,11 +282,14 @@ StateData data = getData(flys, FIELD_WQ_MODE); String mode = data != null ? (String) data.getValue() : null; + boolean isQ = mode != null + ? Boolean.valueOf(mode) + : false; - if (mode != null && mode.equals("W")) { + if (!isQ) { return validateW(artifact); } - else if (mode != null && mode.equals("Q")) { + else if (isQ) { return validateQ(artifact); } else {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Thu Feb 16 12:30:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Thu Feb 16 12:36:25 2012 +0000 @@ -89,8 +89,8 @@ return super.createStaticData(flys, creator, cc, name, value, type); } - String mode = flys.getDataAsString(WQ_MODE); - String free = flys.getDataAsString(WQ_FREE); + boolean isQ = flys.getDataAsBoolean(WQ_MODE); + boolean isFree = flys.getDataAsBoolean(WQ_FREE); WINFOArtifact winfo = (WINFOArtifact) flys; @@ -103,7 +103,7 @@ String label; - if (mode == null || mode.equals("W") || Boolean.valueOf(free)) { + if (!isQ || isFree) { label = getLabel(winfo, cc, value); } else { @@ -454,9 +454,11 @@ WINFOArtifact flys = (WINFOArtifact) artifact; StateData data = getData(flys, WQ_SELECTION); - String selectionMode = data != null ? (String) data.getValue() : null; + boolean isRange = data != null + ? Boolean.valueOf((String) data.getValue()) + : false; - if (selectionMode == null || selectionMode.equals("single")) { + if (!isRange) { return validateSingle(artifact); } else {
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java Thu Feb 16 12:30:33 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java Thu Feb 16 12:36:25 2012 +0000 @@ -57,6 +57,12 @@ */ public static enum WQ_MODE { QFREE, QGAUGE, WFREE, WGAUGE, NONE }; + /** + * An enum that represents the 4 possible WQ input modes in FLYS. The 4 + * values are + * <i>ADAPTED</i> <i>SINGLE</i> <i>RANGE</i> and <i>NONE</i>. + */ + public static enum WQ_INPUT { ADAPTED, SINGLE, RANGE, NONE }; public static final Pattern NUMBERS_PATTERN = Pattern.compile("\\D*(\\d++.\\d*)\\D*"); @@ -169,16 +175,20 @@ return WQ_MODE.NONE; } - String mode = flys.getDataAsString("wq_mode"); - Boolean free = flys.getDataAsBoolean("wq_free"); - - free = free != null ? free : false; + String values = flys.getDataAsString("wq_values"); + Boolean isQ = flys.getDataAsBoolean("wq_mode"); - if (mode != null && mode.equals("Q")) { - return free ? WQ_MODE.QFREE : WQ_MODE.QGAUGE; + if (values != null) { + return isQ ? WQ_MODE.QGAUGE : WQ_MODE.WGAUGE; } - else if (mode != null && mode.equals("W")) { - return free ? WQ_MODE.WFREE : WQ_MODE.WGAUGE; + + Boolean isFree = flys.getDataAsBoolean("wq_free"); + + if (isQ) { + return isFree ? WQ_MODE.QFREE : WQ_MODE.QGAUGE; + } + else if (!isQ) { + return isFree ? WQ_MODE.WFREE : WQ_MODE.WGAUGE; } else { return WQ_MODE.NONE; @@ -186,6 +196,26 @@ } + public static WQ_INPUT getWQInputMode(FLYSArtifact flys) { + if (flys == null) { + return WQ_INPUT.NONE; + } + + Boolean selection = flys.getDataAsBoolean("wq_selection"); + String adapted = flys.getDataAsString("wq_values"); + + if(adapted != null && adapted.length() > 0) { + return WQ_INPUT.ADAPTED; + } + + if (selection != null && selection) { + return WQ_INPUT.RANGE; + } + else { + return WQ_INPUT.SINGLE; + } + } + public static KM_MODE getKmRangeMode(FLYSArtifact flys) { String mode = flys.getDataAsString("ld_mode"); @@ -337,11 +367,9 @@ * @return the Ws. */ public static double[] getWs(FLYSArtifact flys) { - double[] kmRange = getKmRange(flys); - // XXX this is not nice! if (flys instanceof WINFOArtifact) { - return ((WINFOArtifact) flys).getWs(kmRange); + return ((WINFOArtifact) flys).getWs(); } logger.warn("This method currently supports WINFOArtifact only!");