sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1708397 - in /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation: AbstractCoordinateOperation.java AbstractSingleOperation.java DefaultConversion.java
Date Tue, 13 Oct 2015 13:52:38 GMT
Author: desruisseaux
Date: Tue Oct 13 13:52:37 2015
New Revision: 1708397

URL: http://svn.apache.org/viewvc?rev=1708397&view=rev
Log:
Opportunistically exploit the fact that we had to remove the 'final' keyword on some fields
(required for JAXB unmarshalling) for simplifying constructors of various CoordinateOperation
subtypes.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java?rev=1708397&r1=1708396&r2=1708397&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] Tue Oct 13 13:52:37 2015
@@ -115,7 +115,7 @@ public class AbstractCoordinateOperation
      * The source CRS, or {@code null} if not available.
      *
      * <p><b>Consider this field as final!</b>
-     * This field is non final only for the convenience of constructors and for initialization
+     * This field is non-final only for the convenience of constructors and for initialization
      * at XML unmarshalling time by {@link #setSource(CoordinateReferenceSystem)}.</p>
      *
      * @see #getSourceCRS()
@@ -126,7 +126,7 @@ public class AbstractCoordinateOperation
      * The target CRS, or {@code null} if not available.
      *
      * <p><b>Consider this field as final!</b>
-     * This field is non final only for the convenience of constructors and for initialization
+     * This field is non-final only for the convenience of constructors and for initialization
      * at XML unmarshalling time by {@link #setTarget(CoordinateReferenceSystem)}.</p>
      *
      * @see #getTargetCRS()
@@ -138,7 +138,7 @@ public class AbstractCoordinateOperation
      * {@linkplain #getTargetCRS() target CRS} but still required for performing the operation.
      *
      * <p><b>Consider this field as final!</b>
-     * This field is non final only for the convenience of constructors.</p>
+     * This field is non-final only for the convenience of constructors.</p>
      *
      * @see #getInterpolationCRS()
      */
@@ -155,7 +155,7 @@ public class AbstractCoordinateOperation
      * Estimate(s) of the impact of this operation on point accuracy, or {@code null} if
none.
      *
      * <p><b>Consider this field as final!</b>
-     * This field is non final only for the convenience of constructors.</p>
+     * This field is non-final only for the convenience of constructors.</p>
      *
      * @see #getCoordinateOperationAccuracy()
      */
@@ -179,41 +179,21 @@ public class AbstractCoordinateOperation
      * to positions in the {@linkplain #getTargetCRS target coordinate reference system}.
      *
      * <p><b>Consider this field as final!</b>
-     * This field is non final only for the convenience of constructors and for initialization
+     * This field is non-final only for the convenience of constructors and for initialization
      * at XML unmarshalling time by {@link #afterUnmarshal(Unmarshaller, Object)}</p>
      */
     MathTransform transform;
 
     /**
-     * Creates a new coordinate operation with the same values than the specified defining
conversion,
-     * except for the source CRS, target CRS and the math transform which are set the given
values.
-     *
-     * <p>This constructor is (indirectly) for {@link DefaultConversion} usage only,
-     * in order to create a "real" conversion from a defining conversion.</p>
-     */
-    AbstractCoordinateOperation(final CoordinateOperation definition,
-                                final CoordinateReferenceSystem sourceCRS,
-                                final CoordinateReferenceSystem targetCRS,
-                                final MathTransform transform)
-    {
-        super(definition);
-        this.sourceCRS                   = sourceCRS;
-        this.targetCRS                   = targetCRS;
-        this.interpolationCRS            = getInterpolationCRS(definition);
-        this.operationVersion            = definition.getOperationVersion();
-        this.coordinateOperationAccuracy = definition.getCoordinateOperationAccuracy();
-        this.domainOfValidity            = definition.getDomainOfValidity();
-        this.scope                       = definition.getScope();
-        this.transform                   = transform;
-        checkDimensions(null);
-    }
-
-    /**
      * Creates a new coordinate operation initialized from the given properties.
      * It is caller's responsibility to:
      *
      * <ul>
-     *   <li>Set the {@link #sourceCRS}, {@link #targetCRS} and {@link #transform}
fields.</li>
+     *   <li>Set the following fields:<ul>
+     *     <li>{@link #sourceCRS}</li>
+     *     <li>{@link #targetCRS}</li>
+     *     <li>{@link #transform}</li>
+     *   </ul></li>
      *   <li>Invoke {@link #checkDimensions(Map)} after the above-cited fields have
been set.</li>
      * </ul>
      */
@@ -512,7 +492,7 @@ check:      for (int isTarget=0; ; isTar
     /**
      * Returns the interpolation CRS of the given coordinate operation, or {@code null} if
none.
      */
-    static CoordinateReferenceSystem getInterpolationCRS(final CoordinateOperation operation)
{
+    private static CoordinateReferenceSystem getInterpolationCRS(final CoordinateOperation
operation) {
         return (operation instanceof AbstractCoordinateOperation)
                ? ((AbstractCoordinateOperation) operation).getInterpolationCRS() : null;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java?rev=1708397&r1=1708396&r2=1708397&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] Tue Oct 13 13:52:37 2015
@@ -65,7 +65,7 @@ import java.util.Objects;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  */
 @XmlType(name="AbstractSingleOperationType", propOrder = {
@@ -93,9 +93,10 @@ class AbstractSingleOperation extends Ab
      * The parameter values, or {@code null} for inferring it from the math transform.
      *
      * <p><b>Consider this field as final!</b>
-     * This field is modified only at unmarshalling time by {@link #setParameters(GeneralParameterValue[])}</p>
+     * This field is non-final only for the convenience of constructors and for initialization
+     * at XML unmarshalling time by {@link #setParameters(GeneralParameterValue[])}</p>
      */
-    private ParameterValueGroup parameters;
+    ParameterValueGroup parameters;
 
     /**
      * Creates a coordinate operation from the given properties.
@@ -122,50 +123,23 @@ class AbstractSingleOperation extends Ab
     }
 
     /**
-     * Creates a defining conversion from the given transform and/or parameters.
-     * See {@link DefaultConversion#DefaultConversion(Map, OperationMethod, MathTransform,
ParameterValueGroup)}
-     * for more information.
+     * Creates a new coordinate operation initialized from the given properties.
+     * It is caller's responsibility to:
+     *
+     * <ul>
+     *   <li>Set the following fields:<ul>
+     *     <li>{@link #sourceCRS}</li>
+     *     <li>{@link #targetCRS}</li>
+     *     <li>{@link #transform}</li>
+     *     <li>{@link #parameters}</li>
+     *   </ul></li>
+     *   <li>Invoke {@link #checkDimensions(Map)} after the above-cited fields have
been set.</li>
+     * </ul>
      */
-    AbstractSingleOperation(final Map<String,?>       properties,
-                            final OperationMethod     method,
-                            final MathTransform       transform,
-                            final ParameterValueGroup parameters)
-    {
-        super(properties, null, null, null, transform);
+    AbstractSingleOperation(final Map<String,?> properties, final OperationMethod method)
{
+        super(properties);
         ArgumentChecks.ensureNonNull("method", method);
-        if (transform != null) {
-            checkDimensions(method, 0, transform, properties);
-        } else if (parameters == null) {
-            throw new IllegalArgumentException(Errors.getResources(properties)
-                    .getString(Errors.Keys.UnspecifiedParameterValues));
-        }
         this.method = method;
-        this.parameters = (parameters != null) ? parameters.clone() : null;
-    }
-
-    /**
-     * Creates a new coordinate operation with the same values than the specified defining
conversion,
-     * except for the source CRS, target CRS and the math transform which are set the given
values.
-     *
-     * <p>This constructor is for {@link DefaultConversion} usage only,
-     * in order to create a "real" conversion from a defining conversion.</p>
-     *
-     * @param definition The defining conversion.
-     * @param sourceCRS  The source CRS.
-     * @param targetCRS  The target CRS.
-     * @param transform  The math transform, optionally with the parameters used for creating
it.
-     *        Bundled in a {@code Map.Entry} as an ugly workaround for RFE #4093999 in Java
bug database
-     *        ("Relax constraint on placement of this()/super() call in constructors").
-     */
-    AbstractSingleOperation(final SingleOperation definition,
-                            final CoordinateReferenceSystem sourceCRS,
-                            final CoordinateReferenceSystem targetCRS,
-                            final Map.Entry<ParameterValueGroup,MathTransform> transform)
-    {
-        super(definition, sourceCRS, targetCRS, transform.getValue());
-        method = definition.getMethod();
-        final ParameterValueGroup p = transform.getKey();
-        parameters = (p != null) ? p : getParameterValues(definition);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java?rev=1708397&r1=1708396&r2=1708397&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
[UTF-8] Tue Oct 13 13:52:37 2015
@@ -17,7 +17,6 @@
 package org.apache.sis.referencing.operation;
 
 import java.util.Map;
-import java.util.AbstractMap;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.measure.converter.ConversionException;
@@ -39,7 +38,6 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
-import org.apache.sis.util.Workaround;
 import org.apache.sis.util.Utilities;
 
 
@@ -81,7 +79,7 @@ import org.apache.sis.util.Utilities;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  *
  * @see DefaultTransformation
@@ -207,7 +205,18 @@ public class DefaultConversion extends A
                              final MathTransform       transform,
                              final ParameterValueGroup parameters)
     {
-        super(properties, method, transform, parameters);
+        super(properties, method);
+        if (transform != null) {
+            this.transform = transform;
+            checkDimensions(method, 0, transform, properties);
+        } else if (parameters == null) {
+            throw new IllegalArgumentException(Errors.getResources(properties)
+                    .getString(Errors.Keys.UnspecifiedParameterValues));
+        }
+        if (parameters != null) {
+            this.parameters = parameters.clone();
+        }
+        checkDimensions(properties);
     }
 
     /**
@@ -216,16 +225,58 @@ public class DefaultConversion extends A
      * typically a defining conversion.
      *
      * @param definition The defining conversion.
-     * @param sourceCRS  The source CRS.
-     * @param targetCRS  The target CRS.
+     * @param source     The new source CRS.
+     * @param target     The new target CRS.
      * @param factory    The factory to use for creating a transform from the parameters
or for performing axis changes.
      */
     DefaultConversion(final Conversion definition,
-                      final CoordinateReferenceSystem sourceCRS,
-                      final CoordinateReferenceSystem targetCRS,
+                      final CoordinateReferenceSystem source,
+                      final CoordinateReferenceSystem target,
                       final MathTransformFactory factory) throws FactoryException
     {
-        super(definition, sourceCRS, targetCRS, createMathTransform(definition, sourceCRS,
targetCRS, factory));
+        super(definition);
+        int interpDim = ReferencingUtilities.getDimension(super.getInterpolationCRS());
+        if (transform == null) {
+            /*
+             * If the user did not specified explicitely a MathTransform, we will need to
create it
+             * from the parameters. This case happen often when creating a ProjectedCRS,
because the
+             * user often did not have all needed information when he created the defining
conversion:
+             * the length of semi-major and semi-minor axes were often missing. But now we
know those
+             * lengths thanks to the 'sourceCRS' argument given to this method. So we can
complete the
+             * parameters. This is the job of MathTransformFactory.createBaseToDerived(…).
+             */
+            if (parameters == null) {
+                throw new IllegalArgumentException(Errors.format(Errors.Keys.UnspecifiedParameterValues));
+            }
+            transform = factory.createBaseToDerived(source, parameters, target.getCoordinateSystem());
+        } else {
+            /*
+             * If the user specified explicitely a MathTransform, we may still need to swap
or scale axes.
+             * If this conversion is a defining conversion (which is usually the case when
creating a new
+             * ProjectedCRS), then DefaultMathTransformFactory has a specialized createBaseToDerived(…)
+             * method for this job.
+             */
+            if (sourceCRS == null && targetCRS == null && factory instanceof
DefaultMathTransformFactory) {
+                transform = ((DefaultMathTransformFactory) factory).createBaseToDerived(
+                        source.getCoordinateSystem(), transform,
+                        target.getCoordinateSystem());
+            } else {
+                /*
+                 * If we can not use our SIS factory implementation, or if this conversion
is not a defining
+                 * conversion (i.e. if this is the conversion of an existing ProjectedCRS,
in which case the
+                 * math transform may not be normalized), then we fallback on a simpler swapAndScaleAxes(…)
+                 * method defined in this class. This is needed for AbstractCRS.forConvention(AxisConvention).
+                 */
+                transform = swapAndScaleAxes(transform, source, sourceCRS, interpDim, true,
 factory);
+                transform = swapAndScaleAxes(transform, targetCRS, target, interpDim, false,
factory);
+                interpDim = 0;  // Skip createPassThroughTransform(…) since it was handled
by swapAndScaleAxes(…).
+            }
+        }
+        if (interpDim != 0) {
+            transform = factory.createPassThroughTransform(interpDim, transform, 0);
+        }
+        sourceCRS = source;
+        targetCRS = target;
     }
 
     /**
@@ -378,78 +429,6 @@ public class DefaultConversion extends A
     }
 
     /**
-     * Creates the math transform to be given to the sub-class constructor.
-     * This method is a workaround for RFE #4093999 in Java bug database
-     * ("Relax constraint on placement of this()/super() call in constructors").
-     *
-     * <p>This method may also return the parameters used for creating the math transform
because those parameters
-     * may have been augmented with the semi-major and semi-minor axis lengths.  Since those
parameter values have
-     * been set on a clone of {@code definition.getParameterValues()}, those values are lost
(ignoring MathTransform
-     * internal) if we do not return them here.</p>
-     *
-     * @return The math transform, optionally with the parameters used for creating it.
-     *         Bundled in a {@code Map.Entry} as an ugly workaround for RFE #4093999.
-     */
-    @Workaround(library="JDK", version="1.7")
-    private static Map.Entry<ParameterValueGroup,MathTransform> createMathTransform(
-            final Conversion definition,
-            final CoordinateReferenceSystem sourceCRS,
-            final CoordinateReferenceSystem targetCRS,
-            final MathTransformFactory factory) throws FactoryException
-    {
-        final int interpDim = ReferencingUtilities.getDimension(getInterpolationCRS(definition));
-        MathTransform mt = definition.getMathTransform();
-        final Map.Entry<ParameterValueGroup,MathTransform> pair;
-        if (mt == null) {
-            /*
-             * If the user did not specified explicitely a MathTransform, we will need to
create it
-             * from the parameters. This case happen often when creating a ProjectedCRS,
because the
-             * user often did not have all needed information when he created the defining
conversion:
-             * the length of semi-major and semi-minor axes were often missing. But now we
know those
-             * lengths thanks to the 'sourceCRS' argument given to this method. So we can
complete the
-             * parameters. This is the job of MathTransformFactory.createBaseToDerived(…).
-             */
-            final ParameterValueGroup parameters = definition.getParameterValues();
-            if (parameters == null) {
-                throw new IllegalArgumentException(Errors.format(Errors.Keys.UnspecifiedParameterValues));
-            }
-            mt = factory.createBaseToDerived(sourceCRS, parameters, targetCRS.getCoordinateSystem());
-            pair = new AbstractMap.SimpleEntry<>(parameters, mt);
-        } else {
-            pair = new AbstractMap.SimpleEntry<>(null, mt);
-            /*
-             * If the user specified explicitely a MathTransform, we may still need to swap
or scale axes.
-             * If this conversion is a defining conversion (which is usually the case when
creating a new
-             * ProjectedCRS), then DefaultMathTransformFactory has a specialized createBaseToDerived(…)
-             * method for this job.
-             */
-            final CoordinateReferenceSystem mtSource = definition.getSourceCRS();
-            final CoordinateReferenceSystem mtTarget = definition.getTargetCRS();
-            if (mtSource == null && mtTarget == null && factory instanceof
DefaultMathTransformFactory) {
-                mt = ((DefaultMathTransformFactory) factory).createBaseToDerived(
-                        sourceCRS.getCoordinateSystem(), mt,
-                        targetCRS.getCoordinateSystem());
-            } else {
-                /*
-                 * If we can not use our SIS factory implementation, or if this conversion
is not a defining
-                 * conversion (i.e. if this is the conversion of an existing ProjectedCRS,
in which case the
-                 * math transform may not be normalized), then we fallback on a simpler swapAndScaleAxes(…)
-                 * method defined in this class. This is needed for AbstractCRS.forConvention(AxisConvention).
-                 */
-                mt = swapAndScaleAxes(mt, sourceCRS, mtSource, interpDim, true,  factory);
-                mt = swapAndScaleAxes(mt, mtTarget, targetCRS, interpDim, false, factory);
-                pair.setValue(mt);
-                return pair;  // Skip createPassThroughTransform(…) since it was handled
by swapAndScaleAxes(…).
-            }
-        }
-        if (interpDim != 0) {
-            mt = factory.createPassThroughTransform(interpDim, mt, 0);
-        }
-        pair.setValue(mt);
-        return pair;
-    }
-
-    /**
      * Concatenates to the given transform the operation needed for swapping and scaling
the axes.
      * The two coordinate systems must implement the same GeoAPI coordinate system interface.
      * For example if {@code sourceCRS} uses a {@code CartesianCS}, then {@code targetCRS}
must use



Mime
View raw message