diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java @ 1630:cafd8af6734a

Improved bounds validation for distance only states. flys-artifacts/trunk@2806 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 22 Sep 2011 07:58:24 +0000
parents 9a77a9adbb36
children 022f62c75878
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java	Wed Sep 21 14:28:39 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java	Thu Sep 22 07:58:24 2011 +0000
@@ -28,6 +28,26 @@
     protected abstract double[] getMinMax(Artifact artifact);
 
 
+    protected boolean validateBounds(
+        double fromValid, double toValid,
+        double from,      double to)
+    throws IllegalArgumentException
+    {
+        if (from < fromValid) {
+            logger.error(
+                "Invalid 'from'. " + from + " is smaller than " + fromValid);
+            throw new IllegalArgumentException("error_feed_from_out_of_range");
+        }
+        else if (to > toValid) {
+            logger.error(
+                "Invalid 'to'. " + to + " is bigger than " + toValid);
+            throw new IllegalArgumentException("error_feed_to_out_of_range");
+        }
+
+        return true;
+    }
+
+
     /**
      * Validates a given range with a given valid range.
      *
@@ -46,18 +66,8 @@
     {
         logger.debug("RangeState.validateRange");
 
-        if (from < fromValid) {
-            logger.error(
-                "Invalid 'from'. " + from + " is smaller than " + fromValid);
-            throw new IllegalArgumentException("error_feed_from_out_of_range");
-        }
-        else if (to > toValid) {
-            logger.error(
-                "Invalid 'to'. " + to + " is bigger than " + toValid);
-            throw new IllegalArgumentException("error_feed_to_out_of_range");
-        }
-
-        return true;
+        // XXX The step width is not validated at the moment!
+        return validateBounds(fromValid, toValid, from, to);
     }
 
 

http://dive4elements.wald.intevation.org