sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1675611 - in /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing: ./ operation/
Date Thu, 23 Apr 2015 13:28:08 GMT
Author: desruisseaux
Date: Thu Apr 23 13:28:07 2015
New Revision: 1675611

URL: http://svn.apache.org/r1675611
Log:
Referencing: more 'castOrCopy' implementations in CoordinateOperation sub-types.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java
    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/DefaultConicProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultTransformation.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1675611&r1=1675610&r2=1675611&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] Thu Apr 23 13:28:07 2015
@@ -432,6 +432,7 @@ public class AbstractIdentifiedObject ex
      *       {@link org.opengis.referencing.datum.Ellipsoid},
      *       {@link org.opengis.referencing.datum.PrimeMeridian},
      *       {@link org.opengis.referencing.operation.OperationMethod},
+     *       {@link org.opengis.referencing.operation.CoordinateOperation},
      *       {@link org.opengis.parameter.ParameterDescriptor} or
      *       {@link org.opengis.parameter.ParameterDescriptorGroup},
      *       then this method delegates to the {@code castOrCopy(…)} method of the corresponding
SIS subclass.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java?rev=1675611&r1=1675610&r2=1675611&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/SubTypes.java
[UTF-8] Thu Apr 23 13:28:07 2015
@@ -24,6 +24,7 @@ import org.opengis.referencing.datum.Dat
 import org.opengis.referencing.datum.Ellipsoid;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.operation.OperationMethod;
+import org.opengis.referencing.operation.CoordinateOperation;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.apache.sis.referencing.crs.AbstractCRS;
@@ -33,6 +34,7 @@ import org.apache.sis.referencing.datum.
 import org.apache.sis.referencing.datum.DefaultEllipsoid;
 import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
 import org.apache.sis.referencing.operation.DefaultOperationMethod;
+import org.apache.sis.referencing.operation.AbstractCoordinateOperation;
 import org.apache.sis.parameter.DefaultParameterDescriptor;
 import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
 
@@ -83,6 +85,9 @@ final class SubTypes {
         if (object instanceof PrimeMeridian) {
             return DefaultPrimeMeridian.castOrCopy((PrimeMeridian) object);
         }
+        if (object instanceof CoordinateOperation) {
+            return AbstractCoordinateOperation.castOrCopy((CoordinateOperation) object);
+        }
         if (object instanceof OperationMethod) {
             return DefaultOperationMethod.castOrCopy((OperationMethod) object);
         }

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=1675611&r1=1675610&r2=1675611&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] Thu Apr 23 13:28:07 2015
@@ -156,6 +156,7 @@ public class AbstractCoordinateOperation
         this.domainOfValidity            = definition.getDomainOfValidity();
         this.scope                       = definition.getScope();
         this.transform                   = definition.getMathTransform();
+        checkDimensions();
     }
 
     /**
@@ -268,9 +269,14 @@ public class AbstractCoordinateOperation
             coordinateOperationAccuracy = (value == null) ? null :
                     Collections.singleton((PositionalAccuracy) value);
         }
-        /*
-         * Verifiy arguments consistency.
-         */
+        checkDimensions();
+    }
+
+    /**
+     * Ensures that {@link #sourceCRS}, {@link #targetCRS} and {@link #interpolationCRS}
dimensions
+     * are consistent with {@link #transform} input and output dimensions.
+     */
+    private void checkDimensions() {
         if (transform != null) {
             int sourceDim = transform.getSourceDimensions();
             int targetDim = transform.getTargetDimensions();

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=1675611&r1=1675610&r2=1675611&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] Thu Apr 23 13:28:07 2015
@@ -121,6 +121,22 @@ class AbstractSingleOperation extends Ab
     }
 
     /**
+     * Creates a new coordinate operation with the same values than the specified one.
+     * This copy constructor provides a way to convert an arbitrary implementation into a
SIS one
+     * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific
API.
+     *
+     * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+     *
+     * @param operation The coordinate operation to copy.
+     */
+    protected AbstractSingleOperation(final SingleOperation operation) {
+        super(operation);
+        method = operation.getMethod();
+        parameters = (operation instanceof AbstractSingleOperation) ?
+                ((AbstractSingleOperation) operation).parameters : operation.getParameterValues();
+    }
+
+    /**
      * Checks if an operation method and a math transform have a compatible number of source
and target dimensions.
      * In the particular case of a {@linkplain PassThroughTransform pass through transform}
with more dimensions
      * than what we would expect from the given method, the check will rather be performed
against the

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java?rev=1675611&r1=1675610&r2=1675611&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java
[UTF-8] Thu Apr 23 13:28:07 2015
@@ -55,6 +55,19 @@ final class DefaultConicProjection exten
     }
 
     /**
+     * Creates a new coordinate operation with the same values than the specified one.
+     * This copy constructor provides a way to convert an arbitrary implementation into a
SIS one
+     * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific
API.
+     *
+     * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+     *
+     * @param operation The coordinate operation to copy.
+     */
+    protected DefaultConicProjection(final ConicProjection operation) {
+        super(operation);
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The SIS implementation returns {@code ConicProjection.class}.
      *

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=1675611&r1=1675610&r2=1675611&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] Thu Apr 23 13:28:07 2015
@@ -149,6 +149,52 @@ public class DefaultConversion extends A
     }
 
     /**
+     * Creates a new coordinate operation with the same values than the specified one.
+     * This copy constructor provides a way to convert an arbitrary implementation into a
SIS one
+     * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific
API.
+     *
+     * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+     *
+     * @param operation The coordinate operation to copy.
+     *
+     * @see #castOrCopy(Conversion)
+     */
+    protected DefaultConversion(final Conversion operation) {
+        super(operation);
+    }
+
+    /**
+     * Returns a SIS coordinate operation implementation with the values of the given arbitrary
implementation.
+     * This method performs the first applicable action in the following choices:
+     *
+     * <ul>
+     *   <li>If the given object is {@code null}, then this method returns {@code null}.</li>
+     *   <li>Otherwise if the given object is an instance of
+     *       {@link org.opengis.referencing.operation.Conversion},
+     *       {@link org.opengis.referencing.operation.Projection},
+     *       {@link org.opengis.referencing.operation.CylindricalProjection},
+     *       {@link org.opengis.referencing.operation.ConicProjection} or
+     *       {@link org.opengis.referencing.operation.PlanarProjection},
+     *       then this method delegates to the {@code castOrCopy(…)} method of the corresponding
SIS subclass.
+     *       Note that if the given object implements more than one of the above-cited interfaces,
+     *       then the {@code castOrCopy(…)} method to be used is unspecified.</li>
+     *   <li>Otherwise if the given object is already an instance of
+     *       {@code DefaultConversion}, then it is returned unchanged.</li>
+     *   <li>Otherwise a new {@code DefaultConversion} instance is created using the
+     *       {@linkplain #DefaultConversion(Conversion) copy constructor}
+     *       and returned. Note that this is a <cite>shallow</cite> copy operation,
since the other
+     *       properties contained in the given object are not recursively copied.</li>
+     * </ul>
+     *
+     * @param  object The object to get as a SIS implementation, or {@code null} if none.
+     * @return A SIS implementation containing the values of the given object (may be the
+     *         given object itself), or {@code null} if the argument was null.
+     */
+    public static DefaultConversion castOrCopy(final Conversion object) {
+        return SubTypes.forConversion(object);
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The default implementation returns {@code Conversion.class}.
      * Subclasses implementing a more specific GeoAPI interface shall override this method.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java?rev=1675611&r1=1675610&r2=1675611&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
[UTF-8] Thu Apr 23 13:28:07 2015
@@ -55,6 +55,19 @@ final class DefaultCylindricalProjection
     }
 
     /**
+     * Creates a new coordinate operation with the same values than the specified one.
+     * This copy constructor provides a way to convert an arbitrary implementation into a
SIS one
+     * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific
API.
+     *
+     * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+     *
+     * @param operation The coordinate operation to copy.
+     */
+    protected DefaultCylindricalProjection(final CylindricalProjection operation) {
+        super(operation);
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The SIS implementation returns {@code CylindricalProjection.class}.
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java?rev=1675611&r1=1675610&r2=1675611&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
[UTF-8] Thu Apr 23 13:28:07 2015
@@ -55,6 +55,19 @@ final class DefaultPlanarProjection exte
     }
 
     /**
+     * Creates a new coordinate operation with the same values than the specified one.
+     * This copy constructor provides a way to convert an arbitrary implementation into a
SIS one
+     * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific
API.
+     *
+     * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+     *
+     * @param operation The coordinate operation to copy.
+     */
+    protected DefaultPlanarProjection(final PlanarProjection operation) {
+        super(operation);
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The SIS implementation returns {@code PlanarProjection.class}.
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java?rev=1675611&r1=1675610&r2=1675611&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
[UTF-8] Thu Apr 23 13:28:07 2015
@@ -67,6 +67,19 @@ class DefaultProjection extends DefaultC
     }
 
     /**
+     * Creates a new coordinate operation with the same values than the specified one.
+     * This copy constructor provides a way to convert an arbitrary implementation into a
SIS one
+     * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific
API.
+     *
+     * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+     *
+     * @param operation The coordinate operation to copy.
+     */
+    protected DefaultProjection(final Projection operation) {
+        super(operation);
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The default implementation returns {@code Projection.class}.
      * Subclasses implementing a more specific GeoAPI interface shall override this method.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultTransformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultTransformation.java?rev=1675611&r1=1675610&r2=1675611&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultTransformation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultTransformation.java
[UTF-8] Thu Apr 23 13:28:07 2015
@@ -111,6 +111,38 @@ public class DefaultTransformation exten
     }
 
     /**
+     * Creates a new coordinate operation with the same values than the specified one.
+     * This copy constructor provides a way to convert an arbitrary implementation into a
SIS one
+     * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific
API.
+     *
+     * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+     *
+     * @param operation The coordinate operation to copy.
+     *
+     * @see #castOrCopy(Transformation)
+     */
+    protected DefaultTransformation(final Transformation operation) {
+        super(operation);
+    }
+
+    /**
+     * Returns a SIS coordinate operation implementation with the values of the given arbitrary
implementation.
+     * If the given object is already an instance of {@code DefaultTransformation}, then
it is returned unchanged.
+     * Otherwise a new {@code DefaultTransformation} instance is created using the
+     * {@linkplain #DefaultTransformation(Transformation) copy constructor} and returned.
+     * Note that this is a <cite>shallow</cite> copy operation, since the other
properties contained in the given
+     * object are not recursively copied.
+     *
+     * @param  object The object to get as a SIS implementation, or {@code null} if none.
+     * @return A SIS implementation containing the values of the given object (may be the
+     *         given object itself), or {@code null} if the argument was null.
+     */
+    public static DefaultTransformation castOrCopy(final Transformation object) {
+        return (object == null) || (object instanceof DefaultTransformation)
+                ? (DefaultTransformation) object : new DefaultTransformation(object);
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The SIS implementation returns {@code Transformation.class}.
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java?rev=1675611&r1=1675610&r2=1675611&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/SubTypes.java
[UTF-8] Thu Apr 23 13:28:07 2015
@@ -16,7 +16,7 @@
  */
 package org.apache.sis.referencing.operation;
 
-import org.opengis.referencing.operation.CoordinateOperation;
+import org.opengis.referencing.operation.*;
 
 
 /**
@@ -47,7 +47,16 @@ final class SubTypes {
      * @see AbstractCoordinateOperation#castOrCopy(CoordinateOperation)
      */
     static AbstractCoordinateOperation castOrCopy(final CoordinateOperation object) {
-        // TODO: subclasses to be tested here.
+        if (object instanceof Transformation) {
+            return DefaultTransformation.castOrCopy((Transformation) object);
+        }
+        if (object instanceof Conversion) {
+            return forConversion((Conversion) object);
+        }
+        if (object instanceof SingleOperation) {
+            return (object instanceof AbstractSingleOperation) ? (AbstractSingleOperation)
object
+                   : new AbstractSingleOperation((SingleOperation) object);
+        }
         /*
          * Intentionally check for AbstractCoordinateOperation after the interfaces because
user may have defined
          * his own subclass implementing the same interface.  If we were checking for AbstractCoordinateOperation
@@ -59,4 +68,32 @@ final class SubTypes {
         }
         return new AbstractCoordinateOperation(object);
     }
+
+    /**
+     * Returns a SIS implementation for the given conversion.
+     *
+     * @see DefaultConversion#castOrCopy(Conversion)
+     */
+    static DefaultConversion forConversion(final Conversion object) {
+        if (object instanceof CylindricalProjection) {
+            return (object instanceof DefaultCylindricalProjection) ? ((DefaultCylindricalProjection)
object)
+                   : new DefaultCylindricalProjection((CylindricalProjection) object);
+        }
+        if (object instanceof ConicProjection) {
+            return (object instanceof DefaultConicProjection) ? ((DefaultConicProjection)
object)
+                   : new DefaultConicProjection((ConicProjection) object);
+        }
+        if (object instanceof PlanarProjection) {
+            return (object instanceof DefaultPlanarProjection) ? ((DefaultPlanarProjection)
object)
+                   : new DefaultPlanarProjection((PlanarProjection) object);
+        }
+        if (object instanceof Projection) {
+            return (object instanceof DefaultProjection) ? ((DefaultProjection) object)
+                   : new DefaultProjection((Projection) object);
+        }
+        if (object == null || object instanceof DefaultConversion) {
+            return (DefaultConversion) object;
+        }
+        return new DefaultConversion(object);
+    }
 }



Mime
View raw message