[Dive4elements-commits] [PATCH] RangeState and descendants: Use RangeAccess, resolve direct ld_* usage
Wald Commits
scm-commit at wald.intevation.org
Thu Jan 24 16:03:49 CET 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1359040186 -3600
# Node ID 1358d0c8481c9174c1043c728daafc5aba0bd8e7
# Parent dc0d37715e1654a47e47fbac05d230cc91585715
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
diff -r dc0d37715e16 -r 1358d0c8481c flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java Thu Jan 24 15:04:01 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java Thu Jan 24 16:09:46 2013 +0100
@@ -24,21 +24,12 @@
* @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
*/
public class ComputationRangeState
-extends RangeState
-implements FacetTypes
+extends RangeState
+implements FacetTypes
{
private static Logger logger =
Logger.getLogger(ComputationRangeState.class);
- /** The name of the 'from' field. */
- public static final String FROM = "ld_from";
-
- /** The name of the 'to' field. */
- public static final String TO = "ld_to";
-
- /** The name of the 'step' field. */
- public static final String STEP = "ld_step";
-
/** The default step width. */
public static final int DEFAULT_STEP = 100;
@@ -150,23 +141,5 @@
protected double getDefaultStep() {
return DEFAULT_STEP;
}
-
-
- @Override
- protected String getLowerField() {
- return FROM;
- }
-
-
- @Override
- protected String getUpperField() {
- return TO;
- }
-
-
- @Override
- protected String getStepField() {
- return STEP;
- }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r dc0d37715e16 -r 1358d0c8481c flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.java Thu Jan 24 15:04:01 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.java Thu Jan 24 16:09:46 2013 +0100
@@ -6,6 +6,7 @@
import de.intevation.artifactdatabase.data.StateData;
+import de.intevation.flys.artifacts.access.RangeAccess;
import de.intevation.flys.artifacts.FLYSArtifact;
@@ -23,21 +24,13 @@
public boolean validate(Artifact artifact)
throws IllegalArgumentException
{
+ // TODO think about better hierarchy wrt RangeState#validate.
FLYSArtifact flys = (FLYSArtifact) artifact;
- StateData dFrom = getData(flys, getLowerField());
- StateData dTo = getData(flys, getUpperField());
-
- String fromStr = dFrom != null ? (String) dFrom.getValue() : null;
- String toStr = dTo != null ? (String) dTo.getValue() : null;
-
- if (fromStr == null || toStr == null) {
- throw new IllegalArgumentException("error_empty_state");
- }
-
try {
- double from = Double.parseDouble(fromStr);
- double to = Double.parseDouble(toStr);
+ RangeAccess rangeAccess = new RangeAccess(flys, null);
+ double from = rangeAccess.getFrom();
+ double to = rangeAccess.getTo();
double[] minmax = getMinMax(flys);
@@ -46,6 +39,9 @@
catch (NumberFormatException nfe) {
throw new IllegalArgumentException("error_invalid_double_value");
}
+ catch (NullPointerException npe) {
+ throw new IllegalArgumentException("error_empty_state");
+ }
}
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r dc0d37715e16 -r 1358d0c8481c flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java Thu Jan 24 15:04:01 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java Thu Jan 24 16:09:46 2013 +0100
@@ -6,10 +6,12 @@
import de.intevation.artifactdatabase.data.StateData;
+import de.intevation.flys.artifacts.access.RangeAccess;
import de.intevation.flys.artifacts.FLYSArtifact;
/**
+ * State in which km range is set.
* @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
*/
public abstract class RangeState extends DefaultState {
@@ -21,10 +23,6 @@
public RangeState() {
}
-
- protected abstract String getLowerField();
- protected abstract String getUpperField();
- protected abstract String getStepField();
protected abstract double[] getMinMax(Artifact artifact);
@@ -77,22 +75,11 @@
{
FLYSArtifact flys = (FLYSArtifact) artifact;
- StateData dFrom = getData(flys, getLowerField());
- StateData dTo = getData(flys, getUpperField());
- StateData dStep = getData(flys, getStepField());
-
- String fromStr = dFrom != null ? (String) dFrom.getValue() : null;
- String toStr = dTo != null ? (String) dTo.getValue() : null;
- String stepStr = dStep != null ? (String) dStep.getValue() : null;
-
- if (fromStr == null || toStr == null || stepStr == null) {
- throw new IllegalArgumentException("error_empty_state");
- }
-
try {
- double from = Double.parseDouble(fromStr);
- double to = Double.parseDouble(toStr);
- double step = Double.parseDouble(stepStr);
+ RangeAccess rangeAccess = new RangeAccess(flys, null);
+ double from = rangeAccess.getFrom();
+ double to = rangeAccess.getTo();
+ double step = rangeAccess.getStep();
double[] minmax = getMinMax(flys);
@@ -101,6 +88,9 @@
catch (NumberFormatException nfe) {
throw new IllegalArgumentException("error_invalid_double_value");
}
+ catch (NullPointerException npe) {
+ throw new IllegalArgumentException("error_empty_state");
+ }
}
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r dc0d37715e16 -r 1358d0c8481c flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelGroundDifferences.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelGroundDifferences.java Thu Jan 24 15:04:01 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelGroundDifferences.java Thu Jan 24 16:09:46 2013 +0100
@@ -4,11 +4,14 @@
import org.apache.log4j.Logger;
+import de.intevation.flys.artifacts.FLYSArtifact;
+
import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.CallContext;
import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifactdatabase.data.StateData;
import de.intevation.artifactdatabase.ProtocolUtils;
@@ -28,20 +31,16 @@
Logger.getLogger(WaterlevelGroundDifferences.class);
-
- @Override
protected String getLowerField() {
return LOWER_FIELD;
}
- @Override
protected String getUpperField() {
return UPPER_FIELD;
}
- @Override
protected String getStepField() {
return DIFF_FIELD;
}
@@ -122,5 +121,37 @@
return item;
}
+
+ @Override
+ public boolean validate(Artifact artifact)
+ throws IllegalArgumentException
+ {
+ FLYSArtifact flys = (FLYSArtifact) artifact;
+
+ StateData dFrom = getData(flys, getLowerField());
+ StateData dTo = getData(flys, getUpperField());
+ StateData dStep = getData(flys, getStepField());
+
+ String fromStr = dFrom != null ? (String) dFrom.getValue() : null;
+ String toStr = dTo != null ? (String) dTo.getValue() : null;
+ String stepStr = dStep != null ? (String) dStep.getValue() : null;
+
+ if (fromStr == null || toStr == null || stepStr == null) {
+ throw new IllegalArgumentException("error_empty_state");
+ }
+
+ try {
+ double from = Double.parseDouble(fromStr);
+ double to = Double.parseDouble(toStr);
+ double step = Double.parseDouble(stepStr);
+
+ double[] minmax = getMinMax(flys);
+
+ return validateBounds(minmax[0], minmax[1], from, to, step);
+ }
+ catch (NumberFormatException nfe) {
+ throw new IllegalArgumentException("error_invalid_double_value");
+ }
+ }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r dc0d37715e16 -r 1358d0c8481c flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/LocationSelect.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/LocationSelect.java Thu Jan 24 15:04:01 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/LocationSelect.java Thu Jan 24 16:09:46 2013 +0100
@@ -18,13 +18,6 @@
/** The logger used in this class. */
private static Logger logger = Logger.getLogger(LocationSelect.class);
- private static final String LOWER = "from";
-
- private static final String UPPER = "to";
-
- private static final String STEP = "step";
-
-
/**
* The default constructor that initializes an empty State object.
*/
@@ -42,21 +35,6 @@
return FLYSUtils.getRiverMinMax(flysArtifact);
}
- @Override
- protected String getLowerField() {
- return LOWER;
- }
-
- @Override
- protected String getUpperField() {
- return UPPER;
- }
-
- @Override
- protected String getStepField() {
- return STEP;
- }
-
/** Misuse to set location mode. */
@Override
@@ -66,7 +44,5 @@
((FLYSArtifact) artifact).addStringData("ld_mode", "distance");
return super.validate(artifact);
}
-
-
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
More information about the Dive4elements-commits
mailing list