sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/04: Remove unnecessary reference to Citation standard in PropertyAccessor.
Date Tue, 04 Jun 2019 16:21:27 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 88826a8bffe9f4baf43319f8f0aaff35126d0969
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jun 4 16:27:33 2019 +0200

    Remove unnecessary reference to Citation standard in PropertyAccessor.
---
 .../org/apache/sis/metadata/InformationMap.java     | 14 +++++++++++---
 .../org/apache/sis/metadata/MetadataStandard.java   |  6 +++---
 .../org/apache/sis/metadata/PropertyAccessor.java   | 21 +++++++--------------
 .../java/org/apache/sis/metadata/SpecialCases.java  |  6 ++----
 .../apache/sis/metadata/PropertyAccessorTest.java   | 18 +++++++++---------
 .../sis/metadata/PropertyConsistencyCheck.java      |  4 ++--
 .../org/apache/sis/metadata/SpecialCasesTest.java   |  8 ++++----
 7 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/InformationMap.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/InformationMap.java
index 94cf320..53e8bf6 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/InformationMap.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/InformationMap.java
@@ -19,6 +19,7 @@ package org.apache.sis.metadata;
 import java.util.Map;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
+import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.ExtendedElementInformation;
 
 
@@ -37,13 +38,20 @@ import org.opengis.metadata.ExtendedElementInformation;
  */
 final class InformationMap extends PropertyMap<ExtendedElementInformation> {
     /**
+     * The standard which define the {@link PropertyAccessor#type} interface.
+     */
+    private final Citation standard;
+
+    /**
      * Creates an information map for the specified accessor.
      *
+     * @param standard   the standard which define the {@code accessor.type} interface.
      * @param accessor   the accessor to use for the metadata.
      * @param keyPolicy  determines the string representation of keys in the map.
      */
-    InformationMap(final PropertyAccessor accessor, final KeyNamePolicy keyPolicy) {
+    InformationMap(final Citation standard, final PropertyAccessor accessor, final KeyNamePolicy
keyPolicy) {
         super(accessor, keyPolicy);
+        this.standard = standard;
     }
 
     /**
@@ -53,7 +61,7 @@ final class InformationMap extends PropertyMap<ExtendedElementInformation>
{
     @Override
     public ExtendedElementInformation get(final Object key) {
         if (key instanceof String) {
-            return accessor.information(accessor.indexOf((String) key, false));
+            return accessor.information(standard, accessor.indexOf((String) key, false));
         }
         return null;
     }
@@ -66,7 +74,7 @@ final class InformationMap extends PropertyMap<ExtendedElementInformation>
{
         return new Iter() {
             @Override
             public Map.Entry<String,ExtendedElementInformation> next() {
-                final ExtendedElementInformation value = accessor.information(index);
+                final ExtendedElementInformation value = accessor.information(standard, index);
                 if (value == null) {
                     // PropertyAccessor.information(int) never return null if the index is
valid.
                     throw new NoSuchElementException();
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
index 7d02300..5ea0960 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
@@ -378,9 +378,9 @@ public class MetadataStandard implements Serializable {
             final Class<?> standardImpl = getImplementation(type);
             final PropertyAccessor accessor;
             if (SpecialCases.isSpecialCase(type)) {
-                accessor = new SpecialCases(citation, type, k.type, standardImpl);
+                accessor = new SpecialCases(type, k.type, standardImpl);
             } else {
-                accessor = new PropertyAccessor(citation, type, k.type, standardImpl);
+                accessor = new PropertyAccessor(type, k.type, standardImpl);
             }
             return accessor;
         });
@@ -766,7 +766,7 @@ public class MetadataStandard implements Serializable {
     {
         ensureNonNull("type",     type);
         ensureNonNull("keyNames", keyPolicy);
-        return new InformationMap(getAccessor(createCacheKey(type), true), keyPolicy);
+        return new InformationMap(citation, getAccessor(createCacheKey(type), true), keyPolicy);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
index 5d2e52f..5544ed7 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
@@ -29,7 +29,6 @@ import org.opengis.annotation.UML;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.ExtendedElementInformation;
 import org.apache.sis.internal.util.CollectionsExt;
-import org.apache.sis.internal.util.Citations;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.measure.ValueRange;
 import org.apache.sis.util.Classes;
@@ -115,11 +114,6 @@ class PropertyAccessor {
     }
 
     /**
-     * The standard which define the {@link #type} interface.
-     */
-    private final Citation standard;
-
-    /**
      * The implemented metadata interface.
      */
     final Class<?> type;
@@ -229,22 +223,20 @@ class PropertyAccessor {
      * The array will be created when first needed. A {@code null} element means that
      * the information at that index has not yet been computed.
      *
-     * @see #information(int)
+     * @see #information(Citation, int)
      */
     private transient ExtendedElementInformation[] informations;
 
     /**
      * Creates a new property accessor for the specified metadata implementation.
      *
-     * @param  standard        the standard which define the {@code type} interface.
      * @param  type            the interface implemented by the metadata class.
      * @param  implementation  the class of metadata implementations, or {@code type} if
none.
      * @param  standardImpl    the implementation specified by the {@link MetadataStandard},
or {@code null} if none.
      *                         This is the same than {@code implementation} unless a custom
implementation is used.
      */
-    PropertyAccessor(final Citation standard, final Class<?> type, final Class<?>
implementation, final Class<?> standardImpl) {
+    PropertyAccessor(final Class<?> type, final Class<?> implementation, final
Class<?> standardImpl) {
         assert type.isAssignableFrom(implementation) : implementation;
-        this.standard       = standard;
         this.type           = type;
         this.implementation = implementation;
         this.getters        = getGetters(type, implementation, standardImpl);
@@ -645,13 +637,14 @@ class PropertyAccessor {
      * Returns the information for the property at the given index.
      * The information are created when first needed.
      *
-     * @param  index  the index of the property for which to get the information.
+     * @param  standard  the standard which define the {@link #type} interface.
+     * @param  index     the index of the property for which to get the information.
      * @return the information for the property at the given index, or {@code null} if the
index is out of bounds.
      *
      * @see PropertyInformation
      */
     @SuppressWarnings({"unchecked","rawtypes"})
-    final synchronized ExtendedElementInformation information(final int index) {
+    final synchronized ExtendedElementInformation information(final Citation standard, final
int index) {
         ExtendedElementInformation[] informations = this.informations;
         if (informations == null) {
             this.informations = informations = new PropertyInformation<?>[standardCount];
@@ -1297,7 +1290,7 @@ class PropertyAccessor {
      * Output example:
      *
      * {@preformat text
-     *     PropertyAccessor[13 getters & 13 setters in DefaultCitation:Citation from
“ISO 19115”]
+     *     PropertyAccessor[13 getters & 13 setters in DefaultCitation:Citation]
      * }
      */
     @Override
@@ -1321,6 +1314,6 @@ class PropertyAccessor {
         if (type != implementation) {
             buffer.append(':').append(Classes.getShortName(type));
         }
-        return buffer.append(" from “").append(Citations.getIdentifier(standard, false)).append("”]").toString();
+        return buffer.append(']').toString();
     }
 }
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
index 6186158..bf476f3 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
@@ -16,7 +16,6 @@
  */
 package org.apache.sis.metadata;
 
-import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.extent.GeographicBoundingBox;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Longitude;
@@ -43,15 +42,14 @@ final class SpecialCases extends PropertyAccessor {
     /**
      * Creates a new property accessor for the specified metadata implementation.
      *
-     * @param  standard        the standard which define the {@code type} interface.
      * @param  type            the interface implemented by the metadata, which must be
      *                         the value returned by {@link MetadataStandard#findInterface(CacheKey)}.
      * @param  implementation  the class of metadata implementations, or {@code type} if
none.
      * @param  standardImpl    the implementation specified by the {@link MetadataStandard},
or {@code null} if none.
      *                         This is the same than {@code implementation} unless a custom
implementation is used.
      */
-    SpecialCases(final Citation standard, final Class<?> type, final Class<?>
implementation, final Class<?> standardImpl) {
-        super(standard, type, implementation, standardImpl);
+    SpecialCases(final Class<?> type, final Class<?> implementation, final Class<?>
standardImpl) {
+        super(type, implementation, standardImpl);
         assert isSpecialCase(type) : type;
         westBoundLongitude = indexOf("westBoundLongitude", true);
         eastBoundLongitude = indexOf("eastBoundLongitude", true);
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
index ec01d42..1651ba7 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
@@ -91,7 +91,7 @@ public final strictfp class PropertyAccessorTest extends TestCase {
      * Creates a new property accessor for the {@link DefaultCitation} class.
      */
     private static PropertyAccessor createPropertyAccessor() {
-        return new PropertyAccessor(HardCodedCitations.ISO_19115, Citation.class, DefaultCitation.class,
DefaultCitation.class);
+        return new PropertyAccessor(Citation.class, DefaultCitation.class, DefaultCitation.class);
     }
 
     /**
@@ -201,7 +201,7 @@ public final strictfp class PropertyAccessorTest extends TestCase {
     @Test
     @DependsOnMethod("testConstructor")
     public void testConstructorWithInheritance() {
-        assertMappingEquals(new PropertyAccessor(HardCodedCitations.ISO_19115, DataIdentification.class,
DefaultDataIdentification.class, DefaultDataIdentification.class),
+        assertMappingEquals(new PropertyAccessor(DataIdentification.class, DefaultDataIdentification.class,
DefaultDataIdentification.class),
         //……Declaring type………………………Method………………………………………………………………………JavaBeans………………………………………………………UML
identifier………………………………………Sentence……………………………………………………………Type………………………………………………………………
             Identification.class, "getCitation",                   "citation",          
        "citation",                  "Citation",                     Citation.class,
             Identification.class, "getAbstract",                   "abstract",          
        "abstract",                  "Abstract",                     InternationalString.class,
@@ -236,7 +236,7 @@ public final strictfp class PropertyAccessorTest extends TestCase {
     @DependsOnMethod("testConstructorWithInheritance")
     public void testConstructorWithCovariantReturnType() {
         final Class<?> type = GeographicCRS.class;
-        assertMappingEquals(new PropertyAccessor(HardCodedCitations.ISO_19111, type, type,
type),
+        assertMappingEquals(new PropertyAccessor(type, type, type),
         //……Declaring type……………………………Method……………………………………………JavaBeans……………………………UML
identifier………………Sentence…………………………………Type…………………………………………………………
             GeographicCRS.class,    "getCoordinateSystem", "coordinateSystem", "coordinateSystem",
"Coordinate system",  EllipsoidalCS.class,       // Covariant return type
             GeodeticCRS.class,      "getDatum",            "datum",            "datum", 
          "Datum",              GeodeticDatum.class,       // Covariant return type
@@ -249,15 +249,15 @@ public final strictfp class PropertyAccessorTest extends TestCase {
     }
 
     /**
-     * Tests the {@link PropertyAccessor#information(int)} method.
+     * Tests the {@link PropertyAccessor#information(Citation, int)} method.
      * This method delegates to some {@link PropertyInformationTest} methods.
      */
     @Test
     @DependsOnMethod("testConstructor")
     public void testInformation() {
         final PropertyAccessor accessor = createPropertyAccessor();
-        PropertyInformationTest.validateTitle           (accessor.information(accessor.indexOf("title",
           true)));
-        PropertyInformationTest.validatePresentationForm(accessor.information(accessor.indexOf("presentationForm",
true)));
+        PropertyInformationTest.validateTitle           (accessor.information(HardCodedCitations.ISO_19115,
accessor.indexOf("title",            true)));
+        PropertyInformationTest.validatePresentationForm(accessor.information(HardCodedCitations.ISO_19115,
accessor.indexOf("presentationForm", true)));
     }
 
     /**
@@ -365,8 +365,8 @@ public final strictfp class PropertyAccessorTest extends TestCase {
     @Test
     @DependsOnMethod("testSet")
     public void testSetDeprecated() {
-        final PropertyAccessor accessor = new PropertyAccessor(HardCodedCitations.ISO_19115,
-                CoverageDescription.class, DefaultCoverageDescription.class, DefaultCoverageDescription.class);
+        final PropertyAccessor accessor = new PropertyAccessor(CoverageDescription.class,
+                    DefaultCoverageDescription.class, DefaultCoverageDescription.class);
         final int indexOfDeprecated  = accessor.indexOf("contentType", true);
         final int indexOfReplacement = accessor.indexOf("attributeGroup", true);
         assertTrue("Deprecated elements shall be sorted after non-deprecated ones.",
@@ -622,7 +622,7 @@ public final strictfp class PropertyAccessorTest extends TestCase {
     @Test
     public void testToString() {
         final PropertyAccessor accessor = createPropertyAccessor();
-        assertEquals("PropertyAccessor[14 getters (+1 ext.) & 15 setters in DefaultCitation:Citation
from “ISO 19115”]", accessor.toString());
+        assertEquals("PropertyAccessor[14 getters (+1 ext.) & 15 setters in DefaultCitation:Citation]",
accessor.toString());
     }
 
     /**
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyConsistencyCheck.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyConsistencyCheck.java
index 4f73282..1fd7067 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyConsistencyCheck.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyConsistencyCheck.java
@@ -195,7 +195,7 @@ public abstract strictfp class PropertyConsistencyCheck extends AnnotationConsis
                 final Class<?> impl = getImplementation(type);
                 if (impl != null) {
                     assertTrue("Not an implementation of expected interface.", type.isAssignableFrom(impl));
-                    testPropertyValues(new PropertyAccessor(standard.getCitation(), type,
impl, impl));
+                    testPropertyValues(new PropertyAccessor(type, impl, impl));
                 }
             }
         }
@@ -334,7 +334,7 @@ public abstract strictfp class PropertyConsistencyCheck extends AnnotationConsis
                 if (an != null) {
                     final String name = an.name();
                     final String message = impl.getSimpleName() + '.' + name;
-                    final PropertyAccessor accessor = new PropertyAccessor(standard.getCitation(),
type, impl, impl);
+                    final PropertyAccessor accessor = new PropertyAccessor(type, impl, impl);
 
                     // Property shall exist.
                     final int index = accessor.indexOf(name, false);
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
index 441ff7d..4bc17d1 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
@@ -56,8 +56,7 @@ public final strictfp class SpecialCasesTest extends TestCase {
      * Creates a new test case.
      */
     public SpecialCasesTest() {
-        accessor = new SpecialCases(HardCodedCitations.ISO_19115,
-                GeographicBoundingBox.class, DefaultGeographicBoundingBox.class, DefaultGeographicBoundingBox.class);
+        accessor = new SpecialCases(GeographicBoundingBox.class, DefaultGeographicBoundingBox.class,
DefaultGeographicBoundingBox.class);
     }
 
     /**
@@ -187,11 +186,12 @@ public final strictfp class SpecialCasesTest extends TestCase {
     }
 
     /**
-     * Tests {@link SpecialCases#information(int)}.
+     * Tests {@link SpecialCases#information(Citation, int)}.
      */
     @Test
     public void testPropertyInformation() {
-        final ExtendedElementInformation info = accessor.information(accessor.indexOf("westBoundLongitude",
true));
+        final ExtendedElementInformation info = accessor.information(
+                HardCodedCitations.ISO_19115, accessor.indexOf("westBoundLongitude", true));
         final InternationalString domain = info.getDomainValue();
         assertInstanceOf("Expected numerical information about range.", NumberRange.class,
domain);
         final NumberRange<?> range = (NumberRange) domain;


Mime
View raw message