Author: desruisseaux
Date: Tue Oct 20 14:15:51 2015
New Revision: 1709603

URL: http://svn.apache.org/viewvc?rev=1709603&view=rev
Log:
Added tests.

Modified:
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicSouth.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/TransverseMercator.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/internal/referencing/provider/AllProvidersTest.java

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java?rev=1709603&r1=1709602&r2=1709603&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MapProjection.java
 [UTF-8] Tue Oct 20 14:15:51 2015
@@ -55,7 +55,7 @@ import static org.opengis.metadata.Ident
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  */
 @XmlTransient
@@ -212,18 +212,30 @@ public abstract class MapProjection exte
     }
 
     /**
-     * Copies all names and identifiers, but using the given authority as the 
primary name.
-     * This is a convenience method for defining the parameters of an 
ESRI-specific projection
-     * using the EPSG parameters as template.
+     * Copies all aliases and identifiers except the ones for the given 
authority.
+     * If the given replacement is non-null, then it will be used instead of 
the
+     * first occurrence of the omitted name.
+     *
+     * <p>This method does not copy the primary name. It is caller's 
responsibility to add it first.</p>
+     *
+     * @param  source      The parameter from which to copy the names.
+     * @param  except      The authority of the name to omit. Can not be EPSG.
+     * @param  replacement The name to use instead of the omitted one, or 
{@code null} if none.
+     * @param  builder     Where to add the names.
+     * @return The given {@code builder}, for method call chaining.
+     *
+     * @since 0.7
      */
-    static ParameterBuilder addNamesAndIdentifiers(final Citation authority,
-            final ParameterDescriptor<Double> source, final ParameterBuilder 
builder)
+    static ParameterBuilder except(final ParameterDescriptor<Double> source, 
final Citation except,
+            GenericName replacement, final ParameterBuilder builder)
     {
-        builder.addName(sameNameAs(authority, 
source)).addName(source.getName());
-        for (final GenericName alias : source.getAlias()) {
-            if (((Identifier) alias).getAuthority() != authority) {
-                builder.addName(alias);
+        for (GenericName alias : source.getAlias()) {
+            if (((Identifier) alias).getAuthority() == except) {
+                if (replacement == null) continue;
+                alias = replacement;
+                replacement = null;
             }
+            builder.addName(alias);
         }
         for (final Identifier id : source.getIdentifiers()) {
             builder.addIdentifier(id);
@@ -234,6 +246,10 @@ public abstract class MapProjection exte
     /**
      * Copies all names except the EPSG one from the given parameter into the 
builder.
      * The EPSG name is presumed the first name and identifier (this is not 
verified).
+     *
+     * @param  source  The parameter from which to copy the names.
+     * @param  builder Where to add the names.
+     * @return The given {@code builder}, for method call chaining.
      */
     static ParameterBuilder exceptEPSG(final ParameterDescriptor<?> source, 
final ParameterBuilder builder) {
         for (final GenericName alias : source.getAlias()) {
@@ -243,19 +259,10 @@ public abstract class MapProjection exte
     }
 
     /**
-     * Returns the same parameter than the given one, except that the primary 
name is the ESRI name
-     * instead than the EPSG one.
-     */
-    @SuppressWarnings("unchecked")
-    static ParameterDescriptor<Double> forESRI(final 
ParameterDescriptor<Double> source, final ParameterBuilder builder) {
-        return addNamesAndIdentifiers(Citations.ESRI, source, 
builder).createBounded((MeasurementRange<Double>)
-                ((DefaultParameterDescriptor<Double>) 
source).getValueDomain(), source.getDefaultValue());
-    }
-
-    /**
      * Creates a remarks for parameters that are not formally EPSG parameter.
      *
-     * @param origin The name of the projection for where the parameter is 
formally used.
+     * @param  origin The name of the projection for where the parameter is 
formally used.
+     * @return A remarks saying that the parameter is actually defined in 
{@code origin}.
      */
     static InternationalString notFormalParameter(final String origin) {
         return 
Messages.formatInternational(Messages.Keys.NotFormalProjectionParameter_1, 
origin);

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicSouth.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicSouth.java?rev=1709603&r1=1709602&r2=1709603&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicSouth.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicSouth.java
 [UTF-8] Tue Oct 20 14:15:51 2015
@@ -22,7 +22,9 @@ import org.opengis.parameter.ParameterDe
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.parameter.ParameterBuilder;
+import org.apache.sis.parameter.DefaultParameterDescriptor;
 import org.apache.sis.measure.Latitude;
+import org.apache.sis.measure.MeasurementRange;
 
 
 /**
@@ -31,7 +33,7 @@ import org.apache.sis.measure.Latitude;
  * @author  Rueben Schulz (UBC)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  */
 @XmlTransient
@@ -42,13 +44,32 @@ public final class PolarStereographicSou
     private static final long serialVersionUID = -6173635411676914083L;
 
     /**
+     * Copies all names and identifiers, but using the ESRI authority as the 
primary name.
+     * This is a convenience method for defining the parameters of an 
ESRI-specific projection
+     * using the EPSG parameters as template.
+     */
+    private static ParameterBuilder addNamesAndIdentifiers(final 
ParameterDescriptor<Double> source, final ParameterBuilder builder) {
+        return except(source, Citations.ESRI, null, 
builder.addName(sameNameAs(Citations.ESRI, source)).addName(source.getName()));
+    }
+
+    /**
+     * Returns the same parameter than the given one, except that the primary 
name is the ESRI name
+     * instead than the EPSG one.
+     */
+    @SuppressWarnings("unchecked")
+    private static ParameterDescriptor<Double> forESRI(final 
ParameterDescriptor<Double> source, final ParameterBuilder builder) {
+        return addNamesAndIdentifiers(source, 
builder).createBounded((MeasurementRange<Double>)
+                ((DefaultParameterDescriptor<Double>) 
source).getValueDomain(), source.getDefaultValue());
+    }
+
+    /**
      * The group of all parameters expected by this coordinate operation.
      */
     static final ParameterDescriptorGroup PARAMETERS;
     static {
         final ParameterBuilder builder = builder();
         final ParameterDescriptor<?>[] parameters = {
-            addNamesAndIdentifiers(Citations.ESRI, 
PolarStereographicB.STANDARD_PARALLEL, builder)
+            addNamesAndIdentifiers(PolarStereographicB.STANDARD_PARALLEL, 
builder)
                    .createBounded(Latitude.MIN_VALUE, 0, Latitude.MIN_VALUE, 
NonSI.DEGREE_ANGLE),
 
             forESRI(PolarStereographicB.LONGITUDE_OF_ORIGIN, builder),

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/TransverseMercator.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/TransverseMercator.java?rev=1709603&r1=1709602&r2=1709603&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/TransverseMercator.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/TransverseMercator.java
 [UTF-8] Tue Oct 20 14:15:51 2015
@@ -70,8 +70,9 @@ public final class TransverseMercator ex
         LATITUDE_OF_ORIGIN = createLatitude(builder
                 .addNamesAndIdentifiers(Mercator1SP.LATITUDE_OF_ORIGIN), true);
 
-        LONGITUDE_OF_ORIGIN = 
createLongitude(builder.addNamesAndIdentifiers(Mercator1SP.LONGITUDE_OF_ORIGIN)
-                .rename(Citations.NETCDF, "longitude_of_central_meridian"));
+        builder.addName(Mercator1SP.LONGITUDE_OF_ORIGIN.getName());
+        LONGITUDE_OF_ORIGIN = 
createLongitude(except(Mercator1SP.LONGITUDE_OF_ORIGIN, Citations.NETCDF,
+                sameNameAs(Citations.NETCDF, 
LambertConformal2SP.LONGITUDE_OF_FALSE_ORIGIN), builder));
 
         SCALE_FACTOR = createScale(builder
                 .addNamesAndIdentifiers(Mercator1SP.SCALE_FACTOR)

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=1709603&r1=1709602&r2=1709603&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] Tue Oct 20 14:15:51 2015
@@ -37,7 +37,7 @@ import org.apache.sis.util.iso.Types;
 import org.apache.sis.util.Deprecable;
 import org.apache.sis.util.resources.Errors;
 
-import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.util.ArgumentChecks.*;
 
 
 /**
@@ -750,32 +750,40 @@ public abstract class Builder<B extends
         int next = 0;
         int insertAt = aliases.size();
         for (int i = -1; i < aliases.size(); i++) {
-            final Object name = (i < 0) ? 
properties.get(IdentifiedObject.NAME_KEY) : aliases.get(i);
-            if (name != null) {  // Actually only the primary name can be null.
-                final boolean isIdentifier = (name instanceof Identifier);
-                if (authority.equals(isIdentifier ? ((Identifier) 
name).getAuthority() : getAuthority())) {
-                    /*
-                     * Found a name associated to the given authority. Process 
to the replacement if we still
-                     * have some elements to take in the 'replacements' array, 
otherwise remove the name.
-                     */
-                    if (next < length) {
-                        final CharSequence code = replacements[next++];
-                        if (!code.toString().equals(isIdentifier ? 
((Identifier) name).getCode() : name.toString())) {
-                            if (i < 0) {
-                                properties.put(IdentifiedObject.NAME_KEY, 
(authority != getAuthority())
-                                        ? new NamedIdentifier(authority, code) 
: code.toString());
-                            } else {
-                                aliases.set(i, createName(authority, code));
-                            }
-                            insertAt = i + 1;
-                        }
+            final Object old = (i < 0) ? 
properties.get(IdentifiedObject.NAME_KEY) : aliases.get(i);
+            if (old == null) {
+                continue;       // Actually only the primary name can be null.
+            }
+            final boolean wasID = (old instanceof Identifier);   // Usually 
true even for aliases.
+            if (!authority.equals(wasID ? ((Identifier) old).getAuthority() : 
getAuthority())) {
+                continue;       // Current name is not for the authority we 
are looking for.
+            }
+            /*
+             * Found a name associated to the given authority. Process to the 
replacement if we still
+             * have some elements to take in the 'replacements' array, 
otherwise remove the name.
+             */
+            if (next < length) {
+                final CharSequence name;
+                ensureNonNullElement("replacements", next, name = 
replacements[next++]);
+                /*
+                 * If the current name matches the specified replacement, we 
can leave the name as-is.
+                 * Only if the name (in its local part) is not the same, 
proceed to the replacement.
+                 */
+                final String code = name.toString();
+                if (!code.equals(wasID ? ((Identifier) old).getCode() : 
old.toString())) {
+                    if (i < 0) {
+                        properties.put(IdentifiedObject.NAME_KEY,
+                                (authority != getAuthority()) ? new 
NamedIdentifier(authority, name) : code);
                     } else {
-                        if (i < 0) {
-                            properties.remove(IdentifiedObject.NAME_KEY);
-                        } else {
-                            aliases.remove(i--);
-                        }
+                        aliases.set(i, createName(authority, name));
                     }
+                    insertAt = i + 1;
+                }
+            } else {
+                if (i < 0) {
+                    properties.remove(IdentifiedObject.NAME_KEY);
+                } else {
+                    aliases.remove(i--);
                 }
             }
         }
@@ -784,7 +792,9 @@ public abstract class Builder<B extends
          * element of the given authority that we found (so we keep together 
the names of the same authority).
          */
         while (next < length) {
-            aliases.add(insertAt++, createName(authority, 
replacements[next++]));
+            final CharSequence name;
+            ensureNonNullElement("replacements", next, name = 
replacements[next++]);
+            aliases.add(insertAt++, createName(authority, name));
         }
         /*
          * If the primary name has been removed as a result of this method 
execution,

Modified: 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java?rev=1709603&r1=1709602&r2=1709603&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/AllProvidersTest.java
 [UTF-8] Tue Oct 20 14:15:51 2015
@@ -36,7 +36,7 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  */
 @DependsOn({
@@ -62,7 +62,17 @@ public final strictfp class AllProviders
             MillerCylindrical.class,
             LambertConformal1SP.class,
             LambertConformal2SP.class,
-            LambertConformalBelgium.class
+            LambertConformalWest.class,
+            LambertConformalBelgium.class,
+            LambertConformalMichigan.class,
+            TransverseMercator.class,
+            TransverseMercatorSouth.class,
+            PolarStereographicA.class,
+            PolarStereographicB.class,
+            PolarStereographicC.class,
+            PolarStereographicNorth.class,
+            PolarStereographicSouth.class,
+            ObliqueStereographic.class
         };
     }
 


Reply via email to