sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1792953 - in /sis/branches/JDK8/core/sis-utility/src: main/java/org/apache/sis/measure/ main/resources/org/apache/sis/measure/ test/java/org/apache/sis/measure/
Date Thu, 27 Apr 2017 20:02:23 GMT
Author: desruisseaux
Date: Thu Apr 27 20:02:23 2017
New Revision: 1792953

URL: http://svn.apache.org/viewvc?rev=1792953&view=rev
Log:
Adjustement for the previous fix about handling of SI prefixes in "kg" and "l" special cases.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.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/UnitAliases.properties
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitFormatTest.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java?rev=1792953&r1=1792952&r2=1792953&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
[UTF-8] Thu Apr 27 20:02:23 2017
@@ -468,9 +468,15 @@ final class SystemUnit<Q extends Quantit
      * @return the unit after the specified transformation.
      */
     @Override
-    public Unit<Q> transform(final UnitConverter operation) {
+    @SuppressWarnings("unchecked")
+    public Unit<Q> transform(UnitConverter operation) {
         ArgumentChecks.ensureNonNull("operation", operation);
-        return ConventionalUnit.create(this, operation);
+        AbstractUnit<Q> base = this;
+        if (this == Units.KILOGRAM) {
+            base = (AbstractUnit<Q>) Units.GRAM;
+            operation = operation.concatenate(LinearConverter.forPrefix('k'));
+        }
+        return ConventionalUnit.create(base, operation);
     }
 
     /**

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=1792953&r1=1792952&r2=1792953&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]
Thu Apr 27 20:02:23 2017
@@ -1161,39 +1161,41 @@ public final class Units extends Static
          * All Unit<Temperature>.
          */
         K.related(1);
-        KELVIN     = K;
-        CELSIUS    = add(K, LinearConverter.offset(  27315, 100), "°C", SI,    (short) 0);
-        FAHRENHEIT = add(K, new LinearConverter(100, 45967, 180), "°F", OTHER, (short) 0);
+        KELVIN       = K;
+        CELSIUS      = add(K, LinearConverter.offset(  27315, 100), "°C", SI,    (short)
0);
+        FAHRENHEIT   = add(K, new LinearConverter(100, 45967, 180), "°F", OTHER, (short)
0);
         /*
-         * Electricity and magnetism.
-         */
-        AMPERE  = add(ElectricCurrent.class,     null, current,                      "A",
 (byte) (SI | PREFIXABLE), (short) 0);
-        COULOMB = add(ElectricCharge.class,      null, charge,                       "C",
 (byte) (SI | PREFIXABLE), (short) 0);
-        VOLT    = add(ElectricPotential.class,   null, potential,                    "V",
 (byte) (SI | PREFIXABLE), (short) 0);
-        FARAD   = add(ElectricCapacitance.class, null, charge.divide(potential),     "F",
 (byte) (SI | PREFIXABLE), (short) 0);
-        SIEMENS = add(ElectricConductance.class, null, current.divide(potential),    "S",
 (byte) (SI | PREFIXABLE), (short) 0);
-        OHM     = add(ElectricResistance.class,  null, potential.divide(current),    "Ω",
 (byte) (SI | PREFIXABLE), (short) 0);
-        WEBER   = add(MagneticFlux.class,        null, magneticFlux,                 "Wb",
(byte) (SI | PREFIXABLE), (short) 0);
-        TESLA   = add(MagneticFluxDensity.class, null, magneticFlux.divide(area),    "T",
 (byte) (SI | PREFIXABLE), (short) 0);
-        HENRY   = add(ElectricInductance.class,  null, magneticFlux.divide(current), "H",
 (byte) (SI | PREFIXABLE), (short) 0);
-        /*
-         * Other units.
+         * Unit<Volume> and Unit<Mass>. Those units need to be handled in a special
way because:
+         * 1) The base unit of mass is "kg", not "g". This is handled by a hard-coded case
in SystemUnit.
+         * 2) The liter unit is not a SI units, but despite that is commonly used with SI
prefixes.
          */
         SQUARE_METRE = m2;
         CUBIC_METRE  = m3;
         KILOGRAM     = kg;
-        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);
-        HERTZ        = add(Frequency.class,         Scalar.Frequency::new, time.pow(-1),
         "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);
-        LUX          = add(Illuminance.class,       null,                  luminous.divide(area),
"lx",  (byte) (SI       | PREFIXABLE), (short) 0);
-        LUMEN        = add(LuminousFlux.class,      null,                  luminous,    
         "lm",  (byte) (SI       | PREFIXABLE), (short) 0);
-        CANDELA      = add(LuminousIntensity.class, null,                  luminous,    
         "cd",  (byte) (SI       | PREFIXABLE), (short) 0);    // Must be after Lumen.
-        MOLE         = add(AmountOfSubstance.class, null,                  amount,      
         "mol", (byte) (SI       | PREFIXABLE), (short) 0);
-        STERADIAN    = add(SolidAngle.class,        null,                  dimensionless,
        "sr",  (byte) (SI       | PREFIXABLE), (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);
+        /*
+         * Force, energy, electricity, magnetism and other units.
+         */
+        HERTZ      = add(Frequency.class,           Scalar.Frequency::new, time.pow(-1),
                "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);
+        AMPERE     = add(ElectricCurrent.class,     null,                  current,     
                "A",   (byte) (SI | PREFIXABLE), (short) 0);
+        COULOMB    = add(ElectricCharge.class,      null,                  charge,      
                "C",   (byte) (SI | PREFIXABLE), (short) 0);
+        VOLT       = add(ElectricPotential.class,   null,                  potential,   
                "V",   (byte) (SI | PREFIXABLE), (short) 0);
+        FARAD      = add(ElectricCapacitance.class, null,                  charge.divide(potential),
    "F",   (byte) (SI | PREFIXABLE), (short) 0);
+        SIEMENS    = add(ElectricConductance.class, null,                  current.divide(potential),
   "S",   (byte) (SI | PREFIXABLE), (short) 0);
+        OHM        = add(ElectricResistance.class,  null,                  potential.divide(current),
   "Ω",   (byte) (SI | PREFIXABLE), (short) 0);
+        WEBER      = add(MagneticFlux.class,        null,                  magneticFlux,
                "Wb",  (byte) (SI | PREFIXABLE), (short) 0);
+        TESLA      = add(MagneticFluxDensity.class, null,                  magneticFlux.divide(area),
   "T",   (byte) (SI | PREFIXABLE), (short) 0);
+        HENRY      = add(ElectricInductance.class,  null,                  magneticFlux.divide(current),
"H",   (byte) (SI | PREFIXABLE), (short) 0);
+        LUX        = add(Illuminance.class,         null,                  luminous.divide(area),
       "lx",  (byte) (SI | PREFIXABLE), (short) 0);
+        LUMEN      = add(LuminousFlux.class,        null,                  luminous,    
                "lm",  (byte) (SI | PREFIXABLE), (short) 0);
+        CANDELA    = add(LuminousIntensity.class,   null,                  luminous,    
                "cd",  (byte) (SI | PREFIXABLE), (short) 0);    // Must be after Lumen.
+        MOLE       = add(AmountOfSubstance.class,   null,                  amount,      
                "mol", (byte) (SI | PREFIXABLE), (short) 0);
+        STERADIAN  = add(SolidAngle.class,          null,                  dimensionless,
               "sr",  (byte) (SI | PREFIXABLE), (short) 0);
         /*
          * All Unit<Dimensionless>.
          */
@@ -1214,6 +1216,8 @@ public final class Units extends Static
         UnitRegistry.alias(FAHRENHEIT,  "℉");
         UnitRegistry.alias(GRAD,      "gon");
         UnitRegistry.alias(HECTARE,   "hm²");
+        UnitRegistry.alias(LITRE,       "l");
+        UnitRegistry.alias(LITRE,       "ℓ");
         UnitRegistry.alias(UNITY,       "1");
 
         initialized = true;

Modified: sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitAliases.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitAliases.properties?rev=1792953&r1=1792952&r2=1792953&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitAliases.properties
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/resources/org/apache/sis/measure/UnitAliases.properties
[UTF-8] Thu Apr 27 20:02:23 2017
@@ -20,7 +20,6 @@ gradians=grad
 grads=grad
 grams=g
 hours=h
-l=L
 liters=L
 litres=L
 mbar=hPa

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java?rev=1792953&r1=1792952&r2=1792953&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java
[UTF-8] Thu Apr 27 20:02:23 2017
@@ -190,6 +190,9 @@ public final strictfp class Conventional
         assertSame(Units.GRAD,        Units.RADIAN.multiply(Math.PI/200));
         assertSame(Units.ARC_SECOND,  Units.RADIAN.multiply(Math.PI / (180*60*60)));
         assertSame(Units.MICRORADIAN, Units.RADIAN.divide(1E6));
+
+        assertSame(Units.GRAM, Units.KILOGRAM.divide(1E+3));
+        verify(Units.KILOGRAM, Units.KILOGRAM.divide(1E+6), "mg", 1E-6);
     }
 
     /**

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=1792953&r1=1792952&r2=1792953&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] Thu Apr 27 20:02:23 2017
@@ -365,6 +365,7 @@ public final strictfp class UnitFormatTe
         ConventionalUnitTest.verify(Units.HERTZ,       f.parse("MHz"),  "MHz",  1E+6);
         ConventionalUnitTest.verify(Units.PASCAL,      f.parse("daPa"), "daPa", 1E+1);
         ConventionalUnitTest.verify(Units.CUBIC_METRE, f.parse("mL"),   "mL",   1E-6);
+        ConventionalUnitTest.verify(Units.CUBIC_METRE, f.parse("ml"),   "mL",   1E-6);
         ConventionalUnitTest.verify(Units.KILOGRAM,    f.parse("kg"),   "kg",   1E+0);
         ConventionalUnitTest.verify(Units.KILOGRAM,    f.parse("g"),    "g",    1E-3);
         ConventionalUnitTest.verify(Units.KILOGRAM,    f.parse("mg"),   "mg",   1E-6);



Mime
View raw message