You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2022/08/03 16:51:45 UTC
[sis] 01/03: Avoid an `AssertionError` when sub-classing a `Builder` subclass. Allow subclassing of `GeodeticObjectBuilder`.
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 553f9f4f8708a56ba72c1d5a6e310a98648825ea
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Aug 3 16:47:04 2022 +0200
Avoid an `AssertionError` when sub-classing a `Builder` subclass.
Allow subclassing of `GeodeticObjectBuilder`.
---
.../internal/referencing/GeodeticObjectBuilder.java | 18 +++++++++++-------
.../main/java/org/apache/sis/referencing/Builder.java | 6 ++++--
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java
index 30f63540a5..62ef1b36ee 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java
@@ -23,6 +23,7 @@ import java.util.Locale;
import javax.measure.Unit;
import javax.measure.quantity.Time;
import javax.measure.quantity.Length;
+import org.opengis.util.GenericName;
import org.opengis.util.FactoryException;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.parameter.ParameterNotFoundException;
@@ -63,11 +64,11 @@ import org.apache.sis.referencing.IdentifiedObjects;
* However this class may move in a public package later if we feel confident that its API is mature enough.</p>
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.3
* @since 0.6
* @module
*/
-public final class GeodeticObjectBuilder extends Builder<GeodeticObjectBuilder> {
+public class GeodeticObjectBuilder extends Builder<GeodeticObjectBuilder> {
/**
* The geodetic datum, or {@code null} if none.
*/
@@ -517,8 +518,7 @@ public final class GeodeticObjectBuilder extends Builder<GeodeticObjectBuilder>
/**
* Replaces the component starting at given index by the given component. This method can be used for replacing
* e.g. the horizontal component of a CRS, or the vertical component, <i>etc.</i>. If a new compound CRS needs
- * to be created and a {@linkplain #addName(org.opengis.util.GenericName) name has been specified}, that name
- * will be used.
+ * to be created and a {@linkplain #addName(GenericName) name has been specified}, that name will be used.
*
* <h4>Limitations</h4>
* Current implementation can replace exactly one component of {@link CompoundCRS}.
@@ -538,7 +538,11 @@ public final class GeodeticObjectBuilder extends Builder<GeodeticObjectBuilder>
final int srcDim = ReferencingUtilities.getDimension(source);
final int repDim = ReferencingUtilities.getDimension(replacement);
if (firstDimension == 0 && srcDim == repDim) {
- return replacement;
+ /*
+ * conceptually return the replacement. But returning the original instance if applicable
+ * allows the caller to detect that a compound CRS does not need to be replaced.
+ */
+ return source.equals(replacement) ? source : replacement;
}
ArgumentChecks.ensureValidIndex(srcDim - repDim, firstDimension);
if (source instanceof CompoundCRS) {
@@ -556,8 +560,8 @@ public final class GeodeticObjectBuilder extends Builder<GeodeticObjectBuilder>
Object ids = properties.remove(IdentifiedObject.IDENTIFIERS_KEY);
final CoordinateReferenceSystem nc = replaceComponent(c, firstDimension - lower, replacement);
/*
- * Restore the names and identifiers before to create the final CompoundCRS. If no name was specified,
- * reuse the primary name of existing CRS but not the identifiers.
+ * Restore the names and identifiers before to create the final CompoundCRS.
+ * If no name was specified, reuse the primary name of existing CRS but not the identifiers.
*/
if (name == null) {
name = source.getName();
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
index 81e054b5c2..50eb32159a 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
@@ -42,7 +42,7 @@ import static org.apache.sis.util.ArgumentChecks.*;
/**
- * Base class of builders for various kind of {@link IdentifiedObject}. This class provides convenience methods
+ * Base class of builders for various kinds of {@link IdentifiedObject}. This class provides convenience methods
* for filling the {@link #properties} map to be given to an {@link org.opengis.referencing.ObjectFactory}.
* The main properties are:
*
@@ -230,7 +230,7 @@ public abstract class Builder<B extends Builder<B>> {
* Verifies that {@code B} in {@code <B extends Builder<B>} is the expected class.
* This method is for assertion purposes only.
*/
- private static boolean verifyParameterizedType(final Class<?> expected) {
+ private static boolean verifyParameterizedType(Class<?> expected) {
for (Class<?> c = expected; c != null; c = c.getSuperclass()) {
Type type = c.getGenericSuperclass();
if (type instanceof ParameterizedType) {
@@ -240,6 +240,8 @@ public abstract class Builder<B extends Builder<B>> {
if (type == expected) return true;
throw new AssertionError(type);
}
+ } else {
+ expected = c.getSuperclass();
}
}
return false;