sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 04/04: Remove the deprecated ModifiableMetadata.unmodifiable() method.
Date Thu, 12 Sep 2019 14:53:45 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 1387466ac20d88d5b3ab36209d6e1730e0ed7dde
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Sep 12 16:53:01 2019 +0200

    Remove the deprecated ModifiableMetadata.unmodifiable() method.
---
 .../apache/sis/metadata/ModifiableMetadata.java    | 120 +--------------------
 .../metadata/iso/citation/DefaultTelephone.java    |   4 +-
 .../metadata/iso/citation/DefaultCitationTest.java |  17 ---
 .../referencing/gazetteer/FinalLocationType.java   |  20 ++--
 .../sis/referencing/gazetteer/package-info.java    |   2 +-
 .../referencing/gazetteer/LocationTypeTest.java    |   2 +-
 6 files changed, 20 insertions(+), 145 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
index a6a196f..f9c3b78 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
@@ -133,16 +133,6 @@ public abstract class ModifiableMetadata extends AbstractMetadata {
     private transient byte state;
 
     /**
-     * An unmodifiable copy of this metadata, created only when first needed.
-     * If {@code null}, then no unmodifiable entity is available.
-     * If {@code this}, then this entity is itself unmodifiable.
-     *
-     * @deprecated to be deleted after the removal of {@link #unmodifiable()}.
-     */
-    @Deprecated
-    private transient ModifiableMetadata unmodifiable;
-
-    /**
      * Constructs an initially empty metadata.
      * The initial state is {@link State#EDITABLE}.
      */
@@ -297,112 +287,6 @@ public abstract class ModifiableMetadata extends AbstractMetadata {
     }
 
     /**
-     * Returns {@code true} if this metadata is modifiable. This method returns
-     * {@code false} if {@link #freeze()} has been invoked on this object.
-     *
-     * @return {@code true} if this metadata is modifiable.
-     *
-     * @see #freeze()
-     * @see #checkWritePermission()
-     *
-     * @deprecated Replaced by <code>{@linkplain #state()} != State.FINAL</code>.
-     *             See <a href="https://issues.apache.org/jira/browse/SIS-81">SIS-81</a>.
-     */
-    @Deprecated
-    public final boolean isModifiable() {
-        return state <= STAGED;
-    }
-
-    /**
-     * Returns an unmodifiable copy of this metadata. Any attempt to modify a property of
the
-     * returned object will throw an {@link UnmodifiableMetadataException}. The state of
this
-     * object is not modified.
-     *
-     * <p>This method is useful for reusing the same metadata object as a template.
-     * For example:</p>
-     *
-     * {@preformat java
-     *     DefaultCitation myCitation = new DefaultCitation();
-     *     myCitation.setTitle(new SimpleInternationalString("The title of my book"));
-     *     myCitation.setEdition(new SimpleInternationalString("First edition"));
-     *     final Citation firstEdition = (Citation) myCitation.unmodifiable();
-     *
-     *     myCitation.setEdition(new SimpleInternationalString("Second edition"));
-     *     final Citation secondEdition = (Citation) myCitation.unmodifiable();
-     *     // The title of the second edition is unchanged compared to the first edition.
-     * }
-     *
-     * The default implementation makes the following choice:
-     *
-     * <ul>
-     *   <li>If this metadata is itself unmodifiable, then this method returns {@code
this} unchanged.</li>
-     *   <li>Otherwise this method {@linkplain #clone() clone} this metadata and
-     *       {@linkplain #freeze() freeze} the clone before to return it.</li>
-     * </ul>
-     *
-     * @return an unmodifiable copy of this metadata.
-     *
-     * @see MetadataCopier
-     *
-     * @deprecated Replaced by {@code MetadataCopier.forModifiable(getStandard()).copy(this).transition(State.FINAL)}.
-     */
-    @Deprecated
-    public AbstractMetadata unmodifiable() {
-        if (!isModifiable()) {
-            unmodifiable = this;
-        }
-        /*
-         * The 'unmodifiable' field is reset to null by checkWritePermission().
-         * However this is not sufficient since the setter method of some child
-         * could have been invoked without invoking any setter method on 'this'.
-         * So we also need to perform an equality check.
-         */
-        if (unmodifiable == null || !equals(unmodifiable)) {
-            final ModifiableMetadata candidate = (ModifiableMetadata) MetadataCopier.forModifiable(getStandard()).copy(this);
-            candidate.freeze();
-            /*
-             * Set the field only after success. The 'unmodifiable' field must
-             * stay null if an exception occurred during clone() or freeze().
-             */
-            unmodifiable = candidate;
-        }
-        assert !unmodifiable.isModifiable();
-        return unmodifiable;
-    }
-
-    /**
-     * Declares this metadata and all its properties as unmodifiable. Any attempt to modify
a
-     * property after this method call will throw an {@link UnmodifiableMetadataException}.
-     * If this metadata is already unmodifiable, then this method does nothing.
-     *
-     * <p>Subclasses usually do not need to override this method since the default
implementation
-     * performs its work using Java reflection.</p>
-     *
-     * @see #state()
-     * @see #checkWritePermission()
-     *
-     * @deprecated Replaced by {@code transition(State.FINAL)}.
-     */
-    @Deprecated
-    public void freeze() {
-        transition(State.FINAL);
-    }
-
-    /**
-     * @deprecated Replaced by {@link #checkWritePermission(Object)}.
-     *
-     * @throws UnmodifiableMetadataException if this metadata is unmodifiable.
-     */
-    @Deprecated
-    protected void checkWritePermission() throws UnmodifiableMetadataException {
-        if (state == FINAL) {
-            throw new UnmodifiableMetadataException(Resources.format(Resources.Keys.UnmodifiableMetadata));
-        } else {
-            unmodifiable = null;                    // Discard since this metadata is going
to change.
-        }
-    }
-
-    /**
      * Checks if changes in the metadata are allowed. All {@code setFoo(…)} methods in
subclasses
      * shall invoke this method (directly or indirectly) before to apply any change.
      * The current property value should be specified in argument.
@@ -416,7 +300,9 @@ public abstract class ModifiableMetadata extends AbstractMetadata {
      */
     protected void checkWritePermission(Object current) throws UnmodifiableMetadataException
{
         if (state != COMPLETABLE) {
-            checkWritePermission();
+            if (state == FINAL) {
+                throw new UnmodifiableMetadataException(Resources.format(Resources.Keys.UnmodifiableMetadata));
+            }
         } else if (current != null) {
             final MetadataStandard standard;
             if (current instanceof AbstractMetadata) {
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
index f1aef1f..f9d6f7c 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
@@ -216,8 +216,8 @@ public class DefaultTelephone extends ISOMetadata implements Telephone
{
      *
      * <p>This field references the same collection than {@link DefaultContact#phones}
when possible.
      * Note that the link between this collection and {@code DefaultContact.phones} is broken
when
-     * {@link DefaultContact#freeze()} is invoked, since the {@code Cloner.clone(Object)}
method
-     * creates a new (unmodifiable) collection.</p>
+     * {@link DefaultContact} is copied by {@link org.apache.sis.metadata.MetadataCopier},
since the
+     * {@code Cloner.clone(Object)} method creates a new (unmodifiable) collection.</p>
      *
      * @deprecated This field will be removed after we removed the deprecated public methods.
      */
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java
index b4a11d8..ec877ca 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultCitationTest.java
@@ -157,23 +157,6 @@ public final strictfp class DefaultCitationTest extends TestUsingFile
{
     }
 
     /**
-     * Tests {@link DefaultCitation#unmodifiable()}.
-     *
-     * @deprecated To be removed after we removed {@link DefaultCitation#unmodifiable()}.
-     */
-    @Test
-    @Deprecated
-    public void testUnmodifiable() {
-        final DefaultCitation original = create();
-        final DefaultCitation clone = (DefaultCitation) original.unmodifiable();    // This
will invoke 'freeze()'.
-        assertSame("original.unmodifiable", clone, original.unmodifiable());
-        assertSame("clone.unmodifiable",    clone, clone.unmodifiable());
-        assertEquals("original.state", DefaultCitation.State.EDITABLE, original.state());
-        assertEquals("clone.state",    DefaultCitation.State.FINAL,    clone.state());
-        assertCopy(original, clone);
-    }
-
-    /**
      * Verifies that {@code clone} is a copy of {@code original}, sharing same instance
of values when possible.
      */
     private static void assertCopy(final DefaultCitation original, final DefaultCitation
clone) {
diff --git a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
index 255a2bf..5ca0cd2 100644
--- a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
+++ b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/FinalLocationType.java
@@ -26,6 +26,7 @@ import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.extent.GeographicExtent;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 import org.apache.sis.metadata.ModifiableMetadata;
+import org.apache.sis.metadata.MetadataCopier;
 import org.apache.sis.util.ArgumentChecks;
 
 // Branch-dependent imports
@@ -40,7 +41,7 @@ import org.opengis.referencing.gazetteer.ReferenceSystemUsingIdentifiers;
  * system than the original location type.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.1
  * @since   0.8
  * @module
  */
@@ -134,8 +135,8 @@ final class FinalLocationType extends AbstractLocationType implements
Serializab
         theme           = source.getTheme();
         identifications = snapshot(source.getIdentifications());
         definition      = source.getDefinition();
-        territoryOfUse  = (GeographicExtent) unmodifiable(source.getTerritoryOfUse());
-        owner           = (Party) unmodifiable(source.getOwner());
+        territoryOfUse  = unmodifiable(GeographicExtent.class, source.getTerritoryOfUse());
+        owner           = unmodifiable(Party.class, source.getOwner());
         parents         = snapshot(source.getParents(),  rs, existing);
         children        = snapshot(source.getChildren(), rs, existing);
         referenceSystem = rs;
@@ -196,13 +197,18 @@ final class FinalLocationType extends AbstractLocationType implements
Serializab
 
     /**
      * Returns an unmodifiable copy of the given metadata, if necessary and possible.
+     *
+     * @param  <T>       compile-time value of the {@code type} argument.
+     * @param  type      the interface of the metadata object to eventually copy.
+     * @param  metadata  the metadata object to eventually copy, or {@code null}.
+     * @return an unmodifiable copy of the given metadata object, or {@code null} if the
given argument is {@code null}.
      */
-    private static Object unmodifiable(final Object metadata) {
+    private static <T> T unmodifiable(final Class<T> type, T metadata) {
         if (metadata instanceof ModifiableMetadata) {
-            return ((ModifiableMetadata) metadata).unmodifiable();
-        } else {
-            return metadata;
+            metadata = MetadataCopier.forModifiable(((ModifiableMetadata) metadata).getStandard()).copy(type,
metadata);
+            ((ModifiableMetadata) metadata).transition(ModifiableMetadata.State.FINAL);
         }
+        return metadata;
     }
 
     /**
diff --git a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
index 2a273b7..f74a09b 100644
--- a/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
+++ b/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
@@ -31,7 +31,7 @@
  *
  * @author  Chris Mattmann (JPL)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.1
  * @since   0.8
  * @module
  */
diff --git a/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
b/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
index 461ae41..34a3971 100644
--- a/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
+++ b/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/LocationTypeTest.java
@@ -33,7 +33,7 @@ import org.opengis.referencing.gazetteer.LocationType;
  * Tests {@link AbstractLocationType}, {@link FinalLocationType} and {@link ModifiableLocationType}.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.1
  * @since   0.8
  * @module
  */


Mime
View raw message