sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1671016 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/provider/ main/java/org/apache/sis/referencing/ test/java/org/apache/sis/referencing/
Date Fri, 03 Apr 2015 08:26:36 GMT
Author: desruisseaux
Date: Fri Apr  3 08:26:36 2015
New Revision: 1671016

URL: http://svn.apache.org/r1671016
Log:
Referencing: simplified a little bit by removing the Builder.replaceIdentifiers(...) method.
It is less likely to be used than Builder.replaceNames(...).
Also renamed "replaceNames" as "rename".

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator2SP.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java?rev=1671016&r1=1671015&r2=1671016&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator1SP.java
[UTF-8] Fri Apr  3 08:26:36 2015
@@ -93,25 +93,25 @@ public final class Mercator1SP extends M
         final ParameterBuilder builder = builder();
 
         LATITUDE_OF_ORIGIN = createConstant(builder.addNamesAndIdentifiers(Mercator2SP.LATITUDE_OF_ORIGIN)
-                .replaceNames(Citations.ESRI,    (String[]) null)
-                .replaceNames(Citations.NETCDF,  (String[]) null)
+                .rename(Citations.ESRI,   (String[]) null)
+                .rename(Citations.NETCDF, (String[]) null)
                 .setRemarks(Mercator2SP.LATITUDE_OF_ORIGIN.getRemarks()), 0.0);
 
         CENTRAL_MERIDIAN = createLongitude(builder.addNamesAndIdentifiers(Mercator2SP.CENTRAL_MERIDIAN)
-                .replaceNames(Citations.ESRI,    (String[]) null)
-                .replaceNames(Citations.NETCDF,  (String[]) null));
+                .rename(Citations.ESRI,   (String[]) null)
+                .rename(Citations.NETCDF, (String[]) null));
 
         SCALE_FACTOR = createScale(builder.addNamesAndIdentifiers(Mercator2SP.SCALE_FACTOR)
-                .replaceNames(Citations.ESRI,    (String[]) null)
-                .replaceNames(Citations.NETCDF,  (String[]) null));
+                .rename(Citations.ESRI,   (String[]) null)
+                .rename(Citations.NETCDF, (String[]) null));
 
         FALSE_EASTING = createShift(builder.addNamesAndIdentifiers(Mercator2SP.FALSE_EASTING)
-                .replaceNames(Citations.ESRI,    (String[]) null)
-                .replaceNames(Citations.NETCDF,  (String[]) null));
+                .rename(Citations.ESRI,   (String[]) null)
+                .rename(Citations.NETCDF, (String[]) null));
 
         FALSE_NORTHING = createShift(builder.addNamesAndIdentifiers(Mercator2SP.FALSE_NORTHING)
-                .replaceNames(Citations.ESRI,    (String[]) null)
-                .replaceNames(Citations.NETCDF,  (String[]) null));
+                .rename(Citations.ESRI,   (String[]) null)
+                .rename(Citations.NETCDF, (String[]) null));
 
         PARAMETERS = builder
             .addIdentifier(             "9804")                                         
         // The ellipsoidal case

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator2SP.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator2SP.java?rev=1671016&r1=1671015&r2=1671016&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator2SP.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Mercator2SP.java
[UTF-8] Fri Apr  3 08:26:36 2015
@@ -96,11 +96,11 @@ public final class Mercator2SP extends M
         final ParameterBuilder builder = builder();
 
         STANDARD_PARALLEL = createLatitude(builder.addNamesAndIdentifiers(EquidistantCylindrical.STANDARD_PARALLEL)
-                .replaceNames(Citations.GEOTIFF, "StdParallel1")
-                .replaceNames(Citations.PROJ4,   "lat_1"), false);
+                .rename(Citations.GEOTIFF, "StdParallel1")
+                .rename(Citations.PROJ4,   "lat_1"), false);
 
         CENTRAL_MERIDIAN = createLongitude(builder.addNamesAndIdentifiers(EquidistantCylindrical.CENTRAL_MERIDIAN)
-                .replaceNames(Citations.GEOTIFF, "NatOriginLong"));
+                .rename(Citations.GEOTIFF, "NatOriginLong"));
 
         /*
          * "Latitude of natural origin" and "Scale factor" are not formally parameters
@@ -109,7 +109,7 @@ public final class Mercator2SP extends M
          */
         builder.setRequired(false); // Will apply to all remaining parameters.
         LATITUDE_OF_ORIGIN = createConstant(builder.addNamesAndIdentifiers(EquidistantCylindrical.LATITUDE_OF_ORIGIN)
-                .replaceNames(Citations.GEOTIFF, "NatOriginLat")
+                .rename(Citations.GEOTIFF, "NatOriginLat")
                 .setRemarks(EquidistantCylindrical.LATITUDE_OF_ORIGIN.getRemarks()), 0.0);
 
         SCALE_FACTOR = createScale(builder

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java?rev=1671016&r1=1671015&r2=1671016&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
[UTF-8] Fri Apr  3 08:26:36 2015
@@ -670,8 +670,7 @@ public abstract class Builder<B extends
      * Other properties like description and remarks are ignored.
      *
      * <p>This is a convenience method for using an existing object as a template,
before to modify
-     * some names and identifiers by calls to {@link #replaceNames(Citation, CharSequence...)}
or
-     * {@link #replaceIdentifiers(Citation, String...)}.</p>
+     * some names by calls to {@link #rename(Citation, CharSequence[])}.</p>
      *
      * @param  object The object from which to copy the references to names and identifiers.
      * @return {@code this}, for method call chaining.
@@ -723,7 +722,7 @@ public abstract class Builder<B extends
      *
      * @since 0.6
      */
-    public B replaceNames(final Citation authority, final CharSequence... replacements) {
+    public B rename(final Citation authority, final CharSequence... replacements) {
         ensureNonNull("authority", authority);
         final int length = (replacements != null) ? replacements.length : 0;
         /*
@@ -782,58 +781,6 @@ public abstract class Builder<B extends
         }
         return self();
     }
-
-    /**
-     * Replaces the identifiers associated to the given authority by the given new identifiers.
-     * More specifically:
-     *
-     * <ul>
-     *   <li>The first occurrence of an identifier associated to {@code authority}
will be replaced by a new
-     *       identifier with the same authority and the code defined by {@code replacements[0]}.</li>
-     *   <li>The second occurrence of an identifier associated to {@code authority}
will be replaced by a new
-     *       identifier with the same authority and the code defined by {@code replacements[1]}.</li>
-     *   <li><i>etc.</i> until one of the following conditions is meet:
-     *     <ul>
-     *       <li>There is no more identifier associated to the given authority in this
{@code Builder}, in which case
-     *           new identifiers are inserted for all remaining elements in the {@code replacements}
array.</li>
-     *       <li>There is no more elements in the {@code replacements} array, in which
case all remaining
-     *           identifiers associated to the given authority in this {@code Builder} are
removed.</li>
-     *     </ul>
-     *   </li>
-     * </ul>
-     *
-     * @param  authority The authority of the names to replaces.
-     * @param  replacements The new codes for the identifiers to replace,
-     *         or {@code null} for removing all identifiers associated to the given authority.
-     * @return {@code this}, for method call chaining.
-     *
-     * @since 0.6
-     */
-    public B replaceIdentifiers(final Citation authority, final String... replacements) {
-        ensureNonNull("authority", authority);
-        final int length = (replacements != null) ? replacements.length : 0;
-        int next = 0;
-        int insertAt = identifiers.size();
-        for (int i=0; i<identifiers.size();) {
-            final Identifier identifier = identifiers.get(i);
-            if (authority.equals(identifier.getAuthority())) {
-                if (next >= length) {
-                    identifiers.remove(i);
-                    continue; // Do not increment i.
-                }
-                final String code = replacements[next++];
-                if (!code.equals(identifier.getCode())) {
-                    identifiers.set(i, createIdentifier(authority, code));
-                    insertAt = i + 1;
-                }
-            }
-            i++;
-        }
-        while (next < length) {
-            identifiers.add(insertAt++, createIdentifier(authority, replacements[next++]));
-        }
-        return self();
-    }
 
     /**
      * Sets the parameter description as a {@code String} or {@code InternationalString}
instance.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java?rev=1671016&r1=1671015&r2=1671016&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
[UTF-8] Fri Apr  3 08:26:36 2015
@@ -233,20 +233,17 @@ public final strictfp class BuilderTest
     }
 
     /**
-     * Tests {@link Builder#replaceNames(Citation, CharSequence...)}.
-     *
-     * <div class="note">This test depends on {@link #testReplaceIdentifiers()} because
-     * {@code replaceIdentifiers} implementation is simpler than {@code replaceNames}.</div>
+     * Tests {@link Builder#rename(Citation, CharSequence[])}.
      *
      * @since 0.6
      */
     @Test
-    @DependsOnMethod("testReplaceIdentifiers")  // See javadoc.
-    public void testReplaceNames() {
+    @DependsOnMethod("testAddNamesAndIdentifiers")
+    public void testRename() {
         final BuilderMock builder = createMercator(true, false);
 
         // Replace "OGC:Mercator_1SP" and insert a new OGC code before the GeoTIFF one.
-        assertSame(builder, builder.replaceNames(OGC, "Replacement 1", "Replacement 2"));
+        assertSame(builder, builder.rename(OGC, "Replacement 1", "Replacement 2"));
         builder.onCreate(false);
         assertArrayEquals(new String[] {
             "Mercator (variant A)",
@@ -257,7 +254,7 @@ public final strictfp class BuilderTest
         }, builder.getAsStrings(1));
 
         // Replace "EPSG:Mercator (variant A)" and "(1SP)", and insert a new EPSG code as
an alias.
-        assertSame(builder, builder.replaceNames(OGP, "Replacement 3", "Replacement 4", "Replacement
5"));
+        assertSame(builder, builder.rename(OGP, "Replacement 3", "Replacement 4", "Replacement
5"));
         builder.onCreate(false);
         assertArrayEquals(new String[] {
             "Replacement 3",
@@ -269,7 +266,7 @@ public final strictfp class BuilderTest
         }, builder.getAsStrings(1));
 
         // Remove all EPSG codes.
-        assertSame(builder, builder.replaceNames(OGP, (String[]) null));
+        assertSame(builder, builder.rename(OGP, (String[]) null));
         builder.onCreate(false);
         assertArrayEquals(new String[] {
             "OGC:Replacement 1",
@@ -277,42 +274,4 @@ public final strictfp class BuilderTest
             "GeoTIFF:CT_Mercator"
         }, builder.getAsStrings(1));
     }
-
-    /**
-     * Tests {@link Builder#replaceNames(Citation, CharSequence...)}.
-     *
-     * @since 0.6
-     */
-    @Test
-    @DependsOnMethod("testAddNamesAndIdentifiers")
-    public void testReplaceIdentifiers() {
-        final BuilderMock builder = createMercator(false, true);
-
-        // Replace "GeoTIFF:7" and append a new GeoTIFF code at the end of the list.
-        assertSame(builder, builder.replaceIdentifiers(GEOTIFF, "Replacement 1", "Replacement
2"));
-        builder.onCreate(false);
-        assertArrayEquals(new String[] {
-            "Id[\"EPSG\", 9804, Citation[\"OGP\"]]",
-            "Id[\"GeoTIFF\", \"Replacement 1\"]",
-            "Id[\"GeoTIFF\", \"Replacement 2\"]"
-        }, builder.getAsStrings(0));
-
-        // Replace "EPSG:9804" and insert a new EPSG code as an alias.
-        assertSame(builder, builder.replaceIdentifiers(OGP, "Replacement 3", "Replacement
4"));
-        builder.onCreate(false);
-        assertArrayEquals(new String[] {
-            "Id[\"EPSG\", \"Replacement 3\", Citation[\"OGP\"]]",
-            "Id[\"EPSG\", \"Replacement 4\", Citation[\"OGP\"]]",
-            "Id[\"GeoTIFF\", \"Replacement 1\"]",
-            "Id[\"GeoTIFF\", \"Replacement 2\"]"
-        }, builder.getAsStrings(0));
-
-        // Remove all EPSG codes.
-        assertSame(builder, builder.replaceIdentifiers(OGP, (String[]) null));
-        builder.onCreate(false);
-        assertArrayEquals(new String[] {
-            "Id[\"GeoTIFF\", \"Replacement 1\"]",
-            "Id[\"GeoTIFF\", \"Replacement 2\"]"
-        }, builder.getAsStrings(0));
-    }
 }



Mime
View raw message