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

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


The following commit(s) were added to refs/heads/geoapi-3.1 by this push:
     new ff9d7d107b Port methods from the `main` branch for deprecated `Datum` 
methods.
ff9d7d107b is described below

commit ff9d7d107b36a8828a74990e64e14d5f54d8a366
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Jul 17 21:02:03 2024 +0200

    Port methods from the `main` branch for deprecated `Datum` methods.
---
 .../apache/sis/referencing/datum/PseudoDatum.java  | 77 +++++++++++++++++++++-
 1 file changed, 76 insertions(+), 1 deletion(-)

diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/PseudoDatum.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/PseudoDatum.java
index 4ee7b6837c..0ea021b3ec 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/PseudoDatum.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/PseudoDatum.java
@@ -40,6 +40,7 @@ import org.apache.sis.referencing.GeodeticException;
 
 // Specific to the main and geoapi-3.1 branches:
 import java.util.Date;
+import org.opengis.metadata.extent.Extent;
 import org.opengis.referencing.ReferenceIdentifier;
 
 
@@ -189,6 +190,8 @@ public abstract class PseudoDatum<D extends Datum> 
implements Datum, LenientComp
      * @return the datum or pseudo-datum of the given <abbr>CRS</abbr>.
      * @throws NullPointerException if the given argument is {@code null},
      *         or if both the datum and datum ensemble are null.
+     *
+     * @since 2.0 (temporary version number until this branch is released)
      */
     public static ParametricDatum of(final ParametricCRS crs) {
         ParametricDatum datum = crs.getDatum();
@@ -268,6 +271,42 @@ public abstract class PseudoDatum<D extends Datum> 
implements Datum, LenientComp
         return ensemble.getDomains();
     }
 
+    /**
+     * Returns the domain of validity common to all datum members, if any.
+     *
+     * @return value common to all ensemble members, or {@code null} if none.
+     * @hidden
+     */
+    @Override
+    @Deprecated
+    public Extent getDomainOfValidity() {
+        return getCommonNullableValue(Datum::getDomainOfValidity);
+    }
+
+    /**
+     * Returns the scope common to all datum members, if any.
+     *
+     * @return value common to all ensemble members, or {@code null} if none.
+     * @hidden
+     */
+    @Override
+    @Deprecated
+    public InternationalString getScope() {
+        return getCommonNullableValue(Datum::getScope);
+    }
+
+    /**
+     * Returns the anchor point common to all datum members, if any.
+     *
+     * @return value common to all ensemble members, or {@code null} if none.
+     * @hidden
+     */
+    @Override
+    @Deprecated
+    public InternationalString getAnchorPoint() {
+        return getCommonNullableValue(Datum::getAnchorPoint);
+    }
+
     /**
      * Returns an anchor definition which is common to all members of the 
datum ensemble.
      * If the value is not the same for all members (including the case where 
a member
@@ -292,6 +331,18 @@ public abstract class PseudoDatum<D extends Datum> 
implements Datum, LenientComp
         return getCommonOptionalValue(Datum::getAnchorEpoch);
     }
 
+    /**
+     * Returns the realization epoch common to all datum members, if any.
+     *
+     * @return value common to all ensemble members, or {@code null} if none.
+     * @hidden
+     */
+    @Override
+    @Deprecated
+    public Date getRealizationEpoch() {
+        return getCommonNullableValue(Datum::getRealizationEpoch);
+    }
+
     /**
      * Returns a publication date which is common to all members of the datum 
ensemble.
      * If the value is not the same for all members (including the case where 
a member
@@ -317,6 +368,30 @@ public abstract class PseudoDatum<D extends Datum> 
implements Datum, LenientComp
         return getCommonOptionalValue(Datum::getConventionalRS);
     }
 
+    /**
+     * Returns an optional value which is common to all ensemble members.
+     * If all members do not have the same value, returns {@code null}.
+     *
+     * @param  <V>     type of value.
+     * @param  getter  method to invoke on each member for getting the value.
+     * @return a value common to all members, or {@code null} if none.
+     */
+    final <V> V getCommonNullableValue(final Function<D, V> getter) {
+        final Iterator<D> it = ensemble.getMembers().iterator();
+check:  if (it.hasNext()) {
+            final V value = getter.apply(it.next());
+            if (value != null) {
+                while (it.hasNext()) {
+                    if (!value.equals(getter.apply(it.next()))) {
+                        break check;
+                    }
+                }
+                return value;
+            }
+        }
+        return null;
+    }
+
     /**
      * Returns an optional value which is common to all ensemble members.
      * If all members do not have the same value, returns an empty value.
@@ -525,7 +600,7 @@ check:  if (it.hasNext()) {
         @Override
         @Deprecated
         public VerticalDatumType getVerticalDatumType() {
-            return 
getCommonMandatoryValue(VerticalDatum::getVerticalDatumType);
+            return getCommonNullableValue(VerticalDatum::getVerticalDatumType);
         }
     }
 

Reply via email to