sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1675086 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/referencing/cs/ sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ sis-referencing/src/test/java/org/apache/sis/referencing/crs/ si...
Date Tue, 21 Apr 2015 10:49:54 GMT
Author: desruisseaux
Date: Tue Apr 21 10:49:54 2015
New Revision: 1675086

URL: http://svn.apache.org/r1675086
Log:
Workaround for a JSR-275 bug: Unit.toString() sometime throws IllegalArgumentException.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCompoundCS.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/CoordinateOperationMethodsHTML.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/AbstractCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultSphericalCSTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCompoundCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCompoundCS.java?rev=1675086&r1=1675085&r2=1675086&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCompoundCS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCompoundCS.java
[UTF-8] Tue Apr 21 10:49:54 2015
@@ -18,10 +18,10 @@ package org.apache.sis.referencing.cs;
 
 import java.util.Map;
 import java.util.List;
-import javax.measure.unit.Unit;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
+import org.apache.sis.internal.util.Utilities;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Workaround;
 import org.apache.sis.util.iso.Types;
@@ -150,12 +150,9 @@ public class DefaultCompoundCS extends A
         for (final CoordinateSystemAxis axis : axes) {
             buffer.append(separator).append(Types.getCodeLabel(axis.getDirection()));
             separator = ", ";
-            final Unit<?> unit = axis.getUnit();
-            if (unit != null) {
-                final String symbol = unit.toString();
-                if (!symbol.isEmpty()) {
-                    buffer.append(" (").append(symbol).append(')');
-                }
+            final String symbol = Utilities.toString(axis.getUnit());
+            if (symbol != null && !symbol.isEmpty()) {
+                buffer.append(" (").append(symbol).append(')');
             }
         }
         return buffer.append('.').toString();

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/CoordinateOperationMethodsHTML.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/CoordinateOperationMethodsHTML.java?rev=1675086&r1=1675085&r2=1675086&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/CoordinateOperationMethodsHTML.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/CoordinateOperationMethodsHTML.java
[UTF-8] Tue Apr 21 10:49:54 2015
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.io.IOException;
-import javax.measure.unit.Unit;
 import org.opengis.util.FactoryException;
 import org.opengis.util.GenericName;
 import org.opengis.metadata.Identifier;
@@ -35,6 +34,7 @@ import org.opengis.referencing.crs.Coord
 import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.util.Constants;
+import org.apache.sis.internal.util.Utilities;
 import org.apache.sis.measure.Range;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Longitude;
@@ -46,7 +46,6 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.Characters;
 import org.apache.sis.util.Numbers;
-import org.apache.sis.util.Workaround;
 import org.apache.sis.test.HTMLGenerator;
 
 
@@ -472,20 +471,10 @@ public final class CoordinateOperationMe
      * Returns the string representation of the given parameter unit,
      * or an empty string (never {@code null}) if none.
      */
-    @Workaround(library="JSR-275", version="0.9.3")
     private static String getUnit(final ParameterDescriptor<?> param) {
-        final Unit<?> unit = param.getUnit();
-        if (unit != null) {
-            final String text;
-            try {
-                text = unit.toString();
-                if (!text.isEmpty()) {
-                    return text.equals("deg") ? "°" : " " + text;
-                }
-            } catch (IllegalArgumentException e) {
-                // Workaround for JSR-275 implementation bug.
-                // Do nothing, we will returns the empty string below.
-            }
+        final String unit = Utilities.toString(param.getUnit());
+        if (unit != null && !unit.isEmpty()) {
+            return " " + unit;
         }
         return "";
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/AbstractCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/AbstractCRSTest.java?rev=1675086&r1=1675085&r2=1675086&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/AbstractCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/AbstractCRSTest.java
[UTF-8] Tue Apr 21 10:49:54 2015
@@ -48,7 +48,7 @@ public final strictfp class AbstractCRST
                     new AbstractCS (singletonMap(NAME_KEY, "My strange CS"),
                     HardCodedAxes.TIME, HardCodedAxes.ALTITUDE, HardCodedAxes.GEODETIC_LATITUDE,
HardCodedAxes.GEODETIC_LONGITUDE));
         expected =  new AbstractCRS(singletonMap(NAME_KEY, "My CRS"),
-                    new AbstractCS (singletonMap(NAME_KEY, "Coordinate system: East (deg),
North (deg), Up (m), Future (d)."),
+                    new AbstractCS (singletonMap(NAME_KEY, "Coordinate system: East (°),
North (°), Up (m), Future (d)."),
                     HardCodedAxes.GEODETIC_LONGITUDE, HardCodedAxes.GEODETIC_LATITUDE, HardCodedAxes.ALTITUDE,
HardCodedAxes.TIME));
         actual   =  toTest.forConvention(AxesConvention.RIGHT_HANDED);
 

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultSphericalCSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultSphericalCSTest.java?rev=1675086&r1=1675085&r2=1675086&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultSphericalCSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/DefaultSphericalCSTest.java
[UTF-8] Tue Apr 21 10:49:54 2015
@@ -43,7 +43,7 @@ public final strictfp class DefaultSpher
         final AbstractCS normalized = SPHERICAL.forConvention(AxesConvention.CONVENTIONALLY_ORIENTED);
         assertNotSame(SPHERICAL, normalized);
         assertEquals(new DefaultSphericalCS(
-            Collections.singletonMap(AbstractCS.NAME_KEY, "Spherical CS: East (deg), North
(deg), Up (m)."),
+            Collections.singletonMap(AbstractCS.NAME_KEY, "Spherical CS: East (°), North
(°), Up (m)."),
             HardCodedAxes.SPHERICAL_LONGITUDE,
             HardCodedAxes.SPHERICAL_LATITUDE,
             HardCodedAxes.GEOCENTRIC_RADIUS

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java?rev=1675086&r1=1675085&r2=1675086&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/UnitAdapter.java
[UTF-8] Tue Apr 21 10:49:54 2015
@@ -19,6 +19,7 @@ package org.apache.sis.internal.jaxb.gco
 import javax.measure.unit.Unit;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.internal.util.Utilities;
 
 
 /**
@@ -54,7 +55,7 @@ public class UnitAdapter extends XmlAdap
      */
     @Override
     public String marshal(final Unit<?> value) {
-        return (value != null) ? value.toString() : null;
+        return Utilities.toString(value);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java?rev=1675086&r1=1675085&r2=1675086&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] Tue Apr 21 10:49:54 2015
@@ -18,9 +18,11 @@ package org.apache.sis.internal.util;
 
 import java.util.Formatter;
 import java.util.FormattableFlags;
+import javax.measure.unit.Unit;
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.Workaround;
 
 
 /**
@@ -28,7 +30,7 @@ import org.apache.sis.util.CharSequences
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.6
  * @module
  */
 public final class Utilities extends Static {
@@ -39,6 +41,31 @@ public final class Utilities extends Sta
     }
 
     /**
+     * Returns the string representation of the given unit, or {@code null} if none.
+     * This method is used as a workaround for a bug in JSR-275, which sometime throws
+     * an exception in the {@link Unit#toString()} method.
+     *
+     * @param  unit The unit for which to get a string representation, or {@code null}.
+     * @return The string representation of the given string (may be an empty string), or
{@code null}.
+     *
+     * @since 0.6
+     */
+    @Workaround(library="JSR-275", version="0.9.3")
+    public static String toString(final Unit<?> unit) {
+        if (unit != null) try {
+            String text = unit.toString();
+            if (text.equals("deg")) {
+                text = "°";
+            }
+            return text;
+        } catch (IllegalArgumentException e) {
+            // Workaround for JSR-275 implementation bug.
+            // Do nothing, we will return null below.
+        }
+        return null;
+    }
+
+    /**
      * Appends to the given buffer only the characters that are valid for a Unicode identifier.
      * The given separator character is append before the given {@code text} only if the
buffer
      * is not empty and at least one {@code text} character is valid.



Mime
View raw message