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 7812f5c6af557e963b3b52ae50ab2c392fe53348 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Feb 21 16:13:32 2024 +0100 Add units of measurement for knot and tonne. --- .../org/apache/sis/measure/UnitNames.properties | 2 + .../apache/sis/measure/UnitNames_en_US.properties | 1 + .../org/apache/sis/measure/UnitNames_fr.properties | 1 + .../main/org/apache/sis/measure/Units.java | 53 ++++++++++++++++++++-- .../org/apache/sis/measure/UnitFormatTest.java | 2 + .../test/org/apache/sis/measure/UnitsTest.java | 7 +-- 6 files changed, 59 insertions(+), 7 deletions(-) diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames.properties b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames.properties index 8b69549be1..7cf0da8c0d 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames.properties +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames.properties @@ -30,6 +30,7 @@ J=joule kg=kilogram km=kilometre km\u2215h=kilometres per hour +kn=knot L=litre lm=lumen lx=lux @@ -56,6 +57,7 @@ rad\u2215s=radians per second s=second S=siemens sr=steradian +t=tonne T=tesla unity=unity V=volt diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames_en_US.properties b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames_en_US.properties index aceb2737d8..94d76daee2 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames_en_US.properties +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames_en_US.properties @@ -9,3 +9,4 @@ m\u00b3=cubic meter mi=international mile mm=millimeter nm=nanometer +t=metric ton diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames_fr.properties b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames_fr.properties index b087c0099a..bb1a4cf951 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames_fr.properties +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/UnitNames_fr.properties @@ -16,6 +16,7 @@ in=pouce kg=kilogramme km=kilom\u00e8tre km\u2215h=kilom\u00e8tres par heure +kn=n\u0153ud M=mille marin international m=m\u00e8tre m\u00b2=m\u00e8tre carr\u00e9 diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/Units.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/Units.java index 8a66199f21..493b2a5476 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/Units.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/Units.java @@ -75,7 +75,7 @@ import static org.apache.sis.measure.UnitRegistry.PREFIXABLE; * * @author Martin Desruisseaux (IRD, Geomatys) * @author Alexis Manin (Geomatys) - * @version 1.4 + * @version 1.5 * @since 0.3 */ public final class Units extends Static { @@ -597,7 +597,7 @@ public final class Units extends Static { * <table class="compact" style="margin-left:30px; line-height:1.25"> * <caption>Related units</caption> * <tr><td>SI speed units:</td> <td style="word-spacing:1em"><u><b>{@code METRES_PER_SECOND}</b></u>.</td></tr> - * <tr><td>Non-SI units:</td> <td style="word-spacing:1em">{@link #KILOMETRES_PER_HOUR}.</td></tr> + * <tr><td>Non-SI units:</td> <td style="word-spacing:1em">{@link #KILOMETRES_PER_HOUR}, {@link #KNOT}.</td></tr> * <tr><td>Components:</td> <td style="word-spacing:0.5em">{@link #METRE} ∕ {@link #SECOND}</td></tr> * </table> * @@ -613,7 +613,7 @@ public final class Units extends Static { * <table class="compact" style="margin-left:30px; line-height:1.25"> * <caption>Related units</caption> * <tr><td>SI speed units:</td> <td style="word-spacing:1em"><b>{@link #METRES_PER_SECOND}</b>.</td></tr> - * <tr><td>Non-SI units:</td> <td style="word-spacing:1em"><u>{@code KILOMETRES_PER_HOUR}</u>.</td></tr> + * <tr><td>Non-SI units:</td> <td style="word-spacing:1em"><u>{@code KILOMETRES_PER_HOUR}</u>, {@link #KNOT}.</td></tr> * <tr><td>Components:</td> <td style="word-spacing:0.5em">{@link #KILOMETRE} ∕ {@link #HOUR}</td></tr> * </table> * @@ -621,6 +621,22 @@ public final class Units extends Static { */ public static final Unit<Speed> KILOMETRES_PER_HOUR; + /** + * Unit of measurement defined as 1.852 km/h. + * The {@linkplain ConventionalUnit#getSystemUnit() system unit} is {@link #METRES_PER_SECOND} + * and the unlocalized name is “knot”. + * + * <table class="compact" style="margin-left:30px; line-height:1.25"> + * <caption>Related units</caption> + * <tr><td>SI speed units:</td> <td style="word-spacing:1em"><b>{@link #METRES_PER_SECOND}</b>.</td></tr> + * <tr><td>Non-SI units:</td> <td style="word-spacing:1em">{@link #KILOMETRES_PER_HOUR}, <u>{@code #KNOT}</u>.</td></tr> + * <tr><td>Components:</td> <td style="word-spacing:0.5em">{@link #KILOMETRE} ∕ {@link #HOUR}</td></tr> + * </table> + * + * @since 1.5 + */ + public static final Unit<Speed> KNOT; + /** * The SI derived unit for acceleration (m/s²). * The unlocalized name is “metres per second squared”. @@ -999,6 +1015,12 @@ public final class Units extends Static { * A SI conventional unit for mass (g). * The unlocalized name is “gram”. * + * <table class="compact" style="margin-left:30px; line-height:1.25"> + * <caption>Related units</caption> + * <tr><td>SI mass units:</td> <td style="word-spacing:1em"><u>{@code GRAM}</u>, <b>{@link #KILOGRAM}</b>.</td></tr> + * <tr><td>Non-SI units:</td> <td style="word-spacing:1em">{@link #TONNE}.</td></tr> + * </table> + * * @since 0.8 */ public static final Unit<Mass> GRAM; @@ -1007,10 +1029,30 @@ public final class Units extends Static { * The SI base unit for mass (kg). * The unlocalized name is “kilogram”. * + * <table class="compact" style="margin-left:30px; line-height:1.25"> + * <caption>Related units</caption> + * <tr><td>SI mass units:</td> <td style="word-spacing:1em">{@link #GRAM}, <u><b>{@code KILOGRAM}</b></u>.</td></tr> + * <tr><td>Non-SI units:</td> <td style="word-spacing:1em">{@link #TONNE}.</td></tr> + * </table> + * * @since 0.8 */ public static final Unit<Mass> KILOGRAM; + /** + * The SI convention unit for mass (t). + * The unlocalized name is “tonne”. + * + * <table class="compact" style="margin-left:30px; line-height:1.25"> + * <caption>Related units</caption> + * <tr><td>SI mass units:</td> <td style="word-spacing:1em">{@link #GRAM}, <b>{@link #KILOGRAM}</b>.</td></tr> + * <tr><td>Non-SI units:</td> <td style="word-spacing:1em"><u>{@code TONNE}</u>.</td></tr> + * </table> + * + * @since 1.5 + */ + public static final Unit<Mass> TONNE; + /** * The SI base unit for amount of substance (mol). * The unlocalized name is “mole”. @@ -1229,11 +1271,12 @@ public final class Units extends Static { final SystemUnit<ScaleRateOfChange> unityPerSecond; unityPerSecond = new SystemUnit<>(ScaleRateOfChange.class, frequency, null, OTHER, (short) 1036, null); unityPerSecond.related(1); - mps .related(1); + mps .related(2); mps2.related(1); METRES_PER_SECOND = mps; METRES_PER_SECOND_SQUARED = mps2; KILOMETRES_PER_HOUR = add(mps, LinearConverter.scale(10, 36), "km∕h", ACCEPTED, (short) 0); + KNOT = add(mps, LinearConverter.scale(1852, 3600), "kn", OTHER, (short) 0); RADIANS_PER_SECOND = add(AngularVelocity.class, null, frequency, "rad∕s", SI, (short) 1035); GAL = add(mps2, centi, "Gal", (byte) (CGS | PREFIXABLE | ACCEPTED), (short) 0); add(unityPerSecond, LinearConverter.scale(1, 31556925445E6), "ppm∕a", OTHER, (short) 1030); @@ -1261,6 +1304,7 @@ public final class Units extends Static { SQUARE_METRE = m2; CUBIC_METRE = m3; KILOGRAM = kg; + TONNE = add(kg, kilo, "t", ACCEPTED, (short) 0); HECTARE = add(m2, ten4, "ha", ACCEPTED, (short) 0); LITRE = add(m3, milli, "L", (byte) (ACCEPTED | PREFIXABLE), (short) 0); GRAM = add(kg, milli, "g", (byte) (ACCEPTED | PREFIXABLE), (short) 0); @@ -1314,6 +1358,7 @@ public final class Units extends Static { UnitRegistry.alias(DEGREE, Short.valueOf(Constants.EPSG_AXIS_DEGREES)); UnitRegistry.alias(ARC_MINUTE, "'"); UnitRegistry.alias(ARC_SECOND, "\""); + UnitRegistry.alias(KNOT, "kt"); // Symbol used in aviation. UnitRegistry.alias(KELVIN, "K"); // Ordinary "K" letter (not the dedicated Unicode character). UnitRegistry.alias(CELSIUS, "℃"); UnitRegistry.alias(CELSIUS, "Cel"); diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitFormatTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitFormatTest.java index 433f67b81d..acddb61c9f 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitFormatTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitFormatTest.java @@ -100,6 +100,7 @@ public final class UnitFormatTest extends TestCase { verify(declared, "RADIANS_PER_SECOND", "∕T", "rad∕s", "radians per second", Units.RADIANS_PER_SECOND); verify(declared, "METRES_PER_SECOND", "L∕T", "m∕s", "metres per second", Units.METRES_PER_SECOND); verify(declared, "KILOMETRES_PER_HOUR", "L∕T", "km∕h", "kilometres per hour", Units.KILOMETRES_PER_HOUR); + verify(declared, "KNOT", "L∕T", "kn", "knot", Units.KNOT); verify(declared, "PASCAL", "M∕(L⋅T²)", "Pa", "pascal", Units.PASCAL); verify(declared, "HECTOPASCAL", "M∕(L⋅T²)", "hPa", "hectopascal", Units.HECTOPASCAL); verify(declared, "DECIBAR", "M∕(L⋅T²)", "dbar", "decibar", Units.DECIBAR); @@ -125,6 +126,7 @@ public final class UnitFormatTest extends TestCase { verify(declared, "LUX", "J∕L²", "lx", "lux", Units.LUX); verify(declared, "KILOGRAM", "M", "kg", "kilogram", Units.KILOGRAM); verify(declared, "GRAM", "M", "g", "gram", Units.GRAM); + verify(declared, "TONNE", "M", "t", "tonne", Units.TONNE); verify(declared, "MOLE", "N", "mol", "mole", Units.MOLE); verify(declared, "UNITY", "", "", null, Units.UNITY); verify(declared, "PERCENT", "", "%", "percent", Units.PERCENT); diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitsTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitsTest.java index 0362b32a40..53aa9107e2 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitsTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/UnitsTest.java @@ -184,9 +184,10 @@ public final class UnitsTest extends TestCase { */ @Test public void testConversionFactors() { - assertEquals(1000, KILOMETRE .getConverterTo(METRE) .convert( 1)); - assertEquals( 3.6, METRES_PER_SECOND.getConverterTo(KILOMETRES_PER_HOUR).convert( 1)); - assertEquals(1E-6, BECQUEREL .getConverterTo(CURIE) .convert(37000), 1E-20); + assertEquals(1000, KILOMETRE .getConverterTo(METRE) .convert( 1)); + assertEquals( 3.6, METRES_PER_SECOND.getConverterTo(KILOMETRES_PER_HOUR).convert( 1)); + assertEquals(18.52, KNOT .getConverterTo(KILOMETRES_PER_HOUR).convert( 10)); + assertEquals(1E-6, BECQUEREL .getConverterTo(CURIE) .convert(37000), 1E-20); } /**