sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Better error message in the common case where the range of valid values is (0…n].
Date Mon, 03 Sep 2018 16:56:09 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit ed8ae65ae1b76f42edf700a0651c900277697df1
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Sep 3 18:41:56 2018 +0200

    Better error message in the common case where the range of valid values is (0…n].
---
 .../internal/jaxb/metadata/RS_ReferenceSystem.java |  5 ++-
 .../java/org/apache/sis/parameter/Verifier.java    | 49 ++++++++++++----------
 .../apache/sis/util/resources/Errors.properties    |  2 +-
 3 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/RS_ReferenceSystem.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/RS_ReferenceSystem.java
index 70934c5..94933ce 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/RS_ReferenceSystem.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/RS_ReferenceSystem.java
@@ -28,7 +28,10 @@ import org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata;
  *
  * @author  Guilhem Legal (Geomatys)
  * @version 1.0
- * @since   0.3
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/SIS-431">SIS-431</a>
+ *
+ * @since 0.3
  * @module
  */
 public class RS_ReferenceSystem extends PropertyType<RS_ReferenceSystem, ReferenceSystem>
{
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java b/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
index 7ae4c17..2bf01c6 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/parameter/Verifier.java
@@ -240,29 +240,34 @@ final class Verifier {
     {
         final Verifier verifier = ensureValidValue(valueClass, validValues, null, null, convertedValue);
         if (verifier == null && valueDomain != null) {
-            if (!valueClass.isArray()) {
-                /*
-                 * Following assertion should never fail with DefaultParameterDescriptor
instances.
-                 * It could fail if the user overrides DefaultParameterDescriptor.getValueDomain()
-                 * in a way that break the method contract.
-                 */
-                assert valueDomain.getElementType() == valueClass : valueDomain;
-                if (!((Range) valueDomain).contains((Comparable<?>) convertedValue))
{
-                    return new Verifier(false, Errors.Keys.ValueOutOfRange_4, true, null,
-                            valueDomain.getMinValue(), valueDomain.getMaxValue(), convertedValue);
-                }
-            } else {
-                /*
-                 * Following assertion should never fail under the same condition than above.
-                 */
-                assert valueDomain.getElementType() == Numbers.primitiveToWrapper(valueClass.getComponentType())
: valueDomain;
-                final int length = Array.getLength(convertedValue);
-                for (int i=0; i<length; i++) {
-                    final Object e = Array.get(convertedValue, i);
-                    if (!((Range) valueDomain).contains((Comparable<?>) e)) {
-                        return new Verifier(false, Errors.Keys.ValueOutOfRange_4, true, i,
-                                valueDomain.getMinValue(), valueDomain.getMaxValue(), e);
+            final boolean isArray = valueClass.isArray();
+            /*
+             * Following assertion should never fail with DefaultParameterDescriptor instances.
+             * It could fail if the user overrides DefaultParameterDescriptor.getValueDomain()
+             * in a way that break the method contract.
+             */
+            assert valueDomain.getElementType() == (isArray ? Numbers.primitiveToWrapper(valueClass.getComponentType())
: valueClass) : valueDomain;
+            final int length = isArray ? Array.getLength(convertedValue) : 1;
+            for (int i=0; i<length; i++) {
+                final Object value = isArray ? Array.get(convertedValue, i) : convertedValue;
+                if (!((Range) valueDomain).contains((Comparable<?>) value)) {
+                    final short errorKey;
+                    final Object[] arguments;
+                    final Object minValue = valueDomain.getMinValue();
+                    if ((minValue instanceof Number) && ((Number) minValue).doubleValue()
== 0 && !valueDomain.isMinIncluded()
+                        && (value instanceof Number) && ((Number) value).doubleValue()
< 0)
+                    {
+                        errorKey     = Errors.Keys.ValueNotGreaterThanZero_2;
+                        arguments    = new Object[2];
+                    } else {
+                        errorKey     = Errors.Keys.ValueOutOfRange_4;
+                        arguments    = new Object[4];
+                        arguments[1] = minValue;
+                        arguments[2] = valueDomain.getMaxValue();
                     }
+                    if (isArray) arguments[0] = i;
+                    arguments[arguments.length - 1] = value;
+                    return new Verifier(false, errorKey, true, arguments);
                 }
             }
         }
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
index 990dcce..d238722 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
@@ -84,7 +84,7 @@ IllegalCharacterForFormat_3       = The \u201c{2}\u201d character in \u201c{1}\u
 IllegalClass_2                    = Class \u2018{1}\u2019 is illegal. It must be \u2018{0}\u2019
or a derived class.
 IllegalCoordinateSystem_1         = Coordinate system can not be \u201c{0}\u201d.
 IllegalCRSType_1                  = Coordinate reference system can not be of type \u2018{0}\u2019.
-IllegalFormatPatternForClass_2    = The \u201c{1}\u201d pattern can not be applied to formating
of objects of type \u2018{0}\u2019.
+IllegalFormatPatternForClass_2    = The \u201c{1}\u201d pattern can not be applied to formatting
of objects of type \u2018{0}\u2019.
 IllegalIdentifierForCodespace_2   = \u201c{1}\u201d is not a valid identifier for the \u201c{0}\u201d
code space.
 IllegalLanguageCode_1             = The \u201c{0}\u201d language is not recognized.
 IllegalMemberType_2               = Member \u201c{0}\u201d can not be associated to type
\u201c{1}\u201d.


Mime
View raw message