sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1689867 - in /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis: internal/metadata/MetadataUtilities.java metadata/iso/acquisition/DefaultEnvironmentalRecord.java metadata/iso/content/DefaultImageDescription.java
Date Wed, 08 Jul 2015 13:01:27 GMT
Author: desruisseaux
Date: Wed Jul  8 13:01:27 2015
New Revision: 1689867

URL: http://svn.apache.org/r1689867
Log:
Apply to 'ensureInRange' the same fix than 'ensurePositive': accepts arguments identified
as GML "nil value".

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java?rev=1689867&r1=1689866&r2=1689867&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
[UTF-8] Wed Jul  8 13:01:27 2015
@@ -31,7 +31,7 @@ import org.apache.sis.internal.jaxb.Cont
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public final class MetadataUtilities extends Static {
@@ -101,7 +101,7 @@ public final class MetadataUtilities ext
     {
         if (newValue != null) {
             final double value = newValue.doubleValue();
-            if (!(strict ? value > 0 : value >= 0)) { // Use '!' for catching NaN.
+            if (!(strict ? value > 0 : value >= 0)) {   // Use '!' for catching NaN.
                 if (NilReason.forObject(newValue) == null) {
                     final String msg = logOrFormat(classe, property, strict
                             ? Errors.Keys.ValueNotGreaterThanZero_2
@@ -117,34 +117,36 @@ public final class MetadataUtilities ext
     }
 
     /**
-     * Convenience method invoked when an argument is outside the expected range of values.
This method logs
-     * a warning if we are in process of (un)marshalling a XML document, or throw an exception
otherwise.
+     * Ensures that the given argument is either null or between the given minimum and maximum
values.
+     * If the user argument is outside the expected range of values, then this method logs
a warning
+     * if we are in process of (un)marshalling a XML document or throw an exception otherwise.
      *
-     * <p><b>When to use:</b></p>
-     * <ul>
-     *   <li>This method is for setter methods that may be invoked by JAXB. Constructors
or methods ignored
-     *       by JAXB should use the simpler {@link org.apache.sis.util.ArgumentChecks} class
instead.</li>
-     *   <li>This method should be invoked only when ignoring the warning will not
cause information lost.
-     *       The stored metadata value may be invalid, but not lost.</li>
-     * </ul>
-     * <div class="note"><b>Note:</b> the later point is the reason why
problems during XML (un)marshalling
-     * are only warnings for this method, while they are errors by default for
-     * {@link org.apache.sis.xml.ValueConverter} (the later can not store the value in case
of error).</div>
-     *
-     * @param  classe   The caller class.
-     * @param  property The property name. Method name will be inferred by the usual Java
bean convention.
+     * @param  classe   The class which invoke this method.
+     * @param  property Name of the property to check.
      * @param  minimum  The minimal legal value.
      * @param  maximum  The maximal legal value.
-     * @param  value    The invalid argument value.
-     * @throws IllegalArgumentException if we are not (un)marshalling a XML document.
+     * @param  newValue The value given by the user.
+     * @return {@code true} if the value is valid.
+     * @throws IllegalArgumentException if the given value is out of range and the problem
has not been logged.
      */
-    public static void warnOutOfRangeArgument(final Class<?> classe, final String property,
-            final Number minimum, final Number maximum, final Number value) throws IllegalArgumentException
+    public static boolean ensureInRange(final Class<?> classe, final String property,
+            final Number minimum, final Number maximum, final Number newValue)
+            throws IllegalArgumentException
     {
-        final String msg = logOrFormat(classe, property, Errors.Keys.ValueOutOfRange_4, property,
minimum, maximum, value);
-        if (msg != null) {
-            throw new IllegalArgumentException(msg);
+        if (newValue != null) {
+            final double value = newValue.doubleValue();
+            if (!(value >= minimum.doubleValue() && value <= maximum.doubleValue()))
{  // Use '!' for catching NaN.
+                if (NilReason.forObject(newValue) == null) {
+                    final String msg = logOrFormat(classe, property,
+                            Errors.Keys.ValueOutOfRange_4, property, minimum, maximum, newValue);
+                    if (msg != null) {
+                        throw new IllegalArgumentException(msg);
+                    }
+                    return false;
+                }
+            }
         }
+        return true;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java?rev=1689867&r1=1689866&r2=1689867&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/acquisition/DefaultEnvironmentalRecord.java
[UTF-8] Wed Jul  8 13:01:27 2015
@@ -24,7 +24,7 @@ import org.opengis.util.InternationalStr
 import org.apache.sis.measure.ValueRange;
 import org.apache.sis.metadata.iso.ISOMetadata;
 
-import static org.apache.sis.internal.metadata.MetadataUtilities.warnOutOfRangeArgument;
+import static org.apache.sis.internal.metadata.MetadataUtilities.ensureInRange;
 
 
 /**
@@ -176,10 +176,9 @@ public class DefaultEnvironmentalRecord
      */
     public void setMaxRelativeHumidity(final Double newValue) {
         checkWritePermission();
-        if (newValue != null && !(newValue >= 0 && newValue <= 100))
{ // Use '!' for catching NaN.
-            warnOutOfRangeArgument(DefaultEnvironmentalRecord.class, "maxRelativeHumidity",
0, 100, newValue);
+        if (ensureInRange(DefaultEnvironmentalRecord.class, "maxRelativeHumidity", 0, 100,
newValue)) {
+            maxRelativeHumidity = newValue;
         }
-        maxRelativeHumidity = newValue;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java?rev=1689867&r1=1689866&r2=1689867&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
[UTF-8] Wed Jul  8 13:01:27 2015
@@ -25,7 +25,7 @@ import org.opengis.metadata.content.Imag
 import org.opengis.metadata.content.ImagingCondition;
 import org.apache.sis.measure.ValueRange;
 
-import static org.apache.sis.internal.metadata.MetadataUtilities.warnOutOfRangeArgument;
+import static org.apache.sis.internal.metadata.MetadataUtilities.ensureInRange;
 import static org.apache.sis.internal.metadata.MetadataUtilities.ensurePositive;
 
 
@@ -198,26 +198,6 @@ public class DefaultImageDescription ext
     }
 
     /**
-     * Ensures that the given argument is either null or between the given minimum and maximum
values.
-     *
-     * @param property Name of the property to check.
-     * @param min      The minimal legal value.
-     * @param max      The maximal legal value.
-     * @param newValue The value given by the user.
-     * @throws IllegalArgumentException if the given value is out of range and the problem
has not been logged.
-     */
-    private static void ensureInRange(final String property, final double min, final double
max, final Double newValue)
-            throws IllegalArgumentException
-    {
-        if (newValue != null) {
-            final double v = newValue;
-            if (!(v >= min && v <= max)) { // Use '!' for catching NaN.
-                warnOutOfRangeArgument(DefaultImageDescription.class, property, min, max,
v);
-            }
-        }
-    }
-
-    /**
      * Returns the illumination elevation measured in degrees clockwise from the target plane
at
      * intersection of the optical line of sight with the Earth's surface.
      * For images from a scanning device, refer to the centre pixel of the image.
@@ -243,8 +223,9 @@ public class DefaultImageDescription ext
      */
     public void setIlluminationElevationAngle(final Double newValue) {
         checkWritePermission();
-        ensureInRange("illuminationElevationAngle", -90, +90, newValue);
-        illuminationElevationAngle = newValue;
+        if (ensureInRange(DefaultImageDescription.class, "illuminationElevationAngle", -90,
+90, newValue)) {
+            illuminationElevationAngle = newValue;
+        }
     }
 
     /**
@@ -269,8 +250,9 @@ public class DefaultImageDescription ext
      */
     public void setIlluminationAzimuthAngle(final Double newValue) {
         checkWritePermission();
-        ensureInRange("illuminationAzimuthAngle", 0, 360, newValue);
-        illuminationAzimuthAngle = newValue;
+        if (ensureInRange(DefaultImageDescription.class, "illuminationAzimuthAngle", 0, 360,
newValue)) {
+            illuminationAzimuthAngle = newValue;
+        }
     }
 
     /**
@@ -335,8 +317,9 @@ public class DefaultImageDescription ext
      */
     public void setCloudCoverPercentage(final Double newValue) {
         checkWritePermission();
-        ensureInRange("cloudCoverPercentage", 0, 100, newValue);
-        cloudCoverPercentage = newValue;
+        if (ensureInRange(DefaultImageDescription.class, "cloudCoverPercentage", 0, 100,
newValue)) {
+            cloudCoverPercentage = newValue;
+        }
     }
 
     /**



Mime
View raw message