This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 810626ad874ff2cf3bb8905ba58f5cb2bf41fe0e
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Jul 10 16:43:37 2024 +0200

    Remove the `lastMethod` field from `DefaultMathTransformFactory`,
    since the deprecated method reading it has been removed.
    This change is appled on the `geoapi-4.0` branch only.
---
 .../internal/ParameterizedTransformBuilder.java          |  7 ++++---
 .../operation/transform/DefaultMathTransformFactory.java | 16 ----------------
 .../operation/transform/MathTransformBuilder.java        |  1 -
 .../transform/CoordinateSystemTransformTest.java         |  2 +-
 4 files changed, 5 insertions(+), 21 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ParameterizedTransformBuilder.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ParameterizedTransformBuilder.java
index 735edeafd7..d439168dd4 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ParameterizedTransformBuilder.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ParameterizedTransformBuilder.java
@@ -654,8 +654,7 @@ public class ParameterizedTransformBuilder extends 
MathTransformBuilder implemen
             if (provider instanceof AbstractProvider) {
                 provider = ((AbstractProvider) provider).variantFor(transform);
             }
-            // A call to `unique` needs to be last because it set 
`factory.lastMethod` as a side-effect.
-            return unique(swapAndScaleAxes(unique(transform)));
+            return swapAndScaleAxes(unique(transform));
         } catch (FactoryException exception) {
             if (warning != null) {
                 exception.addSuppressed(warning);
@@ -785,7 +784,9 @@ public class ParameterizedTransformBuilder extends 
MathTransformBuilder implemen
          * created transform; it does not change the operation.
          */
         if (normalized instanceof ParameterizedAffine && !(mt instanceof 
ParameterizedAffine)) {
-            return ((ParameterizedAffine) normalized).newTransform(mt);
+            if (mt != (mt = ((ParameterizedAffine) 
normalized).newTransform(mt))) {
+                mt = unique(mt);
+            }
         }
         return mt;
     }
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
index a7daa49664..9e1638086d 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
@@ -180,11 +180,6 @@ public class DefaultMathTransformFactory extends 
AbstractFactory implements Math
      */
     private final Map<Class<?>, OperationMethodSet> methodsByType;
 
-    /**
-     * The last coordinate operation method used by a {@code create(…)} 
constructor.
-     */
-    final ThreadLocal<OperationMethod> lastMethod;
-
     /**
      * The math transforms created so far. This pool is used in order to 
return instances of existing
      * math transforms when possible. If {@code null}, then no pool should be 
used. A null value is
@@ -276,7 +271,6 @@ public class DefaultMathTransformFactory extends 
AbstractFactory implements Math
         this.methods  = Objects.requireNonNull(methods);
         methodsByName = new ConcurrentHashMap<>();
         methodsByType = new IdentityHashMap<>();
-        lastMethod    = new ThreadLocal<>();
         pool          = new WeakHashSet<>(MathTransform.class);
         parser        = new AtomicReference<>();
     }
@@ -288,7 +282,6 @@ public class DefaultMathTransformFactory extends 
AbstractFactory implements Math
         methods       = parent.methods;
         methodsByName = parent.methodsByName;
         methodsByType = parent.methodsByType;
-        lastMethod    = new ThreadLocal<>();
         pool          = null;
         parser        = parent.parser;
         oppositeCachingPolicy = parent;
@@ -889,7 +882,6 @@ public class DefaultMathTransformFactory extends 
AbstractFactory implements Math
     {
         ArgumentChecks.ensureNonNull("source", source);
         ArgumentChecks.ensureNonNull("target", target);
-        lastMethod.remove();                                // In case an 
exception is thrown before completion.
         final var builder = builder(Constants.COORDINATE_SYSTEM_CONVERSION);
         builder.setSourceAxes(source, ellipsoid);
         builder.setTargetAxes(target, ellipsoid);
@@ -912,11 +904,6 @@ public class DefaultMathTransformFactory extends 
AbstractFactory implements Math
      */
     @Override
     public MathTransform createAffineTransform(final Matrix matrix) throws 
FactoryException {
-        /*
-         * Performance note: we could set lastMethod to the "Affine" operation 
method provider, but we do not
-         * because setting this value is not free (e.g. it depends on matrix 
size) and it is rarely needed.
-         */
-        lastMethod.remove();
         return unique(MathTransforms.linear(matrix));
     }
 
@@ -955,7 +942,6 @@ public class DefaultMathTransformFactory extends 
AbstractFactory implements Math
                                                      final MathTransform tr2)
             throws FactoryException
     {
-        lastMethod.remove();
         ArgumentChecks.ensureNonNull("tr1", tr1);
         ArgumentChecks.ensureNonNull("tr2", tr2);
         final MathTransform tr;
@@ -996,7 +982,6 @@ public class DefaultMathTransformFactory extends 
AbstractFactory implements Math
                                                     final int 
numTrailingCoordinates)
             throws FactoryException
     {
-        lastMethod.remove();
         final MathTransform tr;
         try {
             tr = MathTransforms.passThrough(firstAffectedCoordinate, 
subTransform, numTrailingCoordinates);
@@ -1026,7 +1011,6 @@ public class DefaultMathTransformFactory extends 
AbstractFactory implements Math
      */
     @Override
     public MathTransform createFromWKT(final String wkt) throws 
FactoryException {
-        lastMethod.remove();
         ArgumentChecks.ensureNonEmpty("wkt", wkt);
         Parser p = parser.getAndSet(null);
         if (p == null) try {
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/MathTransformBuilder.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/MathTransformBuilder.java
index 9ca49145f5..05ec64e681 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/MathTransformBuilder.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/MathTransformBuilder.java
@@ -91,7 +91,6 @@ public abstract class MathTransformBuilder implements 
MathTransform.Builder {
     protected MathTransform unique(MathTransform result) {
         if (factory instanceof DefaultMathTransformFactory) {
             final var df = (DefaultMathTransformFactory) factory;
-            df.lastMethod.set(getMethod().orElse(null));
             result = df.unique(result);
         }
         return result;
diff --git 
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java
 
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java
index 60e492eb83..84ff5333ff 100644
--- 
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java
+++ 
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java
@@ -99,7 +99,7 @@ public final class CoordinateSystemTransformTest extends 
TransformTestCase {
     }
 
     /**
-     * Verifies that {@link #lastMethod} has the expected value.
+     * Verifies that {@code builder.getMethod()} has the expected value.
      */
     private void assertMethodEquals(final String expected) {
         final OperationMethod method = builder.getMethod().orElseThrow();

Reply via email to