sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/03: Fix the name of the TemporalCRS created from CommonCRS.Temporal.JAVA.
Date Wed, 07 Jul 2021 09:53:02 GMT
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 0123dee40cc95dd6c3b7c19f654182f8ef85a759
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jul 7 10:32:46 2021 +0200

    Fix the name of the TemporalCRS created from CommonCRS.Temporal.JAVA.
---
 .../java/org/apache/sis/referencing/CommonCRS.java  | 16 +++++++++++-----
 .../org/apache/sis/referencing/CommonCRSTest.java   | 21 +++++++++++++++++++++
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
index e064e18..e132695 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
@@ -1661,7 +1661,8 @@ public enum CommonCRS {
          *   <tr><td>Julian</td>             <td>{@link #JULIAN}</td></tr>
          *   <tr><td>Modified Julian</td>    <td>{@link #MODIFIED_JULIAN}</td></tr>
          *   <tr><td>Truncated Julian</td>   <td>{@link #TRUNCATED_JULIAN}</td></tr>
-         *   <tr><td>Unix/POSIX or Java</td> <td>{@link #UNIX}</td></tr>
+         *   <tr><td>Unix/POSIX</td>         <td>{@link #UNIX}</td></tr>
+         *   <tr><td>Java {@link Date}</td>  <td>{@link #JAVA}</td></tr>
          * </table></blockquote>
          *
          * @return the CRS associated to this enum.
@@ -1675,7 +1676,13 @@ public enum CommonCRS {
                     object = crs(cached);
                     if (object == null) {
                         final TemporalDatum datum = datum();
-                        object = new DefaultTemporalCRS(IdentifiedObjects.getProperties(datum,
exclude()), datum, cs());
+                        final Map<String,?> properties;
+                        if (this == JAVA) {
+                            properties = properties(Vocabulary.formatInternational(key, "Java"));
+                        } else {
+                            properties = IdentifiedObjects.getProperties(datum, exclude());
+                        }
+                        object = new DefaultTemporalCRS(properties, datum, cs());
                         cached = object;
                     }
                 }
@@ -1744,12 +1751,11 @@ public enum CommonCRS {
                     object = datum(cached);
                     if (object == null) {
                         if (this == UNIX) {
-                            object = JAVA.datum(); // Share the same instance for UNIX and
JAVA.
+                            object = JAVA.datum();          // Share the same instance for
UNIX and JAVA.
                         } else {
                             final Map<String,?> properties;
                             if (key == Vocabulary.Keys.Time_1) {
-                                properties = properties(Vocabulary.formatInternational(
-                                        key, (this == JAVA) ? "Java" : "Unix/POSIX"));
+                                properties = properties(Vocabulary.formatInternational(key,
"Unix/POSIX"));
                             } else {
                                 properties = properties(key);
                             }
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
index d0e31e6..7b84e2f 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
@@ -21,6 +21,7 @@ import java.util.Map;
 import java.util.HashMap;
 import java.time.Instant;
 import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.crs.GeographicCRS;
@@ -277,10 +278,30 @@ public final strictfp class CommonCRSTest extends TestCase {
             assertSame  (name, crs.getDatum(), e.datum());              // Datum after CRS
creation.
             assertEquals(name, epoch, format(origin));
             assertEquals(name, days, origin.getTime() / DAY_LENGTH - julianEpoch, 0);
+            switch (e) {
+                case JAVA: {
+                    assertNameContains(datum, "Unix/POSIX");
+                    assertNameContains(crs,   "Java");
+                    break;
+                }
+                case UNIX: {
+                    assertNameContains(datum, "Unix/POSIX");
+                    assertNameContains(crs,   "Unix/POSIX");
+                    break;
+                }
+            }
         }
     }
 
     /**
+     * Verifies that the name of given object contains the given word.
+     */
+    private static void assertNameContains(final IdentifiedObject object, final String word)
{
+        final String name = object.getName().getCode();
+        assertTrue(name, name.contains(word));
+    }
+
+    /**
      * Tests {@link CommonCRS#universal(double, double)} with Universal Transverse Mercator
(UTM) projections.
      *
      * @since 0.7

Mime
View raw message