sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1784307 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/
Date Fri, 24 Feb 2017 17:44:46 GMT
Author: desruisseaux
Date: Fri Feb 24 17:44:45 2017
New Revision: 1784307

URL: http://svn.apache.org/viewvc?rev=1784307&view=rev
Log:
Initial implementation of ISO 19112 LocationType.

Added:
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/DefaultLocationType.java
  (with props)
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationTypeTemplate.java
  (with props)
Modified:
    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/UnmodifiableMetadataException.java
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java

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=1784307&r1=1784306&r2=1784307&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 Feb 24 17:44:45 2017
@@ -232,9 +232,8 @@ public abstract class ModifiableMetadata
     }
 
     /**
-     * Checks if changes in the metadata are allowed. All {@code setFoo(...)} methods in
-     * subclasses should invoke this method (directly or indirectly) before to apply any
-     * 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.
      *
      * @throws UnmodifiableMetadataException if this metadata is unmodifiable.
      *

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/UnmodifiableMetadataException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/UnmodifiableMetadataException.java?rev=1784307&r1=1784306&r2=1784307&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/UnmodifiableMetadataException.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/UnmodifiableMetadataException.java
[UTF-8] Fri Feb 24 17:44:45 2017
@@ -22,8 +22,8 @@ package org.apache.sis.metadata;
  * This exception may happen in the following scenarios:
  *
  * <ul>
- *   <li>A metadata instance was initially {@linkplain org.apache.sis.metadata.ModifiableMetadata
- *       modifiable}, but that instance has since be declared unmodifiable.</li>
+ *   <li>A metadata instance was initially {@linkplain org.apache.sis.metadata.ModifiableMetadata
modifiable},
+ *       but that instance has since be declared unmodifiable.</li>
  *   <li>A write operation has been attempted on the {@linkplain AbstractMetadata#asMap()
map view},
  *       but the metadata object has no corresponding setter methods.</li>
  * </ul>

Added: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/DefaultLocationType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/DefaultLocationType.java?rev=1784307&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/DefaultLocationType.java
(added)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/DefaultLocationType.java
[UTF-8] Fri Feb 24 17:44:45 2017
@@ -0,0 +1,278 @@
+/*
+ * 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.referencing.gazetteer;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Collection;
+import java.util.Collections;
+import org.opengis.util.InternationalString;
+import org.opengis.metadata.citation.Party;
+import org.opengis.metadata.extent.GeographicExtent;
+import org.opengis.referencing.gazetteer.LocationType;
+import org.opengis.referencing.gazetteer.ReferenceSystemUsingIdentifiers;
+import org.apache.sis.internal.util.UnmodifiableArrayList;
+import org.apache.sis.metadata.ModifiableMetadata;
+import org.apache.sis.util.ArgumentChecks;
+
+
+/**
+ * Unmodifiable description of a location.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+final class DefaultLocationType implements LocationType {
+    /**
+     * Name of the location type.
+     */
+    private final InternationalString name;
+
+    /**
+     * Property used as the defining characteristic of the location type.
+     */
+    private final InternationalString theme;
+
+    /**
+     * Method(s) of uniquely identifying location instances.
+     */
+    private final List<InternationalString> identifications;
+
+    /**
+     * The way in which location instances are defined.
+     */
+    private final InternationalString definition;
+
+    /**
+     * The reference system that comprises this location type.
+     */
+    private final ReferenceSystemUsingIdentifiers referenceSystem;
+
+    /**
+     * Geographic area within which the location type occurs.
+     */
+    private final GeographicExtent territoryOfUse;
+
+    /**
+     * Name of organization or class of organization able to create and destroy location
instances.
+     */
+    private final Party owner;
+
+    /**
+     * Parent location types (location types of which this location type is a sub-division).
+     */
+    private final List<LocationType> parents;
+
+    /**
+     * Child location types (location types which sub-divides this location type).
+     */
+    private final List<LocationType> children;
+
+    /**
+     * Creates a copy of the given location type with the reference system set to the given
value.
+     *
+     * @param source    the location type to use as a template.
+     * @param rs        the reference system that comprises this location type.
+     * @param existing  other {@code DefaultLocationType} instances created before this one.
+     */
+    @SuppressWarnings("ThisEscapedInObjectConstruction")
+    private DefaultLocationType(final LocationType source, final ReferenceSystemUsingIdentifiers
rs,
+            final Map<LocationType, DefaultLocationType> existing)
+    {
+        /*
+         * Put 'this' in the map at the beginning in case the parents and children contain
cyclic references.
+         * Cyclic references are not allowed if the source are LocationTypeTemplate, but
the user could have
+         * given its own implementation. Having the 'this' reference escaped in object construction
should not
+         * be an issue here because this is a private constructor, and we use it in such
a way that if an
+         * exception is thrown, the whole tree (with all 'this' references) will be discarded.
+         */
+        existing.put(source, this);
+        name            = source.getName();
+        theme           = source.getTheme();
+        identifications = snapshot(source.getIdentifications());
+        definition      = source.getDefinition();
+        territoryOfUse  = (GeographicExtent) unmodifiable(source.getTerritoryOfUse());
+        owner           = (Party) unmodifiable(source.getOwner());
+        parents         = snapshot(source.getParents(),  rs, existing);
+        children        = snapshot(source.getChildren(), rs, existing);
+        referenceSystem = rs;
+    }
+
+    /**
+     * Copies the content of the given collection.
+     *
+     * @param rs        the reference system to assign to the new location types.
+     * @param existing  an initially empty identity hash map for internal usage by this method.
+     */
+    static List<LocationType> snapshot(final Collection<? extends LocationType>
types,
+            final ReferenceSystemUsingIdentifiers rs, final Map<LocationType, DefaultLocationType>
existing)
+    {
+        final LocationType[] array = types.toArray(new LocationType[types.size()]);
+        for (int i=0; i < array.length; i++) {
+            final LocationType source = array[i];
+            ArgumentChecks.ensureNonNullElement("types", i, source);
+            DefaultLocationType copy = existing.get(source);
+            if (copy == null) {
+                copy = new DefaultLocationType(source, rs, existing);
+            }
+            array[i] = copy;
+        }
+        switch (array.length) {
+            case 0:  return Collections.emptyList();
+            case 1:  return Collections.singletonList(array[0]);
+            default: return UnmodifiableArrayList.wrap(array);
+        }
+    }
+
+    /**
+     * Returns the given collection as an unmodifiable list.
+     */
+    @SuppressWarnings("unchecked")
+    private static List<InternationalString> snapshot(final Collection<? extends
InternationalString> c) {
+        if (c instanceof UnmodifiableArrayList<?>) {
+            return (List<InternationalString>) c;
+        } else {
+            return UnmodifiableArrayList.wrap(c.toArray(new InternationalString[c.size()]));
+        }
+    }
+
+    /**
+     * Returns an unmodifiable copy of the given metadata, if necessary and possible.
+     */
+    private static Object unmodifiable(final Object metadata) {
+        if (metadata instanceof ModifiableMetadata) {
+            return ((ModifiableMetadata) metadata).unmodifiable();
+        } else {
+            return metadata;
+        }
+    }
+
+    /**
+     * Returns the name of the location type.
+     *
+     * <div class="note"><b>Examples:</b>
+     * “administrative area”, “town”, “locality”, “street”, “property”.</div>
+     *
+     * @return name of the location type.
+     */
+    @Override
+    public InternationalString getName() {
+        return name;
+    }
+
+    /**
+     * Returns the property used as the defining characteristic of the location type.
+     *
+     * <div class="note"><b>Examples:</b>
+     * <cite>“local administration”</cite> for administrative areas,
+     * <cite>“built environment”</cite> for towns or properties,
+     * <cite>“access”</cite> for streets,
+     * <cite>“electoral”</cite>,
+     * <cite>“postal”</cite>.</div>
+     *
+     * @return property used as the defining characteristic of the location type.
+     *
+     * @see ReferenceSystemUsingIdentifiers#getTheme()
+     */
+    @Override
+    public InternationalString getTheme() {
+        return theme;
+    }
+
+    /**
+     * Returns the method(s) of uniquely identifying location instances.
+     *
+     * <div class="note"><b>Examples:</b>
+     * “name”, “code”, “unique street reference number”, “geographic address”.</div>
+     *
+     * @return method(s) of uniquely identifying location instances.
+     */
+    @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")         // Because unmodifiable
+    public Collection<InternationalString> getIdentifications() {
+        return identifications;
+    }
+
+    /**
+     * Returns the way in which location instances are defined.
+     *
+     * @return the way in which location instances are defined.
+     */
+    @Override
+    public InternationalString getDefinition() {
+        return definition;
+    }
+
+    /**
+     * Returns the geographic area within which the location type occurs.
+     *
+     * <div class="note"><b>Examples:</b>
+     * the geographic domain for a location type “rivers” might be “North America”.</div>
+     *
+     * @return geographic area within which the location type occurs.
+     */
+    @Override
+    public GeographicExtent getTerritoryOfUse() {
+        return territoryOfUse;
+    }
+
+    /**
+     * Returns the reference system that comprises this location type.
+     *
+     * @return the reference system that comprises this location type.
+     */
+    @Override
+    public ReferenceSystemUsingIdentifiers getReferenceSystem() {
+        return referenceSystem;
+    }
+
+    /**
+     * Returns the name of organization or class of organization able to create and destroy
location instances.
+     *
+     * @return organization or class of organization able to create and destroy location
instances.
+     */
+    @Override
+    public Party getOwner() {
+        return owner;
+    }
+
+    /**
+     * Returns the parent location types (location types of which this location type is a
sub-division).
+     * A location type can have more than one possible parent. For example the parent of
a location type named
+     * <cite>“street”</cite> could be <cite>“locality”</cite>,
<cite>“town”</cite> or <cite>“administrative area”</cite>.
+     *
+     * @return parent location types, or an empty collection if none.
+     */
+    @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")         // Because unmodifiable
+    public Collection<LocationType> getParents() {
+        return parents;
+    }
+
+    /**
+     * Returns the child location types (location types which sub-divides this location type).
+     *
+     * @return child location types, or an empty collection if none.
+     */
+    @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")         // Because unmodifiable
+    public Collection<LocationType> getChildren() {
+        return children;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/DefaultLocationType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/DefaultLocationType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationTypeTemplate.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationTypeTemplate.java?rev=1784307&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationTypeTemplate.java
(added)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationTypeTemplate.java
[UTF-8] Fri Feb 24 17:44:45 2017
@@ -0,0 +1,250 @@
+/*
+ * 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.referencing.gazetteer;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import org.opengis.util.InternationalString;
+import org.opengis.metadata.citation.Party;
+import org.opengis.metadata.extent.GeographicExtent;
+import org.opengis.referencing.gazetteer.LocationType;
+import org.opengis.referencing.gazetteer.ReferenceSystemUsingIdentifiers;
+import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.iso.Types;
+
+
+/**
+ * Description of a location to be used as a template in reference system construction.
+ * This object can be used as a {@link LocationType} builder.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+public class LocationTypeTemplate implements LocationType {
+    /**
+     * Name of the location type.
+     */
+    private final InternationalString name;
+
+    /**
+     * Property used as the defining characteristic of the location type.
+     */
+    private InternationalString theme;
+
+    /**
+     * Method(s) of uniquely identifying location instances.
+     */
+    private final List<InternationalString> identifications;
+
+    /**
+     * The way in which location instances are defined.
+     */
+    private InternationalString definition;
+
+    /**
+     * Geographic area within which the location type occurs.
+     */
+    private GeographicExtent territoryOfUse;
+
+    /**
+     * Name of organization or class of organization able to create and destroy location
instances.
+     */
+    private Party owner;
+
+    /**
+     * Parent location types (location types of which this location type is a sub-division).
+     */
+    private final Map<String, LocationTypeTemplate> parents;
+
+    /**
+     * Child location types (location types which sub-divides this location type).
+     */
+    private final Map<String, LocationTypeTemplate> children;
+
+    /**
+     * Creates a new location type of the given name.
+     *
+     * @param name the location type name.
+     */
+    public LocationTypeTemplate(final CharSequence name) {
+        ArgumentChecks.ensureNonNull("name", name);
+        this.name       = Types.toInternationalString(name);
+        identifications = new ArrayList<>();
+        parents         = new LinkedHashMap<>();
+        children        = new LinkedHashMap<>();
+    }
+
+    /**
+     * Returns the name of the location type.
+     * This name is specified at construction time and can not be changed.
+     *
+     * <div class="note"><b>Examples:</b>
+     * “administrative area”, “town”, “locality”, “street”, “property”.</div>
+     *
+     * @return name of the location type.
+     */
+    @Override
+    public InternationalString getName() {
+        return name;
+    }
+
+    /**
+     * Returns the property used as the defining characteristic of the location type.
+     *
+     * <div class="note"><b>Examples:</b>
+     * <cite>“local administration”</cite> for administrative areas,
+     * <cite>“built environment”</cite> for towns or properties,
+     * <cite>“access”</cite> for streets,
+     * <cite>“electoral”</cite>,
+     * <cite>“postal”</cite>.</div>
+     *
+     * @return property used as the defining characteristic of the location type.
+     *
+     * @see ReferenceSystemUsingIdentifiers#getTheme()
+     */
+    @Override
+    public InternationalString getTheme() {
+        return theme;
+    }
+
+    /**
+     * Sets the property used as the defining characteristic of the location type.
+     *
+     * @param  value  the new theme.
+     */
+    public void setTheme(final CharSequence value) {
+        theme = Types.toInternationalString(value);
+    }
+
+    /**
+     * Returns the method(s) of uniquely identifying location instances.
+     *
+     * <div class="note"><b>Examples:</b>
+     * “name”, “code”, “unique street reference number”, “geographic address”.</div>
+     *
+     * The list returned by this method is <cite>live</cite>; changes in that
list
+     * will be reflected immediately in this {@code LocationTypeTemplate} and conversely.
+     *
+     * @return method(s) of uniquely identifying location instances.
+     */
+    @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
+    public List<InternationalString> getIdentifications() {
+        return identifications;
+    }
+
+    /**
+     * Returns the way in which location instances are defined.
+     *
+     * @return the way in which location instances are defined.
+     */
+    @Override
+    public InternationalString getDefinition() {
+        return definition;
+    }
+
+    /**
+     * Sets the way in which location instances are defined.
+     *
+     * @param  value  the new identification.
+     */
+    public void setDefinition(final InternationalString value) {
+        definition = value;
+    }
+
+    /**
+     * Returns the geographic area within which the location type occurs.
+     *
+     * <div class="note"><b>Examples:</b>
+     * the geographic domain for a location type “rivers” might be “North America”.</div>
+     *
+     * @return geographic area within which the location type occurs.
+     */
+    @Override
+    public GeographicExtent getTerritoryOfUse() {
+        return territoryOfUse;
+    }
+
+    /**
+     * Sets the geographic area within which the location type occurs.
+     *
+     * @param  value  the new geographic extent.
+     */
+    public void setTerritoryOfUse(final GeographicExtent value) {
+        territoryOfUse = value;
+    }
+
+    /**
+     * Returns the reference system that comprises this location type.
+     * For a {@code LocationTypeTemplate}, the reference system is always null.
+     * The reference system is set when the template is given to {@link ReferencingByIdentifiers}
constructor.
+     *
+     * @return {@code null}.
+     */
+    @Override
+    public ReferenceSystemUsingIdentifiers getReferenceSystem() {
+        return null;
+    }
+
+    /**
+     * Returns the name of organization or class of organization able to create and destroy
location instances.
+     *
+     * @return organization or class of organization able to create and destroy location
instances.
+     */
+    @Override
+    public Party getOwner() {
+        return owner;
+    }
+
+    /**
+     * Sets the organization or class of organization able to create and destroy location
instances.
+     *
+     * @param  value  the new owner.
+     */
+    public void setOwner(final Party value) {
+        owner = value;
+    }
+
+    /**
+     * Returns the parent location types (location types of which this location type is a
sub-division).
+     * A location type can have more than one possible parent. For example the parent of
a location type named
+     * <cite>“street”</cite> could be <cite>“locality”</cite>,
<cite>“town”</cite> or <cite>“administrative area”</cite>.
+     *
+     * @return parent location types, or an empty collection if none.
+     */
+    @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
+    public Collection<LocationTypeTemplate> getParents() {
+        return parents.values();
+    }
+
+    /**
+     * Returns the child location types (location types which sub-divides this location type).
+     *
+     * @return child location types, or an empty collection if none.
+     */
+    @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
+    public Collection<LocationTypeTemplate> getChildren() {
+        return children.values();
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationTypeTemplate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationTypeTemplate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java?rev=1784307&r1=1784306&r2=1784307&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
[UTF-8] Fri Feb 24 17:44:45 2017
@@ -16,8 +16,10 @@
  */
 package org.apache.sis.referencing.gazetteer;
 
+import java.util.Arrays;
 import java.util.Map;
 import java.util.Collection;
+import java.util.IdentityHashMap;
 import java.util.Objects;
 import javax.xml.bind.annotation.XmlTransient;
 import org.opengis.util.InternationalString;
@@ -27,6 +29,7 @@ import org.opengis.referencing.gazetteer
 import org.apache.sis.referencing.AbstractReferenceSystem;
 import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.iso.Types;
 
@@ -55,15 +58,27 @@ public abstract class ReferencingByIdent
 
     /**
      * Property used to characterize the spatial reference system.
+     *
+     * @see #getTheme()
      */
     private final InternationalString theme;
 
     /**
      * Authority with overall responsibility for the spatial reference system.
+     *
+     * @see #getOverallOwner()
      */
     private final Party overallOwner;
 
     /**
+     * Description of location type(s) in the spatial reference system.
+     * This collection shall be unmodifiable.
+     *
+     * @see #getLocationTypes()
+     */
+    private final Collection<LocationType> locationTypes;
+
+    /**
      * Creates a reference system from the given properties.
      * The properties given in argument follow the same rules than for the
      * {@linkplain AbstractReferenceSystem#AbstractReferenceSystem(Map) super-class constructor}.
@@ -122,11 +137,20 @@ public abstract class ReferencingByIdent
      * </table>
      *
      * @param properties  the properties to be given to the coordinate reference system.
+     * @param types       description of location type(s) in the spatial reference system.
      */
-    public ReferencingByIdentifiers(final Map<String,?> properties) {
+    @SuppressWarnings("ThisEscapedInObjectConstruction")
+    public ReferencingByIdentifiers(final Map<String,?> properties, final LocationType...
types) {
         super(properties);
         theme = Types.toInternationalString(properties, THEME_KEY);
         overallOwner = Containers.property(properties, OVERALL_OWNER_KEY, Party.class);
+        ArgumentChecks.ensureNonNull("types", types);
+        /*
+         * Having the 'this' reference escaped in object construction should not be an issue
here because
+         * we invoke package-private method in such a way that if an exception is thrown,
the whole tree
+         * (with all 'this' references) will be discarded.
+         */
+        locationTypes = DefaultLocationType.snapshot(Arrays.asList(types), this, new IdentityHashMap<>());
     }
 
     /**
@@ -162,11 +186,15 @@ public abstract class ReferencingByIdent
 
     /**
      * Description of location type(s) in the spatial reference system.
+     * The collection returned by this method is unmodifiable.
      *
      * @return description of location type(s) in the spatial reference system.
      */
     @Override
-    public abstract Collection<LocationType> getLocationType();
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")         // Because the collection
is unmodifiable.
+    public Collection<LocationType> getLocationTypes() {
+        return locationTypes;
+    }
 
     /**
      * Compares this reference system with the specified object for equality.



Mime
View raw message