sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1674932 - in /sis/branches/JDK7: ./ core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/ core/sis-referencing/src/main/java/org/apache/...
Date Mon, 20 Apr 2015 15:40:18 GMT
Author: desruisseaux
Date: Mon Apr 20 15:40:18 2015
New Revision: 1674932

URL: http://svn.apache.org/r1674932
Log:
Referencing: merge bug fixes from the JDK8 branch.

Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ParameterizedAffine.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LambertConformal2SP.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorSpherical.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PseudoMercator.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConformal.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/MapProjectionTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ContextualParametersTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/HTMLGenerator.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Apr 20 15:40:18 2015
@@ -1,4 +1,4 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1674318
+/sis/branches/JDK8:1584960-1674930
 /sis/trunk:1394364-1508466,1519089-1519674

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ParameterizedAffine.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ParameterizedAffine.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ParameterizedAffine.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ParameterizedAffine.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -21,6 +21,7 @@ import java.awt.geom.AffineTransform;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.referencing.operation.MathTransform;
+import org.apache.sis.internal.system.Semaphores;
 
 
 /**
@@ -109,12 +110,35 @@ public final class ParameterizedAffine e
     /**
      * Returns the parameter values for this map projection.
      *
+     * <p><b>Hack:</b> this method normally returns the matrix parameters
in case of doubt. However if
+     * {@link Semaphores#PROJCS} is set, then this method returns the map projection parameters
even
+     * if they are not a complete description of this math transform. This internal hack
shall be used
+     * only by {@link org.apache.sis.referencing.operation.DefaultSingleOperation}.</p>
+     *
+     * <p><b>Use case of above hack:</b> consider an "Equidistant Cylindrical
(Spherical)" map projection
+     * from a {@code GeographiCRS} base using (latitude, longitude) axis order. We need to
concatenate an
+     * affine transform performing the axis swapping before the actual map projection. The
concatenated
+     * transform is part of {@code SingleOperation}, which is itself part of {@code ProjecteCRS}.
+     * Consequently we have two conflicting needs:</p>
+     *
+     * <ul>
+     *   <li>If this method is queried from a {@code SingleOperation} instance (usually
indirectly as part of a
+     *     {@code ProjectedCRS}), then we want to return the "Equidistant Cylindrical (Spherical)"
map projection
+     *     parameters without bothering about axis swapping, because the later is described
by the {@code Axis["…"]}
+     *     elements in the enclosing {@code ProjectedCRS} instance.</li>
+     *   <li>But if this {@code MathTransform} is formatted directly (not as a component
of {@code ProjectedCRS}),
+     *     then we want to format it as a matrix, otherwise the users would have no way to
see that an axis swapping
+     *     has been applied.</li>
+     * </ul>
+     *
+     * The {@code Semaphores.PROJCS} flag is SIS internal mechanism for distinguish the two
above-cited cases.
+     *
      * @return The map projection parameters if they are an accurate description of this
transform,
      *         or the generic affine parameters in case of doubt.
      */
     @Override
     public ParameterValueGroup getParameterValues() {
-        return isDefinitive ? parameters : super.getParameterValues();
+        return isDefinitive || Semaphores.query(Semaphores.PROJCS) ? parameters : super.getParameterValues();
     }
 
     /**
@@ -131,7 +155,8 @@ public final class ParameterizedAffine e
         if (super.equals(object)) {
             if (object instanceof ParameterizedAffine) {
                 final ParameterizedAffine that = (ParameterizedAffine) object;
-                return Objects.equals(this.parameters, that.parameters);
+                return (this.isDefinitive == that.isDefinitive) &&
+                       Objects.equals(this.parameters, that.parameters);
             }
             return true;
         }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LambertConformal2SP.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LambertConformal2SP.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LambertConformal2SP.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LambertConformal2SP.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -72,17 +72,6 @@ public final class LambertConformal2SP e
     public static final ParameterDescriptor<Double> STANDARD_PARALLEL_2;
 
     /**
-     * The operation parameter descriptor for the <cite>Scale factor</cite> (not
necessarily at natural origin)
-     * parameter value. Valid values range is (0 … ∞) and default value is 1.
-     *
-     * <p>This parameter is used by {@link LambertConformal1SP} and is not formally
a parameter of
-     * {@link LambertConformal2SP} projections. Nevertheless we declare it is as an optional
parameter because
-     * it is sometime used in Well Known Text (WKT). However it shall be interpreted as a
<cite>Scale factor at
-     * the standard parallels</cite> rather than at the natural origin.</p>
-     */
-    static final ParameterDescriptor<Double> SCALE_FACTOR;
-
-    /**
      * The operation parameter descriptor for the <cite>Easting at false origin</cite>
(Ef) parameter value.
      * Valid values range is unrestricted and default value is 0 metre.
      */
@@ -149,13 +138,16 @@ public final class LambertConformal2SP e
                 .addName(Citations.GEOTIFF, "StdParallel2")
                 .addName(Citations.PROJ4,   "lat_2"));
         /*
-         * Remove the EPSG name and identifier at least for the scale factor, because its
meaning does not fit well
-         * in this context. The EPSG name is "Scale factor at natural origin" while actually
the scale factor applied
-         * here would rather be at the standard parallels.
+         * The scale factor is used by LambertConformal1SP and is not formally a parameter
of LambertConformal2SP.
+         * Nevertheless we declare it is as an optional parameter because it is sometime
used in Well Known Text,
+         * but we omit the EPSG name and identifier because its meaning does not fit well
in this context.
+         * The EPSG name is "Scale factor at natural origin" while actually the scale factor
applied here
+         * would rather be at the standard parallels.
          */
-        SCALE_FACTOR = createScale(builder
+        final ParameterDescriptor<Double> scaleFactor = createScale(builder
                 .addNamesAndIdentifiers(Mercator2SP.SCALE_FACTOR)
-                .setRemarks(notFormalParameter("Lambert Conic Conformal (1SP)")).setDeprecated(true));
+                .setRemarks(notFormalParameter("Lambert Conic Conformal (1SP)"))
+                .setRequired(false).setDeprecated(true));
 
         PARAMETERS = builder
             .addIdentifier(IDENTIFIER)
@@ -174,7 +166,7 @@ public final class LambertConformal2SP e
                     LONGITUDE_OF_FALSE_ORIGIN,
                     STANDARD_PARALLEL_1,
                     STANDARD_PARALLEL_2,
-                    SCALE_FACTOR,
+                    scaleFactor,           // Not formally a LambertConformal2SP parameter.
                     EASTING_AT_FALSE_ORIGIN,
                     NORTHING_AT_FALSE_ORIGIN);
     }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorSpherical.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorSpherical.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorSpherical.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorSpherical.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.referencing.provider;
 
+import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.apache.sis.parameter.ParameterBuilder;
 
@@ -48,6 +49,19 @@ public final class MercatorSpherical ext
     static final ParameterDescriptorGroup PARAMETERS;
     static {
         final ParameterBuilder builder = builder();
+        /*
+         * The scale factor is used by Mercator1SP and is not formally a parameter of "Mercator
(Spherical)" projection.
+         * Nevertheless we declare it as an optional parameter because it was used in EPSG:7.9:3785
(the legacy "Popular
+         * Visualisation CRS / Mercator", now deprecated). But at the difference of what
we did in Mercator2SP, we keep
+         * the EPSG name here since there is no "standard parallel" parameter.  So the "Scale
factor at natural origin"
+         * parameter name still okay provided that the "Latitude of natural origin" parameter
value stay zero (which is
+         * normally enforced by the Mercator1SP.LATITUDE_OF_ORIGIN minimum and maximum values).
+         */
+        final ParameterDescriptor<Double> scaleFactor = createScale(builder
+                .addNamesAndIdentifiers(Mercator1SP.SCALE_FACTOR)
+                .setRemarks(Mercator2SP.SCALE_FACTOR.getRemarks())
+                .setRequired(false));
+
         PARAMETERS = builder
             .addIdentifier(IDENTIFIER)
             .addDeprecatedIdentifier("9841", IDENTIFIER)
@@ -56,6 +70,7 @@ public final class MercatorSpherical ext
             .createGroupForMapProjection(
                     Mercator1SP.LATITUDE_OF_ORIGIN,
                     Mercator1SP.CENTRAL_MERIDIAN,
+                    scaleFactor,
                     FALSE_EASTING,
                     FALSE_NORTHING);
     }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PseudoMercator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PseudoMercator.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PseudoMercator.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PseudoMercator.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -44,7 +44,7 @@ public final class PseudoMercator extend
     /**
      * The group of all parameters expected by this coordinate operation.
      */
-    public static final ParameterDescriptorGroup PARAMETERS;
+    static final ParameterDescriptorGroup PARAMETERS;
     static {
         final ParameterBuilder builder = builder();
         PARAMETERS = builder

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptorGroup.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -52,7 +52,7 @@ import static org.apache.sis.util.Utilit
  *
  * {@preformat java
  *     public class Mercator {
- *         public static final ParameterDescriptorGroup PARAMETERS;
+ *         static final ParameterDescriptorGroup PARAMETERS;
  *         static {
  *             ParameterBuilder builder = new ParameterBuilder();
  *             builder.setCodeSpace(Citations.EPSG, "EPSG").setRequired(true);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConformal.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConformal.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConformal.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/LambertConformal.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -91,7 +91,6 @@ public class LambertConformal extends No
      * @param  type One of {@link #SP1}, {@link #SP2} or {@link #BELGIUM} constants.
      * @return The roles map to give to super-class constructor.
      */
-    @SuppressWarnings("fallthrough")
     private static Map<ParameterRole, ParameterDescriptor<Double>> roles(final
byte type) {
         final EnumMap<ParameterRole, ParameterDescriptor<Double>> roles = new
EnumMap<>(ParameterRole.class);
         /*

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -19,7 +19,6 @@ package org.apache.sis.referencing.opera
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Map;
-import java.util.EnumMap;
 import java.io.Serializable;
 import org.opengis.metadata.Identifier;
 import org.opengis.parameter.ParameterValue;
@@ -27,7 +26,6 @@ import org.opengis.parameter.ParameterVa
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.opengis.parameter.GeneralParameterDescriptor;
-import org.opengis.parameter.ParameterNotFoundException;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransform2D;
@@ -215,7 +213,7 @@ public abstract class NormalizedProjecti
          * <p>Unless specified otherwise, this is always mapped to a parameter named
{@code "semi_major"}.
          * {@code NormalizedProjection} subclasses typically do not need to provide a value
for this key.</p>
          */
-        SEMI_MAJOR(Constants.SEMI_MAJOR),
+        SEMI_MAJOR,
 
         /**
          * Maps the <cite>semi-minor axis length</cite> parameter (symbol: <var>b</var>).
@@ -224,7 +222,7 @@ public abstract class NormalizedProjecti
          * <p>Unless specified otherwise, this is always mapped to a parameter named
{@code "semi_minor"}.
          * {@code NormalizedProjection} subclasses typically do not need to provide a value
for this key.</p>
          */
-        SEMI_MINOR(Constants.SEMI_MINOR),
+        SEMI_MINOR,
 
         /**
          * Maps the parameter for the latitude where to compute the <cite>radius of
conformal sphere</cite>
@@ -239,7 +237,7 @@ public abstract class NormalizedProjecti
          * of the Earth may be an ellipsoid rather than a sphere. In the majority of cases,
this enumeration should
          * not be used.</p>
          */
-        LATITUDE_OF_CONFORMAL_SPHERE_RADIUS(null),
+        LATITUDE_OF_CONFORMAL_SPHERE_RADIUS,
 
         /**
          * Maps the <cite>central meridian</cite> parameter (symbol: λ₀).
@@ -254,7 +252,7 @@ public abstract class NormalizedProjecti
          *   <li>Longitude of projection centre</li>
          * </ul>
          */
-        CENTRAL_MERIDIAN(Constants.CENTRAL_MERIDIAN),
+        CENTRAL_MERIDIAN,
 
         /**
          * Maps the <cite>scale factor</cite> parameter (symbol: <var>k</var>₀).
@@ -267,7 +265,7 @@ public abstract class NormalizedProjecti
          *   <li>Scale factor on pseudo standard parallel</li>
          * </ul>
          */
-        SCALE_FACTOR(Constants.SCALE_FACTOR),
+        SCALE_FACTOR,
 
         /**
          * Maps the <cite>false easting</cite> parameter (symbol: <var>FE</var>).
@@ -280,7 +278,7 @@ public abstract class NormalizedProjecti
          *   <li>Easting at projection centre</li>
          * </ul>
          */
-        FALSE_EASTING(Constants.FALSE_EASTING),
+        FALSE_EASTING,
 
         /**
          * Maps the <cite>false northing</cite> parameter (symbol: <var>FN</var>).
@@ -293,61 +291,7 @@ public abstract class NormalizedProjecti
          *   <li>Northing at projection centre</li>
          * </ul>
          */
-        FALSE_NORTHING(Constants.FALSE_NORTHING);
-
-        /**
-         * The OGC name for this parameter. This is used only when inferring automatically
the role map.
-         * We use the OGC name instead than the EPSG name because OGC names are identical
for a wider
-         * range of projections (e.g. {@code "scale_factor"} for almost all projections).
-         */
-        private final String name;
-
-        /**
-         * Creates a new parameter role associated to the given OGC name.
-         */
-        private ParameterRole(final String name) {
-            this.name = name;
-        }
-
-        /**
-         * Provides default (<var>role</var> → <var>parameter</var>)
associations for the given map projection.
-         * This is a convenience method for a typical set of parameters found in map projections.
-         * This method expects a {@code projection} argument containing descriptors for the
given parameters
-         * (using OGC names):
-         *
-         * <ul>
-         *   <li>{@code "semi_major"}</li>
-         *   <li>{@code "semi_minor"}</li>
-         *   <li>{@code "central_meridian"}</li>
-         *   <li>{@code "scale_factor"}</li>
-         *   <li>{@code "false_easting"}</li>
-         *   <li>{@code "false_northing"}</li>
-         * </ul>
-         *
-         * <div class="note"><b>Note:</b>
-         * Apache SIS uses EPSG names as much as possible, but this method is an exception
to this rule.
-         * In this particular case we use OGC names because they are identical for a wide
range of projections.
-         * For example there is at least {@linkplain #SCALE_FACTOR three different EPSG names}
for the
-         * <cite>"scale factor"</cite> parameter, which OGC defines only {@code
"scale_factor"} for all of them.</div>
-         *
-         * @param  projection The map projection method for which to infer (<var>role</var>
→ <var>parameter</var>) associations.
-         * @return The parameters associated to most role in this enumeration.
-         * @throws ParameterNotFoundException if one of the above-cited parameters is not
found in the given projection method.
-         * @throws ClassCastException if a parameter has been found but is not an instance
of {@code ParameterDescriptor<Double>}.
-         */
-        public static Map<ParameterRole, ParameterDescriptor<Double>> defaultMap(final
OperationMethod projection)
-                throws ParameterNotFoundException, ClassCastException
-        {
-            final ParameterDescriptorGroup parameters = projection.getParameters();
-            final EnumMap<ParameterRole, ParameterDescriptor<Double>> roles =
new EnumMap<>(ParameterRole.class);
-            for (final ParameterRole role : values()) {
-                if (role.name != null) {
-                    final GeneralParameterDescriptor p = parameters.descriptor(role.name);
-                    roles.put(role, Parameters.cast((ParameterDescriptor<?>) p, Double.class));
-                }
-            }
-            return roles;
-        }
+        FALSE_NORTHING
     }
 
     /**
@@ -413,17 +357,14 @@ public abstract class NormalizedProjecti
      * @param method     Description of the map projection parameters.
      * @param parameters The parameters of the projection to be created.
      * @param roles Parameters to look for <cite>central meridian</cite>, <cite>scale
factor</cite>,
-     *        <cite>false easting</cite>, <cite>false northing</cite>
and other values, or {@code null}
-     *        for the {@linkplain ParameterRole#defaultMap(OperationMethod) default associations}.
+     *        <cite>false easting</cite>, <cite>false northing</cite>
and other values.
      */
     protected NormalizedProjection(final OperationMethod method, final Parameters parameters,
-            Map<ParameterRole, ? extends ParameterDescriptor<Double>> roles)
+            final Map<ParameterRole, ? extends ParameterDescriptor<Double>> roles)
     {
-        ensureNonNull("method", method);
+        ensureNonNull("method",     method);
         ensureNonNull("parameters", parameters);
-        if (roles == null) {
-            roles = ParameterRole.defaultMap(method);
-        }
+        ensureNonNull("roles",      roles);
         context = new ContextualParameters(method);
         /*
          * Note: we do not use Map.getOrDefault(K,V) below because the user could have explicitly
associated

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -485,33 +485,24 @@ class ConcatenatedTransform extends Abst
         final List<Object> transforms = getPseudoSteps();
         if (transforms.size() == 1 || Semaphores.query(Semaphores.PROJCS)) {
             for (final Object candidate : transforms) {
-                if (!(candidate instanceof Parameterized)) {
-                    /*
-                     * If a step does not implement the Parameterized interface, we conservatively
-                     * handle it as if it was a non-linear step: we should return its parameters
-                     * (which are null), or return null if there is more non-linear steps.
-                     */
-                    return null;
-                }
-                if (param != null) {
-                    /*
-                     * We found more than one Parameterized step. If both steps are non-linear,
-                     * we fail (return null) because we don't know which one to choose. If
both
-                     * steps are linear, we fail for the same reason   (actually the later
case
-                     * should never occur, since consecutive linear transforms should have
been
-                     * concatenated in a single affine transform. But we check as a safety).
If
-                     * the previous step was linear and the current candidate is non-linear,
we
-                     * retain the current candidate. Otherwise we discart it.
-                     */
-                    final boolean isLinear = (candidate instanceof LinearTransform);
-                    if ((param instanceof LinearTransform) == isLinear) {
+                /*
+                 * Search for non-linear parameters only, ignoring affine transforms and
the matrices
+                 * computed by ContextualParameters. Note that the 'transforms' list is guaranteed
to
+                 * contains at least one non-linear parameter, otherwise we would not have
created a
+                 * ConcatenatedTransform instance.
+                 */
+                if (!(candidate instanceof Matrix) && !(candidate instanceof LinearTransform))
{
+                    if ((param == null) && (candidate instanceof Parameterized))
{
+                        param = (Parameterized) candidate;
+                    } else {
+                        /*
+                         * Found more than one group of non-linear parameters, or found an
object
+                         * that do not declare its parameters.  In the later case, conservatively
+                         * returns 'null' because we do not know what the real parameters
are.
+                         */
                         return null;
                     }
-                    if (isLinear) {
-                        continue;
-                    }
                 }
-                param = (Parameterized) candidate;
             }
         }
         return param;

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -18,6 +18,9 @@ package org.apache.sis.referencing.opera
 
 import java.util.List;
 import java.util.Arrays;
+import java.util.Map;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
 import java.util.Objects;
 import java.io.Serializable;
 import org.opengis.util.FactoryException;
@@ -36,6 +39,7 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.util.DoubleDouble;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
+import org.apache.sis.parameter.Parameters;
 import org.apache.sis.parameter.Parameterized;
 import org.apache.sis.parameter.DefaultParameterValue;
 import org.apache.sis.referencing.operation.matrix.Matrices;
@@ -125,7 +129,7 @@ import static org.apache.sis.util.Argume
  * @see org.apache.sis.referencing.operation.projection.NormalizedProjection
  * @see AbstractMathTransform#getContextualParameters()
  */
-public class ContextualParameters extends FormattableObject implements ParameterValueGroup,
Cloneable, Serializable {
+public class ContextualParameters extends Parameters implements Serializable {
     /**
      * For cross-version compatibility.
      */
@@ -367,13 +371,44 @@ public class ContextualParameters extend
     {
         if (!isFrozen) {
             isFrozen = true;
-            for (int i=0; i < values.length; i++) {
-                final ParameterValue<?> p = values[i];
+            /*
+             * Sort the parameter values in the same order than the parameter descriptor.
This is not essential,
+             * but makes easier to read 'toString()' output by ensuring a consistent order
for most projections.
+             * Some WKT parsers other than SIS may also require the parameter values to be
listed in that specific
+             * order. We proceed by first copying all parameters in a temporary HashMap:
+             */
+            final Map<ParameterDescriptor<?>, ParameterValue<?>> parameters
= new IdentityHashMap<>(values.length);
+            for (ParameterValue<?> p : values) {
                 if (p == null) {
-                    values = Arrays.copyOf(values, i);  // Trim extra values.
-                    break;
+                    break;  // The first null value in the array indicates the end of sequence.
+                }
+                p = DefaultParameterValue.unmodifiable(p);
+                final ParameterDescriptor<?> desc = p.getDescriptor();
+                if (parameters.put(desc, p) != null) {
+                    // Should never happen unless ParameterValue.descriptor changed (contract
violation).
+                    throw new IllegalStateException(Errors.format(Errors.Keys.ElementAlreadyPresent_1,
desc.getName()));
+                }
+            }
+            /*
+             * Then, copy all HashMap values back to the 'values' array in the order they
are declared in the
+             * descriptor. Implementation note: the iteration termination condition uses
the values array, not
+             * the descriptors list, because the former is often shorter than the later.
We should never reach
+             * the end of descriptors list before the end of values array because 'descriptors'
contains all
+             * 'parameters' keys. This is verified by the 'assert' below.
+             */
+            values = new ParameterValue<?>[parameters.size()];
+            assert descriptor.descriptors().containsAll(parameters.keySet());
+            final Iterator<GeneralParameterDescriptor> it = descriptor.descriptors().iterator();
+            for (int i=0; i < values.length;) {
+                /*
+                 * No need to check for it.hasNext(), since a NoSuchElementException below
would be a bug in
+                 * our algorithm (or a concurrent change in the 'descriptor.descriptors()'
list, which would
+                 * be a contract violation). See above 'assert'.
+                 */
+                final ParameterValue<?> p = parameters.get(it.next());
+                if (p != null) {
+                    values[i++] = p;
                 }
-                values[i] = DefaultParameterValue.unmodifiable(p);
             }
         }
         /*
@@ -417,11 +452,6 @@ public class ContextualParameters extend
         for (int i=0; i < values.length; i++) {
             ParameterValue<?> p = values[i];
             if (p == null) {
-                /*
-                 * No existing parameter instance. Create a new one if this ContextualParameter
-                 * is still modifiable.
-                 */
-                ensureModifiable();
                 p = ((ParameterDescriptor<?>) desc).createValue();
                 values[i] = p;
             } else if (p.getDescriptor() != desc) {  // Identity comparison should be okay
here.
@@ -429,7 +459,17 @@ public class ContextualParameters extend
             }
             return p;   // Found or created a parameter.
         }
-        ensureModifiable();
+        /*
+         * We may reach this point if map projection construction is completed (i.e. 'completeTransform(…)'
has
+         * been invoked) and the user asks for a parameter which is not one of the parameters
that we retained.
+         * Returns a parameter initialized to the default value, which is the actual value
(otherwise we would
+         * have stored that parameter).  Note: we do not bother making the parameter immutable
for performance
+         * reason. If the user invokes a setter method on the returned parameter, he may
get a false impression
+         * that this ContextualParameters is still modifiable. We presume that such scenario
would be rare.
+         */
+        if (isFrozen) {
+            return ((ParameterDescriptor<?>) desc).createValue();
+        }
         /*
          * Should never reach this point. If it happen anyway, this means that the descriptor
now accepts
          * more parameters than what it declared at ContextualParameteres construction time,
or that some
@@ -506,12 +546,7 @@ public class ContextualParameters extend
         /*
          * Now proceed to the clone of this ContextualParameters instance.
          */
-        final ContextualParameters clone;
-        try {
-            clone = (ContextualParameters) super.clone();
-        } catch (CloneNotSupportedException e) {
-            throw new AssertionError(e);    // Should never happen since we are cloneable.
-        }
+        final ContextualParameters clone = (ContextualParameters) super.clone();
         clone.values      = param;
         clone.normalize   = normalize.clone();
         clone.denormalize = denormalize.clone();
@@ -545,30 +580,20 @@ public class ContextualParameters extend
     }
 
     /**
-     * Formats a <cite>Well Known Text</cite> version 1 (WKT 1) element for a
transform using this group of parameters.
-     *
-     * <div class="note"><b>Compatibility note:</b>
-     * {@code Param_MT} is defined in the WKT 1 specification only.
-     * If the {@linkplain Formatter#getConvention() formatter convention} is set to WKT 2,
-     * then this method silently uses the WKT 1 convention without raising an error.</div>
-     *
-     * @return {@code "Param_MT"}.
+     * Formats the <cite>Well Known Text</cite> for the transform or the inverse
of the transform
+     * that would be built from the enclosing {@code ContextualParameters}.
      */
-    @Override
-    protected String formatTo(final Formatter formatter) {
-        WKTUtilities.appendParamMT(this, formatter);
-        return "Param_MT";
-    }
+    private final class WKT extends FormattableObject implements Parameterized {
+        /**
+         * {@code true} if this proxy is for the inverse transform instead than the direct
one.
+         */
+        private final boolean inverse;
 
-    /**
-     * Formats the <cite>Well Known Text</cite> for the inverse of the transform
that would be built
-     * from the enclosing {@code ContextualParameters}.
-     */
-    private final class InverseWKT extends FormattableObject implements Parameterized {
         /**
          * Creates a new object to be formatted instead than the enclosing transform.
          */
-        InverseWKT() {
+        WKT(final boolean inverse) {
+            this.inverse = inverse;
         }
 
         /**
@@ -588,12 +613,24 @@ public class ContextualParameters extend
         }
 
         /**
-         * Process to the WKT formatting of the inverse transform.
+         * Formats a <cite>Well Known Text</cite> version 1 (WKT 1) element for
a transform using this group of parameters.
+         *
+         * <div class="note"><b>Compatibility note:</b>
+         * {@code Param_MT} is defined in the WKT 1 specification only.
+         * If the {@linkplain Formatter#getConvention() formatter convention} is set to WKT
2,
+         * then this method silently uses the WKT 1 convention without raising an error.</div>
+         *
+         * @return {@code "Param_MT"}.
          */
         @Override
         protected String formatTo(final Formatter formatter) {
-            formatter.append(ContextualParameters.this);
-            return "Inverse_MT";
+            if (inverse) {
+                formatter.append(new WKT(false));
+                return "Inverse_MT";
+            } else {
+                WKTUtilities.appendParamMT(ContextualParameters.this, formatter);
+                return "Param_MT";
+            }
         }
     }
 
@@ -703,7 +740,7 @@ public class ContextualParameters extend
                 transforms.add(index++, before);
             }
         }
-        transforms.set(index, inverse ? new InverseWKT() : this);
+        transforms.set(index, new WKT(inverse));
         if (after == null) {
             if (hasAfter) {
                 final Object old = transforms.remove(index + 1);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -668,7 +668,7 @@ public class DefaultMathTransformFactory
          * "elt_0_0", "elt_0_1", etc.  The following code just forwards those parameters
to the newly
          * created transform; it does not change the operation.
          */
-        if (parameterized instanceof ParameterizedAffine) {
+        if (parameterized instanceof ParameterizedAffine && !(mt instanceof ParameterizedAffine))
{
             mt = ((ParameterizedAffine) parameterized).newTransform(mt);
         }
         return mt;

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/MapProjectionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/MapProjectionTest.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/MapProjectionTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/MapProjectionTest.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -22,7 +22,6 @@ import org.opengis.metadata.Identifier;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.GeneralParameterDescriptor;
 import org.apache.sis.metadata.iso.citation.Citations;
-import org.apache.sis.internal.util.Constants;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ContextualParametersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ContextualParametersTest.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ContextualParametersTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ContextualParametersTest.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -112,15 +112,16 @@ public final strictfp class ContextualPa
     @Test
     public void testSameTransform() throws FactoryException {
         final ContextualParameters p = create(1, 1);
+        p.parameter("Mandatory 1").setValue(4);
         final MathTransform kernel = MathTransforms.linear(3, 4);
         assertEquals(kernel, p.completeTransform(DefaultMathTransformFactoryTest.factory(),
kernel));
         try {
-            p.parameter("Mandatory 1");
+            p.parameter("Mandatory 1").setValue(10);
             fail("Shall not be allowed to modify an immutable instance.");
-        } catch (IllegalStateException e) {
+        } catch (UnsupportedOperationException e) {
             // This is the expected exception.
             final String message = e.getMessage();
-            assertTrue(message, message.contains("ContextualParameters"));
+            assertTrue(message, message.contains("ParameterValue"));
         }
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/HTMLGenerator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/HTMLGenerator.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/HTMLGenerator.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/HTMLGenerator.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -24,6 +24,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.BufferedWriter;
 import java.io.OutputStreamWriter;
+import java.io.Closeable;
 import org.opengis.util.InternationalString;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Deprecable;
@@ -41,7 +42,7 @@ import org.apache.sis.util.Deprecable;
  * @version 0.6
  * @module
  */
-public abstract class HTMLGenerator implements AutoCloseable {
+public abstract class HTMLGenerator implements Closeable {
     /**
      * The encoding of the files to generate.
      */

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1674932&r1=1674931&r2=1674932&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Mon Apr 20 15:40:18 2015
@@ -59,7 +59,7 @@ public final class DefaultFactories exte
 
     /**
      * Return the default factory implementing the given interface.
-     * This method returns only Apache SIS implementation of factories, and ignore all other.
+     * This method gives preference to Apache SIS implementation of factories if present.
      * This is a temporary mechanism while we are waiting for a real dependency injection
mechanism.
      *
      * @param  <T>  The interface type.
@@ -69,6 +69,7 @@ public final class DefaultFactories exte
     public static synchronized <T> T forClass(final Class<T> type) {
         T factory = type.cast(FACTORIES.get(type));
         if (factory == null && !FACTORIES.containsKey(type)) {
+            T fallback = null;
             for (final T candidate : ServiceLoader.load(type)) {
                 final Class<?> ct = candidate.getClass();
                 if (ct.getName().startsWith("org.apache.sis.")) {
@@ -76,9 +77,13 @@ public final class DefaultFactories exte
                         throw new ServiceConfigurationError("Found two implementations of
" + type);
                     }
                     factory = candidate;
-                    break;
+                } else if (fallback == null) {
+                    fallback = candidate;
                 }
             }
+            if (factory == null) {
+                factory = fallback;
+            }
             FACTORIES.put(type, factory);
         }
         return factory;



Mime
View raw message