sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1766453 - in /sis/branches/JDK8/core/sis-utility/src: main/java/org/apache/sis/measure/LinearConverter.java main/java/org/apache/sis/measure/UnitFormat.java test/java/org/apache/sis/measure/UnitsTest.java
Date Mon, 24 Oct 2016 21:47:34 GMT
Author: desruisseaux
Date: Mon Oct 24 21:47:34 2016
New Revision: 1766453

URL: http://svn.apache.org/viewvc?rev=1766453&view=rev
Log:
UnitFormat need to append the scale factor of ConventionalUnit.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java?rev=1766453&r1=1766452&r2=1766453&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
[UTF-8] Mon Oct 24 21:47:34 2016
@@ -341,11 +341,11 @@ final class LinearConverter extends Abst
     @Debug
     @Override
     public String toString() {
-        final StringBuilder buffer = new StringBuilder().append("\uD835\uDC66 = ");
+        final StringBuilder buffer = new StringBuilder().append("y = ");
         if (scale != 1) {
             buffer.append(scale).append('⋅');
         }
-        buffer.append("\uD835\uDC65");
+        buffer.append('x');
         if (offset != 0) {
             buffer.append(" + ").append(offset);
         }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java?rev=1766453&r1=1766452&r2=1766453&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/UnitFormat.java
[UTF-8] Mon Oct 24 21:47:34 2016
@@ -515,6 +515,18 @@ public class UnitFormat extends Format i
          * Note that this may produce more verbose symbols than needed since derived units
like Volt or Watt are
          * decomposed into their base SI units.
          */
+        final double scale = Units.toStandardUnit(unit);
+        if (scale != 1) {
+            if (Double.isNaN(scale)) {
+                throw new IllegalArgumentException(Errors.format(Errors.Keys.NonRatioUnit_1,
"?(" + unit.getSystemUnit() + ')'));
+            }
+            final String text = Double.toString(scale);
+            int length = text.length();
+            if (text.endsWith(".0")) {
+                length -= 2;
+            }
+            toAppendTo.append(text, 0, length).append(style.multiply);
+        }
         Map<? extends Unit<?>, ? extends Number> components;
         if (unit instanceof AbstractUnit<?>) {
             // In Apache SIS implementation, the powers may be ratios.

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java?rev=1766453&r1=1766452&r2=1766453&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
[UTF-8] Mon Oct 24 21:47:34 2016
@@ -50,16 +50,13 @@ public final strictfp class UnitsTest ex
 
     /**
      * Tests serialization of units.
-     *
-     * @todo The {@code assertEquals} in this method should actually be {@code assertSame},
-     *       but JSR-275 0.9.3 does not resolve units on deserialization.
      */
     @Test
     public void testSerialization() {
-        assertEquals(DEGREE,     assertSerializedEquals(DEGREE));
+        assertSame  (DEGREE,     assertSerializedEquals(DEGREE));
         assertEquals(DMS,        assertSerializedEquals(DMS));
         assertEquals(DMS_SCALED, assertSerializedEquals(DMS_SCALED));
-        assertEquals(PPM,        assertSerializedEquals(PPM));
+        assertSame  (PPM,        assertSerializedEquals(PPM));
     }
 
     /**
@@ -181,7 +178,7 @@ public final strictfp class UnitsTest ex
      */
     @Test
     public void testMultiply() {
-        assertSame(KILOMETRE, multiply(METRE,  1000));
+        assertSame(KILOMETRE, multiply(METRE, 1000));
         assertSame(DEGREE, multiply(RADIAN, 0.017453292519943295));
     }
 



Mime
View raw message