sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1786884 - in /sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer: AbstractLocation.java LocationFormat.java ModifiableLocationTypeAdapter.java ReferencingByIdentifiers.java
Date Tue, 14 Mar 2017 11:42:02 GMT
Author: desruisseaux
Date: Tue Mar 14 11:42:02 2017
New Revision: 1786884

URL: http://svn.apache.org/viewvc?rev=1786884&view=rev
Log:
Remove reference to AbstractLocationType from public API. We copy to ModifiableLocationType
as a workaround for now.

Added:
    sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationTypeAdapter.java
  (with props)
Modified:
    sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
    sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationFormat.java
    sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java

Modified: sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java?rev=1786884&r1=1786883&r2=1786884&view=diff
==============================================================================
--- sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
[UTF-8] (original)
+++ sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
[UTF-8] Tue Mar 14 11:42:02 2017
@@ -218,11 +218,21 @@ public abstract class AbstractLocation {
      * <div class="warning"><b>Upcoming API change — generalization</b><br>
      * in a future SIS version, the type of returned element may be generalized to the
      * {@code org.opengis.referencing.gazetteer.Location} interface.
-     * This change is pending GeoAPI revision.</div>
+     * This change is pending GeoAPI revision.
+     * If applied, this method will be made non-final.</div>
      *
      * @return the nature of the identifier and its associated geographic location.
      */
-    public AbstractLocationType getLocationType() {
+    public final ModifiableLocationType getLocationType() {
+        return ModifiableLocationTypeAdapter.copy(type);
+    }
+
+    /**
+     * Workaround for the lack of {@code LocationType} interface in GeoAPI 3.0.
+     * This workaround will be removed in a future SIS version if the location
+     * type interface is introduced in a future GeoAPI version.
+     */
+    final AbstractLocationType type() {
         return type;
     }
 
@@ -241,7 +251,6 @@ public abstract class AbstractLocation {
      * @see ReferencingByIdentifiers#getOverallOwner()
      */
     public AbstractParty getAdministrator() {
-        final AbstractLocationType type = getLocationType();
         return (type != null) ? type.getOwner() : null;
     }
 

Modified: sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationFormat.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationFormat.java?rev=1786884&r1=1786883&r2=1786884&view=diff
==============================================================================
--- sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationFormat.java
[UTF-8] (original)
+++ sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/LocationFormat.java
[UTF-8] Tue Mar 14 11:42:02 2017
@@ -219,7 +219,7 @@ public class LocationFormat extends Tabu
          * Location type.
          */
         table.appendHorizontalSeparator();
-        final AbstractLocationType type = location.getLocationType();
+        final AbstractLocationType type = location.type();
         if (type != null) {
             append(table, vocabulary, Vocabulary.Keys.LocationType, toString(type.getName(),
locale));
         }

Added: sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationTypeAdapter.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationTypeAdapter.java?rev=1786884&view=auto
==============================================================================
--- sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationTypeAdapter.java
(added)
+++ sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationTypeAdapter.java
[UTF-8] Tue Mar 14 11:42:02 2017
@@ -0,0 +1,101 @@
+/*
+ * 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.List;
+import java.util.Map;
+import java.util.IdentityHashMap;
+import org.opengis.util.InternationalString;
+import org.apache.sis.internal.util.UnmodifiableArrayList;
+
+
+/**
+ * Workaround for the lack of {@code LocationType} interface in GeoAPI 3.0.
+ * This workaround will be removed if a future GeoAPI version publish that interface,
+ * or if {@link AbstractLocationType} is made public.
+ */
+final class ModifiableLocationTypeAdapter extends ModifiableLocationType {
+    /**
+     * The reference system of the original type.
+     * This is the only information not stored in {@link ModifiableLocationType}.
+     */
+    private final ReferencingByIdentifiers referenceSystem;
+
+    /**
+     * Copies all information from the given type.
+     */
+    private ModifiableLocationTypeAdapter(final AbstractLocationType type,
+            final Map<AbstractLocationType,ModifiableLocationTypeAdapter> previous)
+    {
+        super(type.getName());
+        setTheme(type.getTheme());
+        setDefinition(type.getDefinition());
+        setTerritoryOfUse(type.getTerritoryOfUse());
+        setOwner(type.getOwner());
+        for (final InternationalString s : type.getIdentifications()) {
+            addIdentification(s);
+        }
+        referenceSystem = type.getReferenceSystem();
+        for (final AbstractLocationType c : type.getChildren()) {
+            ModifiableLocationTypeAdapter p = previous.get(c);
+            if (p == null) {
+                p = new ModifiableLocationTypeAdapter(c, previous);
+                previous.put(c, p);
+            }
+            p.addParent(this);
+        }
+    }
+
+    /**
+     * Returns type type as-is if it is already an instance of {@code ModifiableLocationType},
+     * or returns a copy otherwise.
+     */
+    static ModifiableLocationType copy(final AbstractLocationType type) {
+        if (type instanceof ModifiableLocationType) {
+            return (ModifiableLocationType) type;
+        } else {
+            return new ModifiableLocationTypeAdapter(type,
+                    new IdentityHashMap<AbstractLocationType,ModifiableLocationTypeAdapter>());
+        }
+    }
+
+    /**
+     * Copies a list of location types.
+     */
+    static List<ModifiableLocationType> copy(final List<? extends AbstractLocationType>
types) {
+        final Map<AbstractLocationType,ModifiableLocationTypeAdapter> previous = new
IdentityHashMap<>();
+        final ModifiableLocationType[] nt = new ModifiableLocationType[types.size()];
+        for (int i=0; i<nt.length; i++) {
+            final AbstractLocationType c = types.get(i);
+            ModifiableLocationTypeAdapter p = previous.get(c);
+            if (p == null) {
+                p = new ModifiableLocationTypeAdapter(c, previous);
+                previous.put(c, p);
+            }
+            nt[i] = p;
+        }
+        return UnmodifiableArrayList.wrap(nt);
+    }
+
+    /**
+     * Returns the reference system of the type given to the constructor.
+     */
+    @Override
+    public ReferencingByIdentifiers getReferenceSystem() {
+        return referenceSystem;
+    }
+}

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

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

Modified: sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java?rev=1786884&r1=1786883&r2=1786884&view=diff
==============================================================================
--- sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
[UTF-8] (original)
+++ sis/trunk/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
[UTF-8] Tue Mar 14 11:42:02 2017
@@ -226,8 +226,8 @@ public class ReferencingByIdentifiers ex
      * @see ModifiableLocationType#getReferenceSystem()
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")         // Because the collection
is unmodifiable.
-    public List<? extends AbstractLocationType> getLocationTypes() {
-        return locationTypes;
+    public List<? extends ModifiableLocationType> getLocationTypes() {
+        return ModifiableLocationTypeAdapter.copy(locationTypes);
     }
 
     /**



Mime
View raw message