You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2022/11/15 18:04:48 UTC

[sis] branch geoapi-4.0 updated (7b995facc0 -> a31026987c)

This is an automated email from the ASF dual-hosted git repository.

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


    from 7b995facc0 Save the "TypeName to Java class" association in `DefaultTypeName`.
     new 76741edb14 Add a `Names.createMemberName(CharSequence, String, CharSequence, TypeName)` convenience method.
     new 74d119635e Constructor argument should be `CharSequence` instead of `InternationalString` for consistency with similar constructors in the rest of metadata packages.
     new a31026987c Add a few tests for metadata quality package.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../metadata/iso/quality/DefaultDescription.java   | 10 ++++++
 .../iso/quality/DefaultDescriptiveResult.java      |  7 ++--
 .../iso/quality/DefaultIndirectEvaluation.java     |  5 +--
 .../iso/quality/DefaultQuantitativeResult.java     | 14 ++++++++
 .../apache/sis/util/iso/DefaultNameFactory.java    |  3 +-
 .../main/java/org/apache/sis/util/iso/Names.java   | 40 +++++++++++++++++-----
 .../iso/quality/DefaultDomainConsistencyTest.java} | 23 +++++++------
 .../DefaultQuantitativeResultTest.java}            | 29 +++++++++-------
 .../apache/sis/test/suite/MetadataTestSuite.java   |  2 ++
 9 files changed, 95 insertions(+), 38 deletions(-)
 copy core/{sis-feature/src/test/java/org/apache/sis/filter/XPathTest.java => sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultDomainConsistencyTest.java} (61%)
 copy core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/{identification/DefaultKeywordsTest.java => quality/DefaultQuantitativeResultTest.java} (51%)


[sis] 01/03: Add a `Names.createMemberName(CharSequence, String, CharSequence, TypeName)` convenience method.

Posted by de...@apache.org.
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 76741edb14b139210ec3bc4c0561cfbbb88ab845
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Nov 15 16:37:47 2022 +0100

    Add a `Names.createMemberName(CharSequence, String, CharSequence, TypeName)` convenience method.
---
 .../apache/sis/util/iso/DefaultNameFactory.java    |  3 +-
 .../main/java/org/apache/sis/util/iso/Names.java   | 40 +++++++++++++++++-----
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
index c093d2d7b4..32854fd0cb 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultNameFactory.java
@@ -246,9 +246,10 @@ public class DefaultNameFactory extends AbstractFactory implements NameFactory {
      * @param  scope  the {@linkplain AbstractName#scope() scope} of the member name to create,
      *                or {@code null} for a global namespace.
      * @param  name   the member name as a string or an international string.
-     * @param  attributeType  the type of the data associated with the record member.
+     * @param  attributeType  the type of the data associated with the member.
      * @return the member name for the given character sequence.
      *
+     * @see Names#createMemberName(CharSequence, String, CharSequence, TypeName)
      * @see Names#createMemberName(CharSequence, String, CharSequence, Class)
      */
     @Override
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/Names.java b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/Names.java
index 8e80469e5a..08ebe2d76b 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/Names.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/Names.java
@@ -27,8 +27,8 @@ import org.opengis.util.NameSpace;
 import org.opengis.util.NameFactory;
 import org.opengis.util.InternationalString;
 import org.apache.sis.util.Static;
-import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.util.UnknownNameException;
+import org.apache.sis.internal.system.DefaultFactories;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
@@ -226,7 +226,7 @@ public final class Names extends Static {
     }
 
     /**
-     * Creates a type name which is local in the given namespace.
+     * Creates a type name from the given character sequence and automatically inferred Java type.
      * The character sequences can be either {@link String} or {@link InternationalString} instances.
      * Those character sequences are taken verbatim; they are <em>not</em> parsed into their components.
      *
@@ -252,13 +252,14 @@ public final class Names extends Static {
     }
 
     /**
-     * Suggests a type name for the given class. Apache SIS provides a mapping between {@code Class}
-     * and {@code TypeName} objects as documented in the {@link DefaultTypeName} javadoc.
-     * This is the converse of {@link #toClass(TypeName)} method.
+     * Creates a type name for the given class using naming convention documented in {@link DefaultTypeName}.
+     * This method is a shortcut for {@link DefaultNameFactory#toTypeName(Class)}
+     * and is the converse of {@link #toClass(TypeName)}.
      *
-     * @param  valueClass the type of values, used for inferring a {@link TypeName} instance.
+     * @param  valueClass  the type of values for which to infer a {@link TypeName} instance.
      * @return a type name for values of the given type.
      *
+     * @see #createMemberName(CharSequence, String, CharSequence, Class)
      * @see DefaultNameFactory#toTypeName(Class)
      *
      * @since 1.3
@@ -283,8 +284,6 @@ public final class Names extends Static {
      * @param  localPart  the name which is locale in the given namespace.
      * @param  valueClass the type of values, used for inferring a {@link TypeName} instance.
      * @return a member name in the given namespace for values of the given type.
-     *
-     * @see DefaultNameFactory#createMemberName(NameSpace, CharSequence, TypeName)
      */
     public static MemberName createMemberName(final CharSequence namespace, final String separator,
             final CharSequence localPart, final Class<?> valueClass)
@@ -296,6 +295,29 @@ public final class Names extends Static {
                factory.toTypeName(valueClass));     // SIS-specific method.
     }
 
+    /**
+     * Creates a member name for attribute values of the given type.
+     * This is a shortcut for {@link DefaultNameFactory#createMemberName(NameSpace, CharSequence, TypeName)}.
+     * See {@linkplain #createMemberName(CharSequence, String, CharSequence, Class) performance note}.
+     *
+     * @param  namespace  the namespace, or {@code null} for the global namespace.
+     * @param  separator  the separator between the namespace and the local part, or {@code null}
+     *                    for the {@linkplain DefaultNameSpace#DEFAULT_SEPARATOR default separator}.
+     * @param  localPart  the name which is locale in the given namespace.
+     * @param  attributeType  the type of the data associated with the member.
+     * @return a member name in the given namespace for values of the given type.
+     *
+     * @since 1.3
+     */
+    public static MemberName createMemberName(final CharSequence namespace, final String separator,
+            final CharSequence localPart, final TypeName attributeType)
+    {
+        ensureNonNull("localPart", localPart);
+        ensureNonNull("attributeType", attributeType);
+        final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
+        return factory.createMemberName(createNameSpace(factory, namespace, separator), localPart, attributeType);
+    }
+
     /**
      * Creates a member name for the given sequence number. The member type will be {@code "OGC:Integer"}.
      * This method can be used for {@linkplain org.apache.sis.metadata.iso.content.DefaultRangeDimension#setSequenceIdentifier
@@ -324,7 +346,7 @@ public final class Names extends Static {
             name = createMemberName(namespace, separator, Integer.toString(localPart), Integer.class);
             if (cached) synchronized (SEQUENCE_NUMBERS) {
                 /*
-                 * No need to check if a value has been set concurrently because Names.createMemberName(…)
+                 * No need to check if a value has been set concurrently because `createMemberName(…)`
                  * already checked if an equal instance exists in the current JVM.
                  */
                 SEQUENCE_NUMBERS[localPart] = name;


[sis] 02/03: Constructor argument should be `CharSequence` instead of `InternationalString` for consistency with similar constructors in the rest of metadata packages.

Posted by de...@apache.org.
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 74d119635edbcc8ab4812fd9f688f04dcfeb1123
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Nov 15 17:13:06 2022 +0100

    Constructor argument should be `CharSequence` instead of `InternationalString`
    for consistency with similar constructors in the rest of metadata packages.
---
 .../apache/sis/metadata/iso/quality/DefaultDescription.java    | 10 ++++++++++
 .../sis/metadata/iso/quality/DefaultDescriptiveResult.java     |  7 ++++---
 .../sis/metadata/iso/quality/DefaultIndirectEvaluation.java    |  5 +++--
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDescription.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDescription.java
index 5e55eaf6e0..53337934f1 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDescription.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDescription.java
@@ -22,6 +22,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.quality.Description;
 import org.opengis.metadata.identification.BrowseGraphic;
+import org.apache.sis.util.iso.Types;
 import org.apache.sis.xml.Namespaces;
 
 
@@ -76,6 +77,15 @@ public class DefaultDescription extends ISOMetadata implements Description {
     public DefaultDescription() {
     }
 
+    /**
+     * Constructs a description initialized with the given text.
+     *
+     * @param  text  text description, or {@code null} if none.
+     */
+    public DefaultDescription(final CharSequence text) {
+        textDescription = Types.toInternationalString(text);
+    }
+
     /**
      * Constructs a new instance initialized with the values from the specified metadata object.
      * This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDescriptiveResult.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDescriptiveResult.java
index d7b7868f33..96b6c1dbe8 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDescriptiveResult.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultDescriptiveResult.java
@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.quality.DescriptiveResult;
+import org.apache.sis.util.iso.Types;
 
 
 /**
@@ -71,10 +72,10 @@ public class DefaultDescriptiveResult extends AbstractResult implements Descript
     /**
      * Creates a conformance result initialized to the given values.
      *
-     * @param statement  statement against which data is being evaluated, or {@code null}.
+     * @param text  statement against which data is being evaluated, or {@code null}.
      */
-    public DefaultDescriptiveResult(final InternationalString statement) {
-        this.statement = statement;
+    public DefaultDescriptiveResult(final CharSequence text) {
+        statement = Types.toInternationalString(text);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultIndirectEvaluation.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultIndirectEvaluation.java
index 05fa85596b..474eebaf4a 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultIndirectEvaluation.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultIndirectEvaluation.java
@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import org.opengis.util.InternationalString;
 import org.opengis.metadata.quality.IndirectEvaluation;
+import org.apache.sis.util.iso.Types;
 
 
 /**
@@ -73,8 +74,8 @@ public class DefaultIndirectEvaluation extends AbstractDataEvaluation implements
      *
      * @param  source  information on which data are used as sources, or {@code null}.
      */
-    public DefaultIndirectEvaluation(final InternationalString source) {
-        deductiveSource = source;
+    public DefaultIndirectEvaluation(final CharSequence source) {
+        deductiveSource = Types.toInternationalString(source);
     }
 
     /**


[sis] 03/03: Add a few tests for metadata quality package.

Posted by de...@apache.org.
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 a31026987c0c7cdf08bae87098cb745032c8947d
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Nov 15 18:12:47 2022 +0100

    Add a few tests for metadata quality package.
---
 .../iso/quality/DefaultQuantitativeResult.java     | 14 ++++++
 .../iso/quality/DefaultDomainConsistencyTest.java  | 47 ++++++++++++++++++++
 .../iso/quality/DefaultQuantitativeResultTest.java | 50 ++++++++++++++++++++++
 .../apache/sis/test/suite/MetadataTestSuite.java   |  2 +
 4 files changed, 113 insertions(+)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java
index d92e2565c0..8e0d1a1b6f 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java
@@ -253,4 +253,18 @@ public class DefaultQuantitativeResult extends AbstractResult implements Quantit
         checkWritePermission(errorStatistic);
         errorStatistic = newValue;
     }
+
+    /**
+     * Returns {@code true} if this metadata contains only {@code null}, nil or empty properties.
+     * The deprecated {@code errorStatistic} is also verified because there is no non-deprecated
+     * replacement receiving a value that {@code super.isEmpty()} would recognize.
+     *
+     * @return {@code true} if this metadata is empty.
+     *
+     * @hidden
+     */
+    @Override
+    public boolean isEmpty() {
+        return super.isEmpty() && errorStatistic == null;
+    }
 }
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultDomainConsistencyTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultDomainConsistencyTest.java
new file mode 100644
index 0000000000..0ad12c0936
--- /dev/null
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultDomainConsistencyTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.metadata.iso.quality;
+
+import java.util.Map;
+import java.util.Collections;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link DefaultDomainConsistency}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.3
+ * @since   1.3
+ * @module
+ */
+public final strictfp class DefaultDomainConsistencyTest extends TestCase {
+    /**
+     * Tests {@link DefaultDomainConsistency#asMap()}.
+     */
+    @Test
+    public void testAsMap() {
+        final DefaultDescriptiveResult r = new DefaultDescriptiveResult("A result");
+        final DefaultDomainConsistency c = new DefaultDomainConsistency();
+        final Map<String,Object> m = c.asMap();
+        c.setResults(Collections.singleton(r));
+        assertEquals(Collections.singletonList(r), m.get("result"));
+    }
+}
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResultTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResultTest.java
new file mode 100644
index 0000000000..ebd8da6df4
--- /dev/null
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResultTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.metadata.iso.quality;
+
+import org.apache.sis.util.SimpleInternationalString;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link DefaultQuantitativeResult}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.3
+ * @since   1.3
+ * @module
+ */
+public final strictfp class DefaultQuantitativeResultTest extends TestCase {
+    /**
+     * Tests {@link DefaultQuantitativeResult#isEmpty()}. The {@code isEmpty()} method needs a special check
+     * for the deprecated {@code "errorStatistic"} property because, contrarily to other deprecated properties,
+     * that one has no replacement. Consequently no non-deprecated property is set as a result of redirection.
+     * Because by default {@code isEmpty()} ignores deprecated properties,
+     * it can cause {@link DefaultQuantitativeResult} to be wrongly considered as empty.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testIsEmpty() {
+        final DefaultQuantitativeResult r = new DefaultQuantitativeResult();
+        assertTrue(r.isEmpty());
+        r.setErrorStatistic(new SimpleInternationalString("a description"));
+        assertFalse(r.isEmpty());
+    }
+}
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java b/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
index a7f8adda19..f570c1bf7d 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
@@ -120,6 +120,8 @@ import org.junit.BeforeClass;
     org.apache.sis.metadata.iso.identification.DefaultServiceIdentificationTest.class,
     org.apache.sis.metadata.iso.quality.AbstractElementTest.class,
     org.apache.sis.metadata.iso.quality.AbstractPositionalAccuracyTest.class,
+    org.apache.sis.metadata.iso.quality.DefaultDomainConsistencyTest.class,
+    org.apache.sis.metadata.iso.quality.DefaultQuantitativeResultTest.class,
     org.apache.sis.metadata.iso.quality.ScopeCodeTest.class,
     org.apache.sis.metadata.iso.lineage.DefaultLineageTest.class,
     org.apache.sis.metadata.iso.lineage.DefaultProcessStepTest.class,