Author: desruisseaux Date: Sat Aug 12 09:56:14 2017 New Revision: 1804863 URL: http://svn.apache.org/viewvc?rev=1804863&view=rev Log: Add RADIANS_PER_SECOND unit and the corresponding AngularVelocity quantity. Add also a Salinity quantity.
Added: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AngularVelocity.java (with props) sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Salinity.java (with props) sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ScaleRateOfChange.java (with props) Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames.properties sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames_fr.properties sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java Added: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AngularVelocity.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AngularVelocity.java?rev=1804863&view=auto ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AngularVelocity.java (added) +++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AngularVelocity.java [UTF-8] Sat Aug 12 09:56:14 2017 @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.measure; + +import javax.measure.Quantity; + + +/** + * The rate of change of an angular displacement with respect to time. + * The SI unit is radians per second (rad/s) and the EPSG code is 1035. + * This quantity is used for describing the rate of changes of {@code rX}, {@code rY} and {@code rZ} terms in + * {@linkplain org.apache.sis.referencing.datum.BursaWolfParameters Bursa-Wolf parameters}, under the effect + * of plate tectonics. + * + * <p>Most quantity types are defined in the {@link javax.measure.quantity}. + * This {@code AngularVelocity} type is an extension to the standard types.</p> + * + * @author Martin Desruisseaux (Geomatys) + * @version 0.8 + * @since 0.8 + * @module + * + * @see Units#RADIANS_PER_SECOND + * @see org.apache.sis.referencing.datum.TimeDependentBWP + */ +public interface AngularVelocity extends Quantity<AngularVelocity> { +} Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AngularVelocity.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AngularVelocity.java ------------------------------------------------------------------------------ svn:mime-type = text/plain;charset=UTF-8 Added: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Salinity.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Salinity.java?rev=1804863&view=auto ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Salinity.java (added) +++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Salinity.java [UTF-8] Sat Aug 12 09:56:14 2017 @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.measure; + +import javax.measure.Quantity; + + +/** + * The Practical Salinity Scale (PSS-78). + * This is a dimensionless quantity for the measurement of sea water salinity. + * In principle, the unit of measurement associated to this quantity has no symbol. + * However Apache SIS uses the "psu" symbol for avoiding confusion with other dimensionless units. + * + * <p>Most quantity types are defined in the {@link javax.measure.quantity}. + * This {@code AngularVelocity} type is an extension to the standard types.</p> + * + * @author Martin Desruisseaux (Geomatys) + * @version 0.8 + * @since 0.8 + * @module + * + * @see Units#PSU + */ +public interface Salinity extends Quantity<Salinity> { +} Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Salinity.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Salinity.java ------------------------------------------------------------------------------ svn:mime-type = text/plain;charset=UTF-8 Added: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ScaleRateOfChange.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ScaleRateOfChange.java?rev=1804863&view=auto ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ScaleRateOfChange.java (added) +++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ScaleRateOfChange.java [UTF-8] Sat Aug 12 09:56:14 2017 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.measure; + +import javax.measure.Quantity; + + +/** + * The rate of change of a scale factor, in unity per second. This unit is specific to the EPSG database. + * It has the same units than frequency, but it still not the same thing. + * + * @author Martin Desruisseaux (Geomatys) + * @version 0.8 + * @since 0.8 + * @module + */ +interface ScaleRateOfChange extends Quantity<ScaleRateOfChange> { +} Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ScaleRateOfChange.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ScaleRateOfChange.java ------------------------------------------------------------------------------ svn:mime-type = text/plain;charset=UTF-8 Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java?rev=1804863&r1=1804862&r2=1804863&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitRegistry.java [UTF-8] Sat Aug 12 09:56:14 2017 @@ -121,22 +121,34 @@ final class UnitRegistry implements Syst */ static <Q extends Quantity<Q>> SystemUnit<Q> init(final SystemUnit<Q> unit) { assert !Units.initialized : unit; // This assertion happens during Units initialization, but it is okay. - boolean existed; - existed = HARD_CODED.put(unit.dimension, unit) != null; - existed |= HARD_CODED.put(unit.quantity, unit) != null; - existed |= HARD_CODED.put(unit.getSymbol(), unit) != null; + int existed; + existed = (HARD_CODED.put(unit.dimension, unit) == null) ? 0 : 1; + existed |= (HARD_CODED.put(unit.quantity, unit) == null) ? 0 : 2; + existed |= (HARD_CODED.put(unit.getSymbol(), unit) == null) ? 0 : 4; if (unit.epsg != 0) { - existed |= HARD_CODED.put(unit.epsg, unit) != null; + existed |= (HARD_CODED.put(unit.epsg, unit) == null) ? 0 : 8; } /* * Key collision on dimension and quantity tolerated for dimensionless units only, with an * an exception for "candela" because "lumen" is candela divided by a dimensionless unit. + * Another exception is "Hz" because it come after rad/s, which has the same dimension. */ - assert !existed || unit.dimension.isDimensionless() || "cd".equals(unit.getSymbol()) : unit; + assert filter(existed, unit) == 0 : unit; return unit; } /** + * Clears the {@code existed} bits for the cases where we allow dimension or quantity type collisions. + * This method is invoked for assertions only. + */ + private static int filter(int existed, final SystemUnit<?> unit) { + final String s = unit.getSymbol(); + if (unit.dimension.isDimensionless()) existed &= ~(1 | 2); // Accepts dimension and quantity collisions. + if (s.equals("cd") || s.equals("Hz")) existed &= ~(1 ); // Accepts dimension collisions only; + return s.isEmpty() ? 0 : existed; + } + + /** * Invoked by {@link Units} static class initializer for registering SI conventional units. * This method shall be invoked in a single thread by the {@code Units} class initializer only. */ Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java?rev=1804863&r1=1804862&r2=1804863&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] Sat Aug 12 09:56:14 2017 @@ -371,7 +371,7 @@ public final class Units extends Static * <table class="compact" summary="Related units" style="margin-left:30px; line-height:1.25"> * <tr><td>SI angle units:</td> <td style="word-spacing:1em">{@link #MICRORADIAN}, <u><b>{@code RADIAN}</b></u>.</td></tr> * <tr><td>In other systems:</td> <td style="word-spacing:1em">{@link #DEGREE}, {@link #ARC_MINUTE}, {@link #ARC_SECOND}, {@link #GRAD}.</td></tr> - * <tr><td>Derived units:</td> <td style="word-spacing:1em">{@link #STERADIAN}.</td></tr> + * <tr><td>Derived units:</td> <td style="word-spacing:1em">{@link #STERADIAN}, {@link #RADIANS_PER_SECOND}.</td></tr> * </table></div> * * @since 0.8 @@ -582,6 +582,19 @@ public final class Units extends Static public static final Unit<Frequency> HERTZ; /** + * The unit for angular velocity (rad/s). + * The identifier is EPSG:1035. + * + * <div class="note"><p class="simpleTagLabel" style="margin-bottom:0">Related units:</p> + * <table class="compact" summary="Related units" style="margin-left:30px; line-height:1.25"> + * <tr><td>Components:</td> <td style="word-spacing:0.5em">{@link #RADIAN} ∕ {@link #SECOND}</td></tr> + * </table></div> + * + * @since 0.8 + */ + public static final Unit<AngularVelocity> RADIANS_PER_SECOND; + + /** * The SI derived unit for speed (m/s). * The unlocalized name is “metres per second” and the identifier is EPSG:1026. * @@ -1020,10 +1033,9 @@ public final class Units extends Static * Salinity measured using PSS-78. While this is a dimensionless measurement, the {@code "psu"} symbol * is sometime added to PSS-78 measurement. However this is officially discouraged. * - * <p>If we make this field public in a future SIS version, we should consider introducing a - * {@code Salinity} quantity type.</p> + * @since 0.8 */ - static final Unit<Dimensionless> PSU; + public static final Unit<Salinity> PSU; /** * Sigma-level, used in oceanography. This is a way to measure a depth as a fraction of the sea floor depth. @@ -1069,6 +1081,7 @@ public final class Units extends Static final UnitDimension temperature = new UnitDimension('Θ'); final UnitDimension amount = new UnitDimension('N'); final UnitDimension luminous = new UnitDimension('J'); + final UnitDimension frequency = time.pow(-1); final UnitDimension area = length.pow(2); final UnitDimension speed = length.divide(time); final UnitDimension force = mass.multiply(speed).divide(time); @@ -1143,11 +1156,19 @@ public final class Units extends Static WEEK = add(s, LinearConverter.scale( 7*24*60*60, 1), "wk", OTHER, (short) 0); TROPICAL_YEAR = add(s, LinearConverter.scale(31556925445.0, 1000), "a", OTHER, (short) 1029); /* - * All Unit<Speed>. - */ + * All Unit<Speed>, Unit<AngularVelocity> and Unit<ScaleRateOfChange>. + * The 'unityPerSecond' unit is not added to the registry because it is specific to the EPSG database, + * has no clear symbol and is easy to confuse with Hertz. We create that unit only for allowing us to + * create the "ppm/a" units. + */ + final SystemUnit<ScaleRateOfChange> unityPerSecond; + unityPerSecond = new SystemUnit<>(ScaleRateOfChange.class, frequency, null, OTHER, (short) 1036, null); + unityPerSecond.related(1); mps.related(1); METRES_PER_SECOND = mps; - KILOMETRES_PER_HOUR = add(mps, LinearConverter.scale(10, 36), "km∕h", ACCEPTED, (short) 0); + KILOMETRES_PER_HOUR = add(mps, LinearConverter.scale(10, 36), "km∕h", ACCEPTED, (short) 0); + RADIANS_PER_SECOND = add(AngularVelocity.class, null, frequency, "rad∕s", SI, (short) 1035); + add(unityPerSecond, LinearConverter.scale(1, 31556925445E6), "ppm∕a", OTHER, (short) 1030); /* * All Unit<Pressure>. */ @@ -1177,8 +1198,9 @@ public final class Units extends Static GRAM = add(kg, milli, "g", (byte) (ACCEPTED | PREFIXABLE), (short) 0); /* * Force, energy, electricity, magnetism and other units. + * Frequency must be defined after angular velocities. */ - HERTZ = add(Frequency.class, Scalar.Frequency::new, time.pow(-1), "Hz", (byte) (SI | PREFIXABLE), (short) 0); + HERTZ = add(Frequency.class, Scalar.Frequency::new, frequency, "Hz", (byte) (SI | PREFIXABLE), (short) 0); NEWTON = add(Force.class, Scalar.Force::new, force, "N", (byte) (SI | PREFIXABLE), (short) 0); JOULE = add(Energy.class, Scalar.Energy::new, energy, "J", (byte) (SI | PREFIXABLE), (short) 0); WATT = add(Power.class, Scalar.Power::new, power, "W", (byte) (SI | PREFIXABLE), (short) 0); @@ -1201,7 +1223,7 @@ public final class Units extends Static */ PERCENT = add(one, centi, "%", OTHER, (short) 0); PPM = add(one, micro, "ppm", OTHER, (short) 9202); - PSU = add(Dimensionless.class, Scalar.Dimensionless::new, dimensionless, "psu", OTHER, (short) 0); + PSU = add(Salinity.class, null, dimensionless, "psu", OTHER, (short) 0); SIGMA = add(Dimensionless.class, Scalar.Dimensionless::new, dimensionless, "sigma", OTHER, (short) 0); PIXEL = add(Dimensionless.class, Scalar.Dimensionless::new, dimensionless, "px", OTHER, (short) 0); UNITY = UnitRegistry.init(one); // Must be last in order to take precedence over all other units associated to UnitDimension.NONE. Modified: sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames.properties URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames.properties?rev=1804863&r1=1804862&r2=1804863&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames.properties [ISO-8859-1] (original) +++ sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames.properties [ISO-8859-1] Sat Aug 12 09:56:14 2017 @@ -45,6 +45,7 @@ psu=practical salinity unit pt=point px=pixel rad=radian +rad\u2215s=radians per second s=second S=siemens sr=steradian Modified: sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames_fr.properties URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames_fr.properties?rev=1804863&r1=1804862&r2=1804863&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames_fr.properties [ISO-8859-1] (original) +++ sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitNames_fr.properties [ISO-8859-1] Sat Aug 12 09:56:14 2017 @@ -24,6 +24,7 @@ mm=millimètre ms=milliseconde nm=nanomètre ppm=parties par million +rad\u2215s=radians par seconde s=seconde sr=stéradian unity=unité Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java?rev=1804863&r1=1804862&r2=1804863&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java [UTF-8] Sat Aug 12 09:56:14 2017 @@ -90,6 +90,7 @@ public final strictfp class UnitFormatTe verify(declared, "WEEK", "T", "wk", "week", Units.WEEK); verify(declared, "TROPICAL_YEAR", "T", "a", "year", Units.TROPICAL_YEAR); verify(declared, "HERTZ", "∕T", "Hz", "hertz", Units.HERTZ); + 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, "PASCAL", "M∕(L⋅T²)", "Pa", "pascal", Units.PASCAL);