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 f97dcee389051880134f53ef52571973b5f55682
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sun Nov 26 19:10:58 2023 +0100

    Miscellaneous utilities:
    - CommonCRS.Temporal.TROPICAL_YEAR
    - QuantityFormat.parseNumber(…)
    - IOUtilities.toBuffered(Reader)
---
 .../main/org/apache/sis/console/package-info.java  |  2 +-
 .../main/org/apache/sis/referencing/CommonCRS.java | 57 +++++++++++++---------
 .../org/apache/sis/referencing/package-info.java   |  2 +-
 .../org/apache/sis/referencing/CommonCRSTest.java  |  1 +
 .../main/org/apache/sis/io/stream/IOUtilities.java | 16 ++++++
 .../org/apache/sis/storage/csv/StoreProvider.java  |  2 +-
 .../org/apache/sis/measure/QuantityFormat.java     | 20 +++++++-
 .../main/org/apache/sis/measure/package-info.java  |  2 +-
 .../main/org/apache/sis/util/Classes.java          |  1 +
 .../org/apache/sis/util/collection/Containers.java |  4 ++
 .../org/apache/sis/util/resources/Vocabulary.java  | 10 ++++
 .../sis/util/resources/Vocabulary.properties       |  2 +
 .../sis/util/resources/Vocabulary_fr.properties    |  2 +
 13 files changed, 94 insertions(+), 27 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/package-info.java
 
b/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/package-info.java
index e5dd6749b0..1a880bf399 100644
--- 
a/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/package-info.java
+++ 
b/endorsed/src/org.apache.sis.console/main/org/apache/sis/console/package-info.java
@@ -25,7 +25,7 @@
  * the following environment variable can be set:
  *
  * {@snippet lang="shell" :
- *   export 
JDK_JAVA_OPTIONS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=127.0.0.1:8000
+ *   export JDK_JAVA_OPTIONS="-enableassertions 
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=127.0.0.1:8000"
  *   }
  *
  * <h2>SIS installation on remote machines</h2>
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CommonCRS.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CommonCRS.java
index 56979288ba..62a21cb608 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CommonCRS.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CommonCRS.java
@@ -143,7 +143,7 @@ import static 
org.apache.sis.util.internal.StandardDateFormat.MILLISECONDS_PER_D
  * </table></blockquote>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.4
+ * @version 1.5
  *
  * @see org.apache.sis.referencing.factory.CommonAuthorityFactory
  *
@@ -1511,12 +1511,13 @@ public enum CommonCRS {
      *   <tr><td>Java time</td>        <td>{@code SIS:JavaTime}</td>           
 <td>CRS</td>         <td>{@link #JAVA}</td></tr>
      *   <tr><td>Julian</td>           <td>{@code OGC:JulianDate}</td>         
 <td>CRS, Datum</td>  <td>{@link #JULIAN}</td></tr>
      *   <tr><td>Modified Julian</td>  <td>{@code SIS:ModifiedJulianDate}</td> 
 <td>CRS, Datum</td>  <td>{@link #MODIFIED_JULIAN}</td></tr>
+     *   <tr><td>Tropical year</td>    <td>{@code SIS:TropicalYear}</td>       
 <td>CRS</td>         <td>{@link #TROPICAL_YEAR}</td></tr>
      *   <tr><td>Truncated Julian</td> <td>{@code 
OGC:TruncatedJulianDate}</td> <td>CRS, Datum</td>  <td>{@link 
#TRUNCATED_JULIAN}</td></tr>
      *   <tr><td>Unix/POSIX time</td>  <td>{@code OGC:UnixTime}</td>           
 <td>CRS, Datum</td>  <td>{@link #UNIX}</td></tr>
      * </table></blockquote>
      *
      * @author  Martin Desruisseaux (Geomatys)
-     * @version 1.3
+     * @version 1.5
      *
      * @see Engineering#TIME
      *
@@ -1575,6 +1576,23 @@ public enum CommonCRS {
         DUBLIN_JULIAN(Vocabulary.Keys.DublinJulian, -25568L * 
MILLISECONDS_PER_DAY + MILLISECONDS_PER_DAY/2,
                       "DublinJulian", false),
 
+        /**
+         * Time measured in units of tropical years since January 1, 2000 at 
00:00 UTC.
+         * The length of a tropical year is defined by the International Union 
of Geological Sciences (IUGS)
+         * as exactly 31556925.445 seconds (approximately 365.24219 days) 
taken as the length of the tropical
+         * year in the year 2000. Apache SIS extends this definition by using 
January 1st, 2000 as the epoch
+         * (by contrast, the IUGS definition is only about duration).
+         *
+         * <h4>Application to geodesy</h4>
+         * The tropical year is the unit of measurement used in EPSG geodetic 
database for year duration.
+         * It it used for rate of changes such as "centimeters per year". Its 
identifier is EPSG:1029.
+         *
+         * @see Units#TROPICAL_YEAR
+         *
+         * @since 1.5
+         */
+        TROPICAL_YEAR(Vocabulary.Keys.TropicalYear, 946684800000L, 
"TropicalYear", false),
+
         /**
          * Time measured as seconds since January 1st, 1970 at 00:00 UTC.
          */
@@ -1707,6 +1725,7 @@ public enum CommonCRS {
          *   <tr><td>Dublin Julian</td>      <td>{@link 
#DUBLIN_JULIAN}</td></tr>
          *   <tr><td>Julian</td>             <td>{@link #JULIAN}</td></tr>
          *   <tr><td>Modified Julian</td>    <td>{@link 
#MODIFIED_JULIAN}</td></tr>
+         *   <tr><td>Tropical year</td>      <td>{@link 
#TROPICAL_YEAR}</td></tr>
          *   <tr><td>Truncated Julian</td>   <td>{@link 
#TRUNCATED_JULIAN}</td></tr>
          *   <tr><td>Unix/POSIX</td>         <td>{@link #UNIX}</td></tr>
          *   <tr><td>Java {@link Date}</td>  <td>{@link #JAVA}</td></tr>
@@ -1746,32 +1765,26 @@ public enum CommonCRS {
          */
         @SuppressWarnings("fallthrough")
         private TimeCS cs() {
-            final Map<String,?> cs, axis;
-            Unit<Time> unit = Units.SECOND;
+            final Unit<Time> unit;
             switch (this) {
                 default: {
                     // Share the coordinate system created for truncated 
Julian.
                     return TRUNCATED_JULIAN.crs().getCoordinateSystem();
                 }
-                case TRUNCATED_JULIAN: {
-                    unit = Units.DAY;
-                    // Fall through
-                }
-                case UNIX: {
-                    // Share the NamedIdentifier created for Java time.
-                    final TimeCS share = JAVA.crs().getCoordinateSystem();
-                    cs   = IdentifiedObjects.getProperties(share, exclude());
-                    axis = IdentifiedObjects.getProperties(share.getAxis(0), 
exclude());
-                    break;
-                }
-                case JAVA: {
-                    // Create all properties for a new coordinate system.
-                    cs   = properties(Vocabulary.Keys.Temporal);
-                    axis = properties(Vocabulary.Keys.Time);
-                    unit = Units.MILLISECOND;
-                    break;
-                }
+                case TRUNCATED_JULIAN: unit = Units.DAY;           break;
+                case TROPICAL_YEAR:    unit = Units.TROPICAL_YEAR; break;
+                case UNIX:             unit = Units.SECOND;        break;
+                case JAVA:             unit = Units.MILLISECOND;   break;
+            }
+            final Map<String,?> axis;
+            if (this == TRUNCATED_JULIAN) {                 // Arbitrary CRS 
to be created before all other CRS.
+                axis = properties(Vocabulary.Keys.Time);
+            } else {
+                // Share the NamedIdentifier created for Truncated Julian time.
+                final TimeCS share = 
TRUNCATED_JULIAN.crs().getCoordinateSystem();
+                axis = IdentifiedObjects.getProperties(share.getAxis(0), 
exclude());
             }
+            final Map<String,?> cs = 
properties(Vocabulary.formatInternational(Vocabulary.Keys.Temporal_1, unit));
             return new DefaultTimeCS(cs, new DefaultCoordinateSystemAxis(axis, 
"t", AxisDirection.FUTURE, unit));
         }
 
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/package-info.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/package-info.java
index 8362780712..5224c67d0e 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/package-info.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/package-info.java
@@ -94,7 +94,7 @@
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Guilhem Legal (Geomatys)
- * @version 1.4
+ * @version 1.5
  * @since   0.4
  */
 @XmlSchema(location = 
"http://schemas.opengis.net/gml/3.2.1/referenceSystems.xsd";,
diff --git 
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CommonCRSTest.java
 
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CommonCRSTest.java
index affca1c81e..b7bd6b63f6 100644
--- 
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CommonCRSTest.java
+++ 
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CommonCRSTest.java
@@ -275,6 +275,7 @@ public final class CommonCRSTest extends TestCase {
                 case DUBLIN_JULIAN:    epoch = "1899-12-31 12:00:00"; days = 
2415020.0; break;
                 case MODIFIED_JULIAN:  epoch = "1858-11-17 00:00:00"; days = 
2400000.5; break;
                 case JULIAN:           epoch = "4713-01-01 12:00:00"; days = 
0;         break;
+                case TROPICAL_YEAR:    epoch = "2000-01-01 00:00:00"; days = 
2451544.5; break;
                 default: throw new AssertionError(e);
             }
             final String        name   = e.name();
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/IOUtilities.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/IOUtilities.java
index e2fbe4996a..516a4cd6f5 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/IOUtilities.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/IOUtilities.java
@@ -20,6 +20,7 @@ import java.util.Locale;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.LineNumberReader;
+import java.io.BufferedReader;
 import java.io.Reader;
 import java.io.DataInput;
 import java.io.DataOutput;
@@ -540,6 +541,21 @@ public final class IOUtilities extends Static {
         }
     }
 
+    /**
+     * Returns the given reader as a buffered reader.
+     * The reader is wrapped if needed.
+     *
+     * @param  reader  the reader to return as a buffered reader.
+     * @return the given reader returned directly or wrapped.
+     */
+    public static BufferedReader toBuffered(final Reader reader) {
+        if (reader instanceof BufferedReader) {
+            return (BufferedReader) reader;
+        } else {
+            return new LineNumberReader(reader);
+        }
+    }
+
     /**
      * Converts the given output stream to an input stream. It is caller's 
responsibility to flush
      * the stream and reset its position to the beginning of file before to 
invoke this method.
diff --git 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/csv/StoreProvider.java
 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/csv/StoreProvider.java
index d762b40e7c..455864ab9a 100644
--- 
a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/csv/StoreProvider.java
+++ 
b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/csv/StoreProvider.java
@@ -105,7 +105,7 @@ public final class StoreProvider extends 
URIDataStore.Provider {
 
         /**
          * Returns the value to be returned by {@link 
StoreProvider#probeContent(StorageConnector)}
-         * for the given WKT keyword. This method changes the case to match 
the one used in the keywords map,
+         * for the given keyword. This method changes the case to match the 
one used in the keywords map,
          * then verify if the keyword that we found is one of the known WKT 
keywords. Keywords with the "CRS"
          * suffix are WKT 2 while keywords with the "CS" suffix are WKT 1.
          */
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/QuantityFormat.java
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/QuantityFormat.java
index 0fd2aa8e36..6c9f326e22 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/QuantityFormat.java
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/QuantityFormat.java
@@ -35,7 +35,7 @@ import org.apache.sis.util.resources.Errors;
  * Parses and formats numbers with units of measurement.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.4
+ * @version 1.5
  *
  * @see NumberFormat
  * @see UnitFormat
@@ -231,6 +231,24 @@ public class QuantityFormat extends Format implements 
javax.measure.format.Quant
         return null;
     }
 
+    /**
+     * Parses only a number without units of measurement.
+     * This method is sometime useful when the number is in a context where 
the unit is not repeated.
+     *
+     * @param  source  the number to parse.
+     * @return the number parsed from the specified text.
+     * @throws MeasurementParseException if the given text cannot be parsed.
+     * @since  1.5
+     */
+    public Number parseNumber(final String source) throws 
MeasurementParseException {
+        final var pos = new ParsePosition(0);
+        final Number value = numberFormat.parse(source, pos);
+        if (value != null) {
+            return value;
+        }
+        throw new 
MeasurementParseException(Errors.format(Errors.Keys.CanNotParse_1, source), 
source, pos.getErrorIndex());
+    }
+
     /**
      * Returns a clone of this format.
      *
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/package-info.java
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/package-info.java
index 49fe43094f..4f26b26f98 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/package-info.java
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/package-info.java
@@ -97,7 +97,7 @@
  *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
  * @author  Alexis Manin (Geomatys)
- * @version 1.4
+ * @version 1.5
  * @since   0.3
  */
 package org.apache.sis.measure;
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/Classes.java 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/Classes.java
index ac05516c74..95c94ba41e 100644
--- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/Classes.java
+++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/Classes.java
@@ -115,6 +115,7 @@ public final class Classes extends Static {
                 do element = element.getComponentType();
                 while (element!=null && ++change != 0);
             } else if (element != Void.TYPE) {
+                // TODO: use Class.arrayType() with JDK12.
                 final StringBuilder buffer = new StringBuilder();
                 do buffer.insert(0, '[');
                 while (--change != 0);
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/Containers.java
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/Containers.java
index bcb18b24f4..599301e770 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/Containers.java
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/Containers.java
@@ -259,6 +259,10 @@ public final class Containers extends Static {
      * {@link java.util.HashSet} as well, which are built on top of {@code 
HashMap}.
      * However, it is not needed for {@link java.util.IdentityHashMap}.</p>
      *
+     * <h4>Future evolution</h4>
+     * This method may be deprecated in favor of {@code 
HashMap.newHashMap(int)}
+     * when Apache SIS will be allowed to compile for JDK19.
+     *
      * @param  count  the number of elements to be put into the hash map or 
hash set.
      * @return the minimal initial capacity to be given to the hash map 
constructor.
      */
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary.java
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary.java
index 9a581e9c82..7b67be2cf2 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary.java
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary.java
@@ -1219,6 +1219,11 @@ public class Vocabulary extends IndexedResourceBundle {
          */
         public static final short TemporalExtent = 192;
 
+        /**
+         * Temporal ({0})
+         */
+        public static final short Temporal_1 = 276;
+
         /**
          * Temporary files
          */
@@ -1284,6 +1289,11 @@ public class Vocabulary extends IndexedResourceBundle {
          */
         public static final short Transparent = 249;
 
+        /**
+         * Tropical year
+         */
+        public static final short TropicalYear = 275;
+
         /**
          * True
          */
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary.properties
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary.properties
index 4e60a35b3c..e9abdbb809 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary.properties
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary.properties
@@ -247,6 +247,7 @@ SubsetOf_1              = Subset of {0}
 Summary                 = Summary
 SupersededBy_1          = Superseded by {0}.
 Temporal                = Temporal
+Temporal_1              = Temporal ({0})
 TemporalExtent          = Temporal extent
 TemporaryFiles          = Temporary files
 Thermal                 = Thermal
@@ -261,6 +262,7 @@ Transformation          = Transformation
 TransformationAccuracy  = Transformation accuracy
 Transparency            = Transparency
 Transparent             = Transparent
+TropicalYear            = Tropical year
 TruncatedJulian         = Truncated Julian
 True                    = True
 Type                    = Type
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary_fr.properties
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary_fr.properties
index 5c2178784e..67bebdcb73 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary_fr.properties
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Vocabulary_fr.properties
@@ -254,6 +254,7 @@ SubsetOf_1              = Sous-ensemble de {0}
 Summary                 = R\u00e9sum\u00e9
 SupersededBy_1          = Remplac\u00e9 par {0}.
 Temporal                = Temporel
+Temporal_1              = Temporel ({0})
 TemporalExtent          = Plage temporelle
 TemporaryFiles          = Fichiers temporaires
 Thermal                 = Thermique
@@ -268,6 +269,7 @@ Transformation          = Transformation
 TransformationAccuracy  = Pr\u00e9cision de la transformation
 Transparency            = Transparence
 Transparent             = Transparent
+TropicalYear            = Ann\u00e9e tropique
 TruncatedJulian         = Julien tronqu\u00e9
 True                    = Vrai
 Type                    = Type

Reply via email to