sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/02: Remove LegacyPropertyAdapter.asCollection(…) method since it duplicates CollectionsExt.singletonOrEmpty(…).
Date Sun, 05 May 2019 15:40:39 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 50b074f84a445b683f6f1dcf1de50b40ad309fb8
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sun May 5 17:39:55 2019 +0200

    Remove LegacyPropertyAdapter.asCollection(…) method since it duplicates CollectionsExt.singletonOrEmpty(…).
---
 .../apache/sis/internal/metadata/LegacyPropertyAdapter.java | 13 +------------
 .../org/apache/sis/internal/metadata/MetadataUtilities.java |  3 ++-
 .../sis/metadata/iso/DefaultExtendedElementInformation.java |  5 +++--
 .../java/org/apache/sis/metadata/iso/DefaultMetadata.java   |  4 ++--
 .../apache/sis/metadata/iso/citation/DefaultContact.java    |  7 ++++---
 .../metadata/iso/content/DefaultCoverageDescription.java    |  9 +++++----
 .../iso/distribution/DefaultDigitalTransferOptions.java     |  2 +-
 .../apache/sis/metadata/iso/distribution/DefaultFormat.java |  3 ++-
 .../apache/sis/metadata/iso/distribution/DefaultMedium.java |  5 +++--
 .../iso/maintenance/DefaultMaintenanceInformation.java      |  5 +++--
 .../org/apache/sis/metadata/iso/quality/DefaultScope.java   |  3 ++-
 11 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
index a07d302..34701f1 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
@@ -191,20 +191,9 @@ public abstract class LegacyPropertyAdapter<L,N> extends AbstractCollection<L>
{
     }
 
     /**
-     * Returns the given value as an empty or singleton collection.
-     *
-     * @param  <L>    the type of the old value.
-     * @param  value  the value, or {@code null} if none.
-     * @return the given value as a collection.
-     */
-    public static <L> Collection<L> asCollection(final L value) {
-        return (value != null) ? Collections.singleton(value) : Collections.emptySet();
-    }
-
-    /**
      * Returns {@code true} if the given metadata is empty.
      */
-    static boolean isEmpty(final Object container) {
+    private static boolean isEmpty(final Object container) {
         return (container instanceof Emptiable) && ((Emptiable) container).isEmpty();
     }
 
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
index e8a219d..0e88012 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
@@ -29,6 +29,7 @@ import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.util.Strings;
+import org.apache.sis.internal.util.CollectionsExt;
 
 
 /**
@@ -219,7 +220,7 @@ public final class MetadataUtilities extends Static {
      */
     public static <T> Collection<T> setFirst(Collection<T> values, final
T newValue) {
         if (values == null) {
-            return LegacyPropertyAdapter.asCollection(newValue);
+            return CollectionsExt.singletonOrEmpty(newValue);
         }
         if (newValue == null) {
             final Iterator<T> it = values.iterator();
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
index 450c8d8..a6e3c3a 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
@@ -33,10 +33,11 @@ import org.apache.sis.util.iso.Types;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.NilReason;
 import org.apache.sis.internal.jaxb.Context;
-import org.apache.sis.internal.xml.LegacyNamespaces;
 import org.apache.sis.internal.jaxb.FilterByVersion;
+import org.apache.sis.internal.xml.LegacyNamespaces;
 import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+import org.apache.sis.internal.util.CollectionsExt;
 
 import static org.apache.sis.internal.metadata.MetadataUtilities.ensurePositive;
 
@@ -577,7 +578,7 @@ public class DefaultExtendedElementInformation extends ISOMetadata implements
Ex
 
             /** Returns an iterator over 0 or 1 element. Current iterator implementation
is unmodifiable. */
             @Override public Iterator<InternationalString> iterator() {
-                return LegacyPropertyAdapter.asCollection(getRationale()).iterator();
+                return CollectionsExt.singletonOrEmpty(getRationale()).iterator();
             }
 
             /** Adds an element only if the set is empty. This method is invoked by JAXB
at unmarshalling time. */
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
index 92e9b02..d67d579 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
@@ -706,7 +706,7 @@ public class DefaultMetadata extends ISOMetadata implements Metadata {
      */
     @Deprecated
     public void setCharacterSet(final CharacterSet newValue) {
-        setCharacterSets(LegacyPropertyAdapter.asCollection((newValue != null) ? newValue.toCharset()
: null));
+        setCharacterSets(CollectionsExt.singletonOrEmpty((newValue != null) ? newValue.toCharset()
: null));
     }
 
     /**
@@ -1646,7 +1646,7 @@ public class DefaultMetadata extends ISOMetadata implements Metadata
{
      * Sets the character coding standard for the metadata set (used in legacy ISO 19157
format).
      */
     private void setCharset(final Charset newValue) {
-        setCharacterSets(LegacyPropertyAdapter.asCollection(newValue));
+        setCharacterSets(CollectionsExt.singletonOrEmpty(newValue));
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java
index 117d1bc..dab0444 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java
@@ -33,10 +33,11 @@ import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.jaxb.FilterByVersion;
-import org.apache.sis.internal.xml.LegacyNamespaces;
 import org.apache.sis.internal.jaxb.gco.InternationalStringAdapter;
 import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+import org.apache.sis.internal.xml.LegacyNamespaces;
+import org.apache.sis.internal.util.CollectionsExt;
 
 
 /**
@@ -337,7 +338,7 @@ public class DefaultContact extends ISOMetadata implements Contact {
      */
     @Deprecated
     public void setAddress(final Address newValue) {
-        setAddresses(LegacyPropertyAdapter.asCollection(newValue));
+        setAddresses(CollectionsExt.singletonOrEmpty(newValue));
     }
 
     /**
@@ -393,7 +394,7 @@ public class DefaultContact extends ISOMetadata implements Contact {
      */
     @Deprecated
     public void setOnlineResource(final OnlineResource newValue) {
-        setOnlineResources(LegacyPropertyAdapter.asCollection(newValue));
+        setOnlineResources(CollectionsExt.singletonOrEmpty(newValue));
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
index 5af5218..5439958 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
@@ -31,10 +31,11 @@ import org.opengis.metadata.content.ImageDescription;
 import org.opengis.metadata.content.RangeDimension;
 import org.opengis.metadata.content.RangeElementDescription;
 import org.opengis.util.RecordType;
+import org.apache.sis.internal.util.CollectionsExt;
+import org.apache.sis.internal.xml.LegacyNamespaces;
 import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 import org.apache.sis.internal.jaxb.FilterByVersion;
-import org.apache.sis.internal.xml.LegacyNamespaces;
 import org.apache.sis.internal.jaxb.metadata.MD_Identifier;
 
 import static org.apache.sis.internal.metadata.MetadataUtilities.valueIfDefined;
@@ -279,7 +280,7 @@ public class DefaultCoverageDescription extends AbstractContentInformation
imple
     @Deprecated
     public void setContentType(final CoverageContentType newValue) {
         checkWritePermission(valueIfDefined(attributeGroups));
-        final Collection<CoverageContentType> newValues = LegacyPropertyAdapter.asCollection(newValue);
+        final Collection<CoverageContentType> newValues = CollectionsExt.singletonOrEmpty(newValue);
         Collection<AttributeGroup> groups = attributeGroups;
         if (groups != null) {
             for (final AttributeGroup group : groups) {
@@ -317,7 +318,7 @@ public class DefaultCoverageDescription extends AbstractContentInformation
imple
             /** Stores a legacy value into the new kind of value. */
             @Override protected AttributeGroup wrap(final RangeDimension value) {
                 final DefaultAttributeGroup container = new DefaultAttributeGroup();
-                container.setAttributes(asCollection(value));
+                container.setAttributes(CollectionsExt.singletonOrEmpty(value));
                 return container;
             }
 
@@ -330,7 +331,7 @@ public class DefaultCoverageDescription extends AbstractContentInformation
imple
             /** Updates the legacy value in an existing instance of the new kind of value.
*/
             @Override protected boolean update(final AttributeGroup container, final RangeDimension
value) {
                 if (container instanceof DefaultAttributeGroup) {
-                    ((DefaultAttributeGroup) container).setAttributes(asCollection(value));
+                    ((DefaultAttributeGroup) container).setAttributes(CollectionsExt.singletonOrEmpty(value));
                     return true;
                 }
                 return false;
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
index 1dca3e0..e0a0678 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
@@ -283,7 +283,7 @@ public class DefaultDigitalTransferOptions extends ISOMetadata implements
Digita
      */
     @Deprecated
     public void setOffLine(final Medium newValue) {
-        setOffLines(LegacyPropertyAdapter.asCollection(newValue));
+        setOffLines(CollectionsExt.singletonOrEmpty(newValue));
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java
index 5db6209..c894219 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java
@@ -33,6 +33,7 @@ import org.apache.sis.internal.jaxb.FilterByVersion;
 import org.apache.sis.internal.xml.LegacyNamespaces;
 import org.apache.sis.internal.jaxb.metadata.MD_Medium;
 import org.apache.sis.internal.jaxb.metadata.CI_Citation;
+import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.ISOMetadata;
 
@@ -303,7 +304,7 @@ public class DefaultFormat extends ISOMetadata implements Format {
     public void setName(final InternationalString newValue) {
         checkWritePermission(formatSpecificationCitation);
         setFormatSpecificationCitation((citation, value) ->
-                citation.setAlternateTitles(LegacyPropertyAdapter.asCollection(value)), newValue);
+                citation.setAlternateTitles(CollectionsExt.singletonOrEmpty(value)), newValue);
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
index fdcbfc4..c262b5c 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
@@ -36,9 +36,10 @@ import org.apache.sis.internal.jaxb.FilterByVersion;
 import org.apache.sis.internal.jaxb.metadata.CI_Citation;
 import org.apache.sis.internal.jaxb.metadata.MD_Identifier;
 import org.apache.sis.internal.metadata.legacy.MediumName;
-import org.apache.sis.internal.xml.LegacyNamespaces;
 import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+import org.apache.sis.internal.xml.LegacyNamespaces;
+import org.apache.sis.internal.util.CollectionsExt;
 
 import static org.apache.sis.internal.metadata.MetadataUtilities.ensurePositive;
 
@@ -250,7 +251,7 @@ public class DefaultMedium extends ISOMetadata implements Medium {
 
             /** Returns an iterator over 0 or 1 element. Current iterator implementation
is unmodifiable. */
             @Override public Iterator<Double> iterator() {
-                return LegacyPropertyAdapter.asCollection(getDensity()).iterator();
+                return CollectionsExt.singletonOrEmpty(getDensity()).iterator();
             }
 
             /** Adds an element only if the set is empty. This method is invoked by JAXB
at unmarshalling time. */
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
index 1760003..a39cd91 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
@@ -39,6 +39,7 @@ import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.jaxb.FilterByVersion;
 import org.apache.sis.internal.xml.LegacyNamespaces;
+import org.apache.sis.internal.util.CollectionsExt;
 
 import static org.apache.sis.internal.metadata.MetadataUtilities.valueIfDefined;
 
@@ -409,7 +410,7 @@ public class DefaultMaintenanceInformation extends ISOMetadata implements
Mainte
             /** Stores a legacy value into the new kind of value. */
             @Override protected Scope wrap(final ScopeDescription value) {
                 final DefaultScope container = new DefaultScope();
-                container.setLevelDescription(asCollection(value));
+                container.setLevelDescription(CollectionsExt.singletonOrEmpty(value));
                 return container;
             }
 
@@ -422,7 +423,7 @@ public class DefaultMaintenanceInformation extends ISOMetadata implements
Mainte
             /** Updates the legacy value in an existing instance of the new kind of value.
*/
             @Override protected boolean update(final Scope container, final ScopeDescription
value) {
                 if (container instanceof DefaultScope) {
-                    ((DefaultScope) container).setLevelDescription(asCollection(value));
+                    ((DefaultScope) container).setLevelDescription(CollectionsExt.singletonOrEmpty(value));
                     return true;
                 }
                 return false;
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
index 2172bc9..fcdbbae 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
@@ -23,6 +23,7 @@ import org.opengis.metadata.quality.Scope;
 import org.opengis.metadata.maintenance.ScopeCode;
 import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+import org.apache.sis.internal.util.CollectionsExt;
 
 
 /**
@@ -132,6 +133,6 @@ public class DefaultScope extends org.apache.sis.metadata.iso.maintenance.Defaul
      */
     @Deprecated
     public void setExtent(final Extent newValue) {
-        setExtents(LegacyPropertyAdapter.asCollection(newValue));
+        setExtents(CollectionsExt.singletonOrEmpty(newValue));
     }
 }


Mime
View raw message