sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1609852 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/ sis-metadata/src/main/j...
Date Fri, 11 Jul 2014 22:06:55 GMT
Author: desruisseaux
Date: Fri Jul 11 22:06:55 2014
New Revision: 1609852

URL: http://svn.apache.org/r1609852
Log:
Upgraded DefaultTelephone and DefaultContact to ISO 19115:2014. Those 2 classes were tricky,
because those 2 standards changed the places were multi-occurrences of telephone numbers were
managed. Keeping compatibility between both the old and new standards required DefaultTelephone
to know about the DefaultContact instance that contains it.

Added:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/LegacyTelephones.java   (with props)
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java   (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Cloner.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/AbstractParty.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -22,6 +22,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import org.apache.sis.metadata.AbstractMetadata;
+import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.ArgumentChecks;
 
@@ -159,8 +160,8 @@ public abstract class LegacyPropertyAdap
                         }
                         caller.warningOccurred = true;
                     }
-                    MetadataUtilities.warning(callerClass, callerMethod,
-                            Messages.Keys.IgnoredPropertiesAfterFirst_1, valueClass);
+                    Context.warningOccured(Context.current(), callerClass, callerMethod,
+                            Messages.class, Messages.Keys.IgnoredPropertiesAfterFirst_1, valueClass);
                 }
                 return value;
             }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Cloner.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Cloner.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Cloner.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/Cloner.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -105,7 +105,11 @@ final class Cloner extends org.apache.si
                 } else {
                     // Conservatively assumes a List if we are not sure to have a Set,
                     // since the list is less destructive (no removal of duplicated).
-                    collection = Containers.unmodifiableList(array);
+                    switch (array.length) {
+                        case 0:  collection = Collections.EMPTY_LIST; break; // Redundant with isEmpty(), but we are paranoiac.
+                        case 1:  collection = Collections.singletonList(array[0]); break;
+                        default: collection = Containers.unmodifiableList(array); break;
+                    }
                 }
             }
             return collection;

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ModifiableMetadata.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -385,7 +385,7 @@ public abstract class ModifiableMetadata
             if (unmodifiable == FREEZING) {
                 /*
                  * freeze() method is under progress. The source collection is already
-                 * an unmodifiable instance created by unmodifiable(Object).
+                 * an unmodifiable instance created by Cloner.clone(Object).
                  */
                 assert collectionType(elementType).isInstance(source);
                 return (Collection<E>) source;

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -1100,9 +1100,7 @@ class PropertyAccessor {
     {
         assert type.isInstance(metadata1) : metadata1;
         assert type.isInstance(metadata2) : metadata2;
-        final int count = (mode == ComparisonMode.STRICT &&
-                EXTRA_GETTER.getDeclaringClass().isInstance(metadata2)) ? allCount : standardCount;
-        for (int i=0; i<count; i++) {
+        for (int i=0; i<standardCount; i++) {
             final Method method = getters[i];
             final Object value1 = get(method, metadata1);
             final Object value2 = get(method, metadata2);
@@ -1118,6 +1116,16 @@ class PropertyAccessor {
                 return false;
             }
         }
+        /*
+         * One final check for the IdentifiedObjects.getIdentifiers() collection.
+         */
+        if (mode == ComparisonMode.STRICT && EXTRA_GETTER.getDeclaringClass().isInstance(metadata2)) {
+            final Object value1 = get(EXTRA_GETTER, metadata1);
+            final Object value2 = get(EXTRA_GETTER, metadata2);
+            if (!isNullOrEmpty(value1) || !isNullOrEmpty(value2)) {
+                return Utilities.deepEquals(value1, value2, mode);
+            }
+        }
         return true;
     }
 

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/AbstractParty.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/AbstractParty.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/AbstractParty.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/AbstractParty.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -28,7 +28,7 @@ import org.apache.sis.util.iso.Types;
 
 
 /**
- * Information about the individual and / or organisation of the party.
+ * Information about the individual and / or organization of the party.
  *
  * @author  Rémi Maréchal (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -174,7 +174,7 @@ public class DefaultCitation extends ISO
      * Constructs a citation with the specified responsible party.
      * This convenience constructor initializes the citation title
      * to the first non-null of the following properties:
-     * {@linkplain DefaultResponsibleParty#getOrganisationName() organisation name},
+     * {@linkplain DefaultResponsibleParty#getOrganisationName() organization name},
      * {@linkplain DefaultResponsibleParty#getPositionName() position name} or
      * {@linkplain DefaultResponsibleParty#getIndividualName() individual name}.
      *

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -16,6 +16,9 @@
  */
 package org.apache.sis.metadata.iso.citation;
 
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collection;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
@@ -24,7 +27,11 @@ import org.opengis.metadata.citation.Add
 import org.opengis.metadata.citation.Contact;
 import org.opengis.metadata.citation.Telephone;
 import org.opengis.metadata.citation.OnlineResource;
+import org.opengis.metadata.citation.TelephoneType;
 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.metadata.LegacyPropertyAdapter;
 
 
 /**
@@ -33,8 +40,9 @@ import org.apache.sis.metadata.iso.ISOMe
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Touraïvane (IRD)
  * @author  Cédric Briançon (Geomatys)
+ * @author  Rémi Maréchal (Geomatys)
  * @since   0.3 (derived from geotk-2.1)
- * @version 0.3
+ * @version 0.5
  * @module
  */
 @XmlType(name = "CI_Contact_Type", propOrder = {
@@ -49,22 +57,22 @@ public class DefaultContact extends ISOM
     /**
      * Serial number for inter-operability with different versions.
      */
-    private static final long serialVersionUID = 3844283689911660546L;
+    private static final long serialVersionUID = -969735574940462381L;
 
     /**
      * Telephone numbers at which the organization or individual may be contacted.
      */
-    private Telephone phone;
+    private Collection<Telephone> phones;
 
     /**
-     * Physical and email address at which the organization or individual may be contacted.
+     * Physical and email addresses at which the organization or individual may be contacted.
      */
-    private Address address;
+    private Collection<Address> addresses;
 
     /**
      * On-line information that can be used to contact the individual or organization.
      */
-    private OnlineResource onlineResource;
+    private Collection<OnlineResource> onlineResources;
 
     /**
      * Time period (including time zone) when individuals can contact the organization or individual.
@@ -77,6 +85,11 @@ public class DefaultContact extends ISOM
     private InternationalString contactInstructions;
 
     /**
+     * Type of the contact.
+     */
+    private InternationalString contactType;
+
+    /**
      * Constructs an initially empty contact.
      */
     public DefaultContact() {
@@ -89,7 +102,7 @@ public class DefaultContact extends ISOM
      *        organization, or {@code null} if none.
      */
     public DefaultContact(final OnlineResource resource) {
-        this.onlineResource = resource;
+        this.onlineResources = singleton(resource, OnlineResource.class);
     }
 
     /**
@@ -104,11 +117,12 @@ public class DefaultContact extends ISOM
     public DefaultContact(final Contact object) {
         super(object);
         if (object != null) {
-            phone               = object.getPhone();
-            address             = object.getAddress();
-            onlineResource      = object.getOnlineResource();
+            phones              = copyCollection(object.getPhones(), Telephone.class);
+            addresses           = copyCollection(object.getAddresses(), Address.class);
+            onlineResources     = copyCollection(object.getOnlineResources(), OnlineResource.class);
             hoursOfService      = object.getHoursOfService();
             contactInstructions = object.getContactInstructions();
+            contactType         = object.getContactType();
         }
     }
 
@@ -140,64 +154,208 @@ public class DefaultContact extends ISOM
     /**
      * Returns telephone numbers at which the organization or individual may be contacted.
      *
+     * @return Telephone numbers at which the organization or individual may be contacted.
+     *
+     * @since 0.5
+     */
+    @Override
+    public Collection<Telephone> getPhones() {
+        return phones = nonNullCollection(phones, Telephone.class);
+    }
+
+    /**
+     * Sets telephone numbers at which the organization or individual may be contacted.
+     *
+     * @param newValues The new telephones.
+     *
+     * @since 0.5
+     */
+    public void setPhones(Collection<? extends Telephone> newValues) {
+        phones = writeCollection(newValues, phones, Telephone.class);
+        /*
+         * Code below this point will be deleted after we removed the deprecated methods in DefaultTelephone.
+         * This code notifies all DefaultTelephone instances about the the list of phones in order to allow
+         * the deprecated Telephone.getVoices() and Telephone.getFacsimiles() methods to fetches information
+         * from the phones list.
+         */
+        if (phones != null) {
+            boolean modified = false;
+            final Telephone[] p = phones.toArray(new Telephone[newValues.size()]);
+            for (int i=0; i<p.length; i++) {
+                final Telephone phone = p[i];
+                if (phone instanceof DefaultTelephone) {
+                    p[i] = ((DefaultTelephone) phone).setOwner(phones);
+                    modified |= (p[i] != phone);
+                }
+            }
+            if (modified) {
+                phones.clear();
+                phones.addAll(Arrays.asList(p));
+            }
+        }
+    }
+
+    /**
+     * Returns telephone numbers at which the organization or individual may be contacted.
+     * This method returns the first telephone number associated to {@link TelephoneType#VOICE}
+     * or {@link TelephoneType#FACSIMILE FACSIMILE}.
+     *
      * @return Telephone numbers at which the organization or individual may be contacted, or {@code null}.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by {@link #getPhones()}.
      */
     @Override
+    @Deprecated
     @XmlElement(name = "phone")
-    public Telephone getPhone() {
+    public final Telephone getPhone() {
+        Telephone phone = null;
+        if (phones != null) {
+            TelephoneType ignored = null;
+            for (final Telephone c : phones) {
+                final TelephoneType type = c.getNumberType();
+                if (TelephoneType.VOICE.equals(type) || TelephoneType.FACSIMILE.equals(type)) {
+                    if (phone == null) {
+                        phone = c;
+                    }
+                } else if (ignored == null) {
+                    ignored = type;
+                }
+            }
+            if (ignored != null) {
+                Context.warningOccured(Context.current(), DefaultContact.class, "getPhone",
+                        Messages.class, Messages.Keys.IgnoredPropertyAssociatedTo_1, ignored.toString());
+            }
+        }
         return phone;
     }
 
     /**
      * Sets telephone numbers at which the organization or individual may be contacted.
+     * This method delegates to {@link #setPhones(Collection)}.
      *
      * @param newValue The new telephone, or {@code null} if none.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by {@link #setPhones(Collection)}.
      */
-    public void setPhone(final Telephone newValue) {
-        checkWritePermission();
-        phone = newValue;
+    @Deprecated
+    public final void setPhone(Telephone newValue) {
+        Collection<Telephone> newValues = null;
+        if (newValue != null) {
+            if (newValue instanceof DefaultTelephone) {
+                newValues = ((DefaultTelephone) newValue).getOwner();
+            } else {
+                newValues = new ArrayList<>(4);
+                for (String number : newValue.getVoices()) {
+                    newValues.add(new DefaultTelephone(number, TelephoneType.VOICE));
+                }
+                for (String number : newValue.getFacsimiles()) {
+                    newValues.add(new DefaultTelephone(number, TelephoneType.FACSIMILE));
+                }
+            }
+        }
+        setPhones(newValues);
+    }
+
+    /**
+     * Returns the physical and email addresses at which the organization or individual may be contacted.
+     *
+     * @return Physical and email addresses at which the organization or individual may be contacted, or {@code null}.
+     *
+     * @since 0.5
+     */
+    @Override
+    public Collection<Address> getAddresses() {
+        return addresses = nonNullCollection(addresses, Address.class);
+    }
+
+    /**
+     * Sets the physical and email addresses at which the organization or individual may be contacted.
+     *
+     * @param newValues The new addresses.
+     *
+     * @since 0.5
+     */
+    public void setAddresses(final Collection<? extends Address> newValues) {
+        addresses = writeCollection(newValues, addresses, Address.class);
     }
 
     /**
      * Returns the physical and email address at which the organization or individual may be contacted.
+     * This method returns the first {@link #getAddresses() adress} element, or null if none.
      *
      * @return Physical and email address at which the organization or individual may be contacted, or {@code null}.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by {@link #getAddresses()}.
      */
     @Override
+    @Deprecated
     @XmlElement(name = "address")
-    public Address getAddress() {
-        return address;
+    public final Address getAddress() {
+        return LegacyPropertyAdapter.getSingleton(addresses, Address.class, null, DefaultContact.class, "getAddress");
     }
 
     /**
      * Sets the physical and email address at which the organization or individual may be contacted.
+     * This method delegates to {@link #setAddresses(Collection)}.
      *
      * @param newValue The new address, or {@code null} if none.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by {@link #setAddresses(Collectio)}.
      */
-    public void setAddress(final Address newValue) {
-        checkWritePermission();
-        address = newValue;
+    @Deprecated
+    public final void setAddress(final Address newValue) {
+        setAddresses(LegacyPropertyAdapter.asCollection(newValue));
+    }
+
+    /**
+     * Returns on-line information that can be used to contact the individual or organization.
+     *
+     * @return On-line information that can be used to contact the individual or organization.
+     *
+     * @since 0.5
+     */
+    @Override
+    public Collection<OnlineResource> getOnlineResources() {
+        return onlineResources = nonNullCollection(onlineResources, OnlineResource.class);
+    }
+
+    /**
+     * Sets on-line information that can be used to contact the individual or organization.
+     *
+     * @param newValues The new online resources.
+     *
+     * @since 0.5
+     */
+    public void setOnlineResources(final Collection<? extends OnlineResource> newValues) {
+        onlineResources = writeCollection(newValues, onlineResources, OnlineResource.class);
     }
 
     /**
-     * Return on-line information that can be used to contact the individual or organization.
+     * Returns on-line information that can be used to contact the individual or organization.
+     * This method returns the first {@link #getOnlineResources() online resource} element, or null if none.
      *
      * @return On-line information that can be used to contact the individual or organization, or {@code null}.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by {@link #getOnlineResources()}.
      */
     @Override
+    @Deprecated
     @XmlElement(name = "onlineResource")
     public OnlineResource getOnlineResource() {
-        return onlineResource;
+        return LegacyPropertyAdapter.getSingleton(onlineResources, OnlineResource.class, null, DefaultContact.class, "getOnlineResource");
     }
 
     /**
      * Sets on-line information that can be used to contact the individual or organization.
+     * This method delegates to {@link #setOnlineResources(Collection)}.
      *
      * @param newValue The new online resource, or {@code null} if none.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by {@link #setOnlineResources(Collection)}.
      */
+    @Deprecated
     public void setOnlineResource(final OnlineResource newValue) {
-        checkWritePermission();
-        onlineResource = newValue;
+        setOnlineResources(LegacyPropertyAdapter.asCollection(newValue));
     }
 
     /**
@@ -241,4 +399,30 @@ public class DefaultContact extends ISOM
         checkWritePermission();
         contactInstructions = newValue;
     }
+
+    /**
+     * Type of the contact.
+     * Returns {@code null} if none.
+     *
+     * @return Type of the contact, or {@code null} if none.
+     *
+     * @since 0.5
+     */
+    @Override
+/// @XmlElement(name = "contactType")
+    public InternationalString getContactType() {
+        return contactType;
+    }
+
+    /**
+     * Sets new type of the contact.
+     *
+     * @param newValue The new type of the contact.
+     *
+     * @since 0.5
+     */
+    public void setContactType(final InternationalString newValue) {
+        checkWritePermission();
+        contactType = newValue;
+    }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -30,7 +30,7 @@ import org.opengis.util.InternationalStr
  * organizations associated with the dataset.
  *
  * @deprecated As of ISO 19115:2014, the {@code ResponsibleParty} type has been replaced by {@code Responsibility}
- *             to allow more flexible associations of individuals, organisations, and roles.
+ *             to allow more flexible associations of individuals, organizations, and roles.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Touraïvane (IRD)

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -1,4 +1,4 @@
-/*
+ /*
  * 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.
@@ -16,22 +16,42 @@
  */
 package org.apache.sis.metadata.iso.citation;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
 import org.opengis.metadata.citation.Telephone;
+import org.opengis.metadata.citation.TelephoneType;
+import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.metadata.iso.ISOMetadata;
 
 
 /**
  * Telephone numbers for contacting the responsible individual or organization.
  *
+ * {@section Differences between versions 2003 and 2014 of ISO 19115}
+ * For any contact having more than one telephone number, the way to organize the information
+ * changed significantly between the two versions of ISO standard:
+ *
+ * <ul>
+ *   <li>In ISO 19115:2003, each {@code Contact} had only one {@code Telephone} instance, but that instance
+ *       could have an arbitrary amount of "voice" and "facsimile" numbers. The methods (now deprecated) were
+ *       {@link DefaultContact#getPhone()}, {@link #getVoices()} and {@link #getFacsimiles()}.</li>
+ *   <li>In ISO 19115:2014, each {@code Contact} has an arbitrary amount of {@code Telephone} instances, and
+ *       each telephone has exactly one number. The new methods are {@link DefaultContact#getPhones()},
+ *       {@link #getNumber()} and {@link #getNumberType()}.</li>
+ * </ul>
+ *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Cédric Briançon (Geomatys)
- * @since   0.3 (derived from geotk-2.1)
- * @version 0.3
+ * @author  Rémi Maréchal (Geomatys)
+ * @since   0.5 (derived from geotk-2.1)
+ * @version 0.5
  * @module
+ *
+ * @see DefaultContact#getPhones()
  */
 @XmlType(name = "CI_Telephone_Type", propOrder = {
     "voices",
@@ -42,17 +62,17 @@ public class DefaultTelephone extends IS
     /**
      * Serial number for inter-operability with different versions.
      */
-    private static final long serialVersionUID = -1920621361930970869L;
+    private static final long serialVersionUID = 5156405432420742237L;
 
     /**
-     * Telephone numbers by which individuals can speak to the responsible organization or individual.
+     * Telephone number by which individuals can contact responsible organization or individual.
      */
-    private Collection<String> voices;
+    private String number;
 
     /**
-     * Telephone numbers of a facsimile machine for the responsible organization or individual.
+     * Type of telephone number.
      */
-    private Collection<String> facsimiles;
+    private TelephoneType numberType;
 
     /**
      * Constructs a default telephone.
@@ -61,6 +81,19 @@ public class DefaultTelephone extends IS
     }
 
     /**
+     * Constructs a telephone with the given number and type.
+     *
+     * @param number     The telephone number, or {@code null}.
+     * @param numberType The type of telephone number, or {@code null}.
+     *
+     * @since 0.5
+     */
+    public DefaultTelephone(final String number, final TelephoneType numberType) {
+        this.number     = number;
+        this.numberType = numberType;
+    }
+
+    /**
      * 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
      * given object are not recursively copied.
@@ -72,8 +105,8 @@ public class DefaultTelephone extends IS
     public DefaultTelephone(final Telephone object) {
         super(object);
         if (object != null) {
-            voices     = copyCollection(object.getVoices(), String.class);
-            facsimiles = copyCollection(object.getFacsimiles(), String.class);
+            number     = object.getNumber();
+            numberType = object.getNumberType();
         }
     }
 
@@ -103,42 +136,171 @@ public class DefaultTelephone extends IS
     }
 
     /**
+     * Returns the telephone number by which individuals can contact responsible organization or individual.
+     *
+     * @return Telephone number by which individuals can contact responsible organization or individual.
+     *
+     * @since 0.5
+     */
+    @Override
+/// @XmlElement(name = "number", required = true)
+    public String getNumber() {
+        return number;
+    }
+
+    /**
+     * Sets the telephone number by which individuals can contact responsible organization or individual.
+     *
+     * @param newValue The new telephone number by which individuals can contact responsible organization or individual.
+     *
+     * @since 0.5
+     */
+    public void setNumber(final String newValue) {
+        checkWritePermission();
+        number = newValue;
+    }
+
+    /**
+     * Returns the type of telephone number, or {@code null} if none.
+     *
+     * @return Type of telephone number, or {@code null} if none.
+     *
+     * @since 0.5
+     */
+    @Override
+/// @XmlElement(name = "numberType")
+    public TelephoneType getNumberType() {
+        return numberType;
+    }
+
+    /**
+     * Set the type of telephone number.
+     *
+     * @param newValue The new type of telephone number.
+     *
+     * @since 0.5
+     */
+    public void setNumberType(final TelephoneType newValue) {
+        checkWritePermission();
+        numberType = newValue;
+    }
+
+    /**
+     * For implementation of {@link #getVoices()} and {@link #getFacsimiles()} deprecated methods.
+     * Shall be the telephones list of the enclosing {@link DefaultContact} object.
+     *
+     * <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>
+     *
+     * @deprecated This field will be removed after we removed the deprecated public methods.
+     */
+    @Deprecated
+    private Collection<Telephone> owner;
+
+    /**
+     * Specifies the collection which contains this telephone number.
+     * This method is invoked by {@link DefaultContact#setPhones(Collection)}
+     * when the contact "takes possession" of a {@code DefaultTelephone}.
+     *
+     * <p>This method will be removed after we removed the deprecated public methods.</p>
+     *
+     * @param  phones The collection which should contains this telephone number.
+     * @return {@code this}, or a copy of this instance if we conservatively choose to not modify this instance.
+     */
+    final DefaultTelephone setOwner(final Collection<Telephone> phones) {
+        if (owner != phones) {
+            if (owner != null && !CollectionsExt.identityEquals(owner.iterator(), phones.iterator())) {
+                final DefaultTelephone copy = new DefaultTelephone(this);
+                copy.owner = phones;
+                return copy;
+            }
+            owner = phones;
+        }
+        return this;
+    }
+
+    /**
+     * Returns the collection that own this telephone number, or create a new collection.
+     * Creating a new collection is needed when this phone number has not yet been given
+     * to a {@link DefaultContact}.
+     *
+     * <p>This method will be removed after we removed the deprecated public methods.</p>
+     */
+    final Collection<Telephone> getOwner() {
+       if (owner == null) {
+           if (isModifiable()) {
+               owner = new ArrayList<>(4);
+               owner.add(this);
+           } else {
+               owner = Collections.singletonList(this);
+           }
+       }
+       return owner;
+    }
+
+    /**
      * Returns the telephone numbers by which individuals can speak to the responsible organization or individual.
+     * This method searches in the {@linkplain DefaultContact#getPhones() contact phones}, if the contact that own
+     * this phone is known.
      *
      * @return Telephone numbers by which individuals can speak to the responsible organization or individual.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by a {@linkplain #getNumber() number}
+     *             with {@link TelephoneType#VOICE}.
      */
     @Override
+    @Deprecated
     @XmlElement(name = "voice")
-    public Collection<String> getVoices() {
-        return voices = nonNullCollection(voices, String.class);
+    public final Collection<String> getVoices() {
+        return new LegacyTelephones(getOwner(), TelephoneType.VOICE);
     }
 
     /**
      * Sets the telephone numbers by which individuals can speak to the responsible organization or individual.
+     * This method writes in the {@linkplain DefaultContact#getPhones() contact phones}, if the contact that own
+     * this phone is known.
      *
      * @param newValues The new telephone numbers, or {@code null} if none.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by a {@linkplain #setNumber(String) number}
+     *             with {@link TelephoneType#VOICE}.
      */
-    public void setVoices(final Collection<? extends String> newValues) {
-        voices = writeCollection(newValues, voices, String.class);
+    @Deprecated
+    public final void setVoices(final Collection<? extends String> newValues) {
+        ((LegacyTelephones) getVoices()).setValues(newValues);
     }
 
     /**
      * Returns the telephone numbers of a facsimile machine for the responsible organization or individual.
+     * This method searches in the {@linkplain DefaultContact#getPhones() contact phones}, if the contact
+     * that own this phone is known.
      *
      * @return Telephone numbers of a facsimile machine for the responsible organization or individual.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by a {@linkplain #getNumber() number}
+     *             with {@link TelephoneType#FACSIMILE}.
      */
     @Override
+    @Deprecated
     @XmlElement(name = "facsimile")
-    public Collection<String> getFacsimiles() {
-        return facsimiles = nonNullCollection(facsimiles, String.class);
+    public final Collection<String> getFacsimiles() {
+        return new LegacyTelephones(getOwner(), TelephoneType.FACSIMILE);
     }
 
     /**
      * Sets the telephone number of a facsimile machine for the responsible organization or individual.
+     * This method writes in the {@linkplain DefaultContact#getPhones() contact phones}, if the contact
+     * that own this phone is known.
      *
      * @param newValues The new telephone number, or {@code null} if none.
+     *
+     * @deprecated As of ISO 19115:2014, replaced by a {@linkplain #setNumber(String) number}
+     *             with {@link TelephoneType#FACSIMILE}.
      */
-    public void setFacsimiles(final Collection<? extends String> newValues) {
-        facsimiles = writeCollection(newValues, facsimiles, String.class);
+    @Deprecated
+    public final void setFacsimiles(final Collection<? extends String> newValues) {
+        ((LegacyTelephones) getFacsimiles()).setValues(newValues);
     }
 }

Added: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/LegacyTelephones.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/LegacyTelephones.java?rev=1609852&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/LegacyTelephones.java (added)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/LegacyTelephones.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -0,0 +1,89 @@
+/*
+ * 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.citation;
+
+import java.util.Collection;
+import org.opengis.metadata.citation.Telephone;
+import org.opengis.metadata.citation.TelephoneType;
+import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+
+
+/**
+ * An adapter for converting telephone lists from ISO 19115:2014 definition to ISO 19115:2003 definition.
+ * Used for implementation of deprecated {@link DefaultTelephone#getVoices()} and
+ * {@link DefaultTelephone#getFacsimiles()} methods.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+final class LegacyTelephones extends LegacyPropertyAdapter<String,Telephone> {
+    /**
+     * The type of telephone number.
+     * Either {@link TelephoneType#VOICE} or {@link TelephoneType#FACSIMILE}.
+     */
+    private final TelephoneType type;
+
+    /**
+     * Wraps the given telephone list for the given type.
+     */
+    LegacyTelephones(final Collection<Telephone> telephones, final TelephoneType type) {
+        super(telephones);
+        this.type = type;
+    }
+
+    /**
+     * Wraps the given telephone number in a new {@link DefaultTelephone} instance.
+     */
+    @Override
+    protected Telephone wrap(final String value) {
+        final DefaultTelephone telephone = new DefaultTelephone();
+        telephone.setNumber(value);
+        telephone.setNumberType(type);
+        return telephone;
+    }
+
+    /**
+     * Extracts the telephone number from the given {@link DefaultTelephone} instance.
+     */
+    @Override
+    protected String unwrap(final Telephone container) {
+        if (container != null && type.equals(container.getNumberType())) {
+            return container.getNumber();
+        }
+        return null;
+    }
+
+    /**
+     * Updates the telephone number in an existing {@link DefaultTelephone} instance, if possible.
+     */
+    @Override
+    protected boolean update(final Telephone container, final String value) {
+        if (container instanceof DefaultTelephone) {
+            final TelephoneType ct = container.getNumberType();
+            if (ct == null || ct.equals(type)) {
+                if (ct == null) {
+                    ((DefaultTelephone) container).setNumberType(type);
+                }
+                ((DefaultTelephone) container).setNumber(value);
+                return true;
+            }
+        }
+        return false;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/LegacyTelephones.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/LegacyTelephones.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -30,9 +30,9 @@ import org.opengis.metadata.content.Rang
 import org.opengis.metadata.content.RangeElementDescription;
 import org.opengis.util.RecordType;
 import org.apache.sis.xml.Namespaces;
+import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
-import org.apache.sis.internal.metadata.MetadataUtilities;
 
 
 /**
@@ -229,8 +229,8 @@ public class DefaultCoverageDescription 
                         if (type == null) {
                             type = t;
                         } else {
-                            MetadataUtilities.warning(DefaultCoverageDescription.class, "getContentType",
-                                    Messages.Keys.IgnoredPropertiesAfterFirst_1, CoverageContentType.class);
+                            Context.warningOccured(Context.current(), DefaultCoverageDescription.class, "getContentType",
+                                    Messages.class, Messages.Keys.IgnoredPropertiesAfterFirst_1, CoverageContentType.class);
                             break;
                         }
                     }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -86,7 +86,7 @@ public final strictfp class TreeNodeTest
         final DefaultContact contact = new DefaultContact();
         final DefaultAddress address = new DefaultAddress();
         address.getElectronicMailAddresses().add("Some email");
-        contact.setAddress(address);
+        contact.getAddresses().add(address);
         party.setContactInfo(contact);
         citation.getCitedResponsibleParties().add(party);
         return citation;
@@ -236,7 +236,7 @@ public final strictfp class TreeNodeTest
               ONE,          // citedResponsibleParty
                 null,       // individualName
                 null,       // contactInfo
-                  null,     // address
+                  ZERO,     // address
                     ZERO,   // electronicMailAddress
                 null,       // role
               ZERO,         // presentationForm

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -57,7 +57,7 @@ public final strictfp class DefaultMetad
     private Object[] parameters;
 
     /**
-     * For internal {@code DefaultLegalConstraints} usage.
+     * For internal {@code DefaultMetadata} usage.
      *
      * @return {@code Object.class}.
      */

Added: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java?rev=1609852&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java (added)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -0,0 +1,188 @@
+/*
+ * 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.citation;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.logging.LogRecord;
+import org.opengis.metadata.citation.Telephone;
+import org.opengis.metadata.citation.TelephoneType;
+import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.util.logging.WarningListener;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.XMLTestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link DefaultContact} and its interaction with {@link DefaultTelephone}.
+ * Those two classes are a little bit tricky because of the deprecated telephone methods.
+ * See {@link DefaultTelephone} class javadoc for more information.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public final strictfp class DefaultContactTest extends XMLTestCase implements WarningListener<Object> {
+    /**
+     * The resource key for the message of the warning that occurred, or {@code null} if none.
+     */
+    private Object resourceKey;
+
+    /**
+     * The parameter of the warning that occurred, or {@code null} if none.
+     */
+    private Object[] parameters;
+
+    /**
+     * For internal {@code DefaultContact} usage.
+     *
+     * @return {@code Object.class}.
+     */
+    @Override
+    public Class<Object> getSourceClass() {
+        return Object.class;
+    }
+
+    /**
+     * Invoked when a warning occurred while unmarshalling a test XML fragment. This method ensures that no other
+     * warning occurred before this method call (i.e. each test is allowed to cause at most one warning), then
+     * remember the warning parameters for verification by the test method.
+     *
+     * @param source  Ignored.
+     * @param warning The warning.
+     */
+    @Override
+    public void warningOccured(final Object source, final LogRecord warning) {
+        assertNull(resourceKey);
+        assertNull(parameters);
+        assertNotNull(resourceKey = warning.getMessage());
+        assertNotNull(parameters  = warning.getParameters());
+    }
+
+    /**
+     * Initializes the test for catching warning messages.
+     */
+    private void init() {
+        context = new Context(0, null, null, null, null, null, null, this);
+    }
+
+    /**
+     * Tests the ISO 19115:2014 {@link DefaultContact#setPhones(Collection)} method,
+     * then query with both the new and the deprecated methods.
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testSetPhones() {
+        init();
+        final DefaultTelephone   tel1 = new DefaultTelephone("00.01", TelephoneType.SMS);
+        final DefaultTelephone   tel2 = new DefaultTelephone("00.02", TelephoneType.VOICE);
+        final DefaultTelephone   tel3 = new DefaultTelephone("00.03", TelephoneType.FACSIMILE);
+        final DefaultTelephone   tel4 = new DefaultTelephone("00.04", TelephoneType.VOICE);
+        final DefaultTelephone[] tels = new DefaultTelephone[] {tel1, tel2, tel3, tel4};
+        final DefaultContact  contact = new DefaultContact();
+        contact.setPhones(Arrays.asList(tel1, tel2, tel3, tel4));
+        assertArrayEquals("getPhones", tels, contact.getPhones().toArray());
+        /*
+         * Test the deprecated 'getPhone()' method. Invoking that method shall emit
+         * a warning, since the ISO 19115:2003 methods can not represent SMS numbers.
+         */
+        assertSame("getPhone", tel2, contact.getPhone()); // Shall ignore the TelephoneType.SMS.
+        assertEquals("warningOccured", "IgnoredPropertyAssociatedTo_1", resourceKey);
+        assertArrayEquals("warningOccured", new String[] {"TelephoneType[SMS]"}, parameters);
+        verifyLegacyLists(tels);
+    }
+
+    /**
+     * Verify that the {@link DefaultTelephone#getVoices()} and {@link DefaultTelephone#getFacsimiles()} methods see
+     * all numbers declared in the parent {@link DefaultContact}. This method presumes that each telephone contains:
+     *
+     * <ul>
+     *   <li>Two voice numbers: "00.02" and "00.04" in that order.</li>
+     *   <li>One facsimile number: "00.03".</li>
+     * </ul>
+     */
+    @SuppressWarnings("deprecation")
+    private static void verifyLegacyLists(final Telephone... tels) {
+        final String[] voices = {"00.02", "00.04"};
+        final String[] facsimiles = {"00.03"};
+        for (final Telephone tel : tels) {
+            assertArrayEquals("getVoices",     voices,     tel.getVoices()    .toArray());
+            assertArrayEquals("getFacsimiles", facsimiles, tel.getFacsimiles().toArray());
+        }
+    }
+
+    /**
+     * Tests the ISO 19115:2003 {@link DefaultContact#setPhone(Telephone)} method,
+     * then query with both the new and the deprecated methods.
+     */
+    @Test
+    @DependsOnMethod("testSetPhones")
+    public void testSetPhone() {
+        testSetPhone(false);
+    }
+
+    /**
+     * Same as {@link #testSetPhone()}, but hiding to {@link DefaultContact} the fact that we
+     * are using a SIS implementation of {@code Telephone}. This will test an other code path.
+     */
+    @Test
+    @DependsOnMethod("testSetPhones")
+    public void testSetNonSISPhone() {
+        testSetPhone(true);
+    }
+
+    /**
+     * Implementation of {@link #testSetPhone()} and {@link #testSetNonSISPhone()}.
+     *
+     * @param hideSIS Whether to hide to {@link DefaultContact} the fact that we
+     *        are using a SIS implementation of {@code Telephone}.
+     */
+    @SuppressWarnings("deprecation")
+    private void testSetPhone(final boolean hideSIS) {
+        init();
+        final DefaultTelephone tel = new DefaultTelephone();
+        tel.setVoices(Arrays.asList("00.02", "00.04"));
+        tel.setFacsimiles(Arrays.asList("00.03"));
+        final Telephone view;
+        if (hideSIS) {
+            view = new Telephone() {
+                @Override public String             getNumber()     {return tel.getNumber();}
+                @Override public TelephoneType      getNumberType() {return tel.getNumberType();}
+                @Override public Collection<String> getVoices()     {return tel.getVoices();}
+                @Override public Collection<String> getFacsimiles() {return tel.getFacsimiles();}
+            };
+        } else {
+            view = tel;
+        }
+        verifyLegacyLists(tel);
+        /*
+         * Give the telephone to a contact, and verify that new telephone instances were created.
+         */
+        final DefaultContact contact = new DefaultContact();
+        contact.setPhone(view);
+        verifyLegacyLists(view);
+        assertArrayEquals("getPhones", new DefaultTelephone[] {
+                new DefaultTelephone("00.02", TelephoneType.VOICE),
+                new DefaultTelephone("00.04", TelephoneType.VOICE),
+                new DefaultTelephone("00.03", TelephoneType.FACSIMILE)
+            }, contact.getPhones().toArray());
+    }
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/citation/DefaultContactTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -60,6 +60,7 @@ import org.junit.BeforeClass;
     org.apache.sis.xml.XLinkMarshallingTest.class,
 
     // ISO implementations.
+    org.apache.sis.metadata.iso.citation.DefaultContactTest.class,
     org.apache.sis.metadata.iso.citation.DefaultCitationDateTest.class,
     org.apache.sis.metadata.iso.citation.DefaultCitationTest.class,
     org.apache.sis.metadata.iso.maintenance.DefaultScopeDescriptionTest.class,

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -51,7 +51,7 @@ import java.util.function.Function;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3 (derived from geotk-3.00)
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public final class CollectionsExt extends Static {
@@ -616,4 +616,21 @@ public final class CollectionsExt extend
         }
         return map;
     }
+
+    /**
+     * Returns {@code true} if the next elements returned by the given iterators are the same.
+     * This method compares using the identity operation ({@code ==}), not {@code equals(Object)}.
+     *
+     * @param  it1 The first iterator.
+     * @param  it2 The second iterator.
+     * @return If both iterators return the same objects.
+     */
+    public static boolean identityEquals(final Iterator<?> it1, final Iterator<?> it2) {
+        while (it1.hasNext()) {
+            if (!it2.hasNext() || it1.next() != it2.next()) {
+                return false;
+            }
+        }
+        return !it2.hasNext();
+    }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -76,6 +76,11 @@ public final class Messages extends Inde
         public static final short IgnoredPropertiesAfterFirst_1 = 6;
 
         /**
+         * Ignored property associated to ‘{0}’.
+         */
+        public static final short IgnoredPropertyAssociatedTo_1 = 7;
+
+        /**
          * Text were discarded for some locales.
          */
         public static final short LocalesDiscarded = 3;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties [ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties [ISO-8859-1] Fri Jul 11 22:06:55 2014
@@ -18,6 +18,7 @@ AlreadyRegistered_2             = {0} \u
 ChangedContainerCapacity_2      = Changed the container capacity from {0} to {1} elements.
 DiscardedExclusiveProperty_2    = Property \u201c{0}\u201d has been discarded in favor of \u201c{1}\u201d, because those two properties are mutually exclusive.
 IgnoredPropertiesAfterFirst_1   = Ignored properties after the first occurrence of \u2018{0}\u2019.
+IgnoredPropertyAssociatedTo_1   = Ignored property associated to \u2018{0}\u2019.
 PropertyHiddenBy_2              = Property \u201c{0}\u201d is hidden by \u201c{1}\u201d.
 LocalesDiscarded                = Text were discarded for some locales.
 UnparsableValueStoredAsText_2   = Can not parse \u201c{1}\u201d as an instance of \u2018{0}\u2019. The value is stored as plain text instead, but will be ignored by some processing.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties [ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties [ISO-8859-1] Fri Jul 11 22:06:55 2014
@@ -18,6 +18,7 @@ AlreadyRegistered_2             = Le {0}
 ChangedContainerCapacity_2      = Changement de la capacit\u00e9 du conteneur de {0} vers {1} \u00e9l\u00e9ments.
 DiscardedExclusiveProperty_2    = La propri\u00e9t\u00e9 \u00ab\u202f{0}\u202f\u00bb a \u00e9t\u00e9 \u00e9cart\u00e9e en faveur de \u00ab\u202f{1}\u202f\u00bb, parce que ces deux propri\u00e9t\u00e9s sont mutuellement exclusives.
 IgnoredPropertiesAfterFirst_1   = Des propri\u00e9t\u00e9s ont \u00e9t\u00e9 ignor\u00e9es apr\u00e8s la premi\u00e8re occurrence de \u2018{0}\u2019.
+IgnoredPropertyAssociatedTo_1   = Une propri\u00e9t\u00e9 associ\u00e9e \u00e0 \u2018{0}\u2019 a \u00e9t\u00e9 ignor\u00e9e.
 PropertyHiddenBy_2              = La propri\u00e9t\u00e9 \u00ab\u202f{0}\u202f\u00bb est masqu\u00e9e par \u00ab\u202f{1}\u202f\u00bb.
 LocalesDiscarded                = Des textes ont \u00e9t\u00e9 ignor\u00e9s pour certaines langues.
 UnparsableValueStoredAsText_2   = La valeur \u00ab\u202f{1}\u202f\u00bb ne peut pas \u00eatre interpr\u00e9t\u00e9e comme une instance de \u2018{0}\u2019. Elle est donc m\u00e9moris\u00e9e sous sa forme textuelle, mais sera ignor\u00e9e par certains traitements.

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -26,6 +26,7 @@ import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.Locale;
 import org.apache.sis.util.collection.CodeListSet;
 import org.apache.sis.util.ObjectConverters;
@@ -43,7 +44,7 @@ import java.util.function.Function;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public final strictfp class CollectionsExtTest extends TestCase {
@@ -140,4 +141,16 @@ public final strictfp class CollectionsE
             assertMapEquals(expected, CollectionsExt.toCaseInsensitiveNameMap(elements, nameFunction, Locale.ROOT));
         }
     }
+
+    /**
+     * Tests {@link CollectionsExt#identityEquals(Iterator, Iterator)}.
+     */
+    @Test
+    public void testIdentityEquals() {
+        final List<String> c1 = Arrays.asList("A", "B", "C");
+        final List<String> c2 = Arrays.asList("A", "B");
+        assertFalse(CollectionsExt.identityEquals(c1.iterator(), c2.iterator()));
+        assertFalse(CollectionsExt.identityEquals(c2.iterator(), c1.iterator()));
+        assertTrue(CollectionsExt.identityEquals(c1.iterator(), Arrays.asList("A", "B", "C").iterator()));
+    }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java?rev=1609852&r1=1609851&r2=1609852&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java [UTF-8] Fri Jul 11 22:06:55 2014
@@ -16,10 +16,8 @@
  */
 package org.apache.sis.util.iso;
 
-import java.util.Set;
 import java.util.Map;
 import java.util.Arrays;
-import java.util.HashSet;
 import java.util.HashMap;
 import java.util.TreeMap;
 import java.util.Locale;
@@ -51,8 +49,8 @@ public final strictfp class TypesTest ex
      */
     @Test
     public void testToInternationalString() {
-        testToInternationalString(new HashMap<String,Object>());
-        testToInternationalString(new TreeMap<String,Object>());
+        testToInternationalString(new HashMap<>());
+        testToInternationalString(new TreeMap<>());
     }
 
     /**
@@ -211,10 +209,9 @@ public final strictfp class TypesTest ex
      */
     @Test
     public void testGetCodeValues() {
-        final Set<OnLineFunction> expected = new HashSet<>(Arrays.asList(
-                OnLineFunction.INFORMATION, OnLineFunction.SEARCH, OnLineFunction.ORDER,
-                OnLineFunction.DOWNLOAD, OnLineFunction.OFFLINE_ACCESS));
         final OnLineFunction[] actual = Types.getCodeValues(OnLineFunction.class);
-        assertTrue(expected.containsAll(Arrays.asList(actual)));
+        assertTrue(Arrays.asList(actual).containsAll(Arrays.asList(
+                OnLineFunction.INFORMATION, OnLineFunction.SEARCH, OnLineFunction.ORDER,
+                OnLineFunction.DOWNLOAD, OnLineFunction.OFFLINE_ACCESS)));
     }
 }



Mime
View raw message