sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1766204 [2/2] - in /sis/branches/JDK8: application/sis-console/src/main/java/org/apache/sis/console/ application/sis-openoffice/src/main/java/org/apache/sis/openoffice/ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ core...
Date Sat, 22 Oct 2016 15:48:56 GMT
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.datum;
 
 import java.util.Map;
+import java.util.Objects;
 import javax.measure.Unit;
 import javax.measure.quantity.Angle;
 import javax.xml.bind.annotation.XmlType;
@@ -28,8 +29,9 @@ import org.opengis.metadata.Identifier;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
+import org.apache.sis.internal.referencing.Formulas;
+import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
-import org.apache.sis.internal.util.PatchedUnitFormat;
 import org.apache.sis.internal.metadata.MetadataUtilities;
 import org.apache.sis.internal.metadata.WKTKeywords;
 import org.apache.sis.internal.jaxb.gml.Measure;
@@ -42,10 +44,6 @@ import org.apache.sis.measure.Units;
 import static org.apache.sis.util.ArgumentChecks.ensureFinite;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
-// Branch-dependent imports
-import java.util.Objects;
-import org.apache.sis.internal.referencing.Formulas;
-
 
 /**
  * Defines the origin from which longitude values are determined.
@@ -149,9 +147,9 @@ public class DefaultPrimeMeridian extend
      *   </tr>
      * </table>
      *
-     * @param properties          The properties to be given to the identified object.
-     * @param greenwichLongitude  The longitude value relative to the Greenwich Meridian.
-     * @param angularUnit         The angular unit of the longitude.
+     * @param  properties          the properties to be given to the identified object.
+     * @param  greenwichLongitude  the longitude value relative to the Greenwich Meridian.
+     * @param  angularUnit         the angular unit of the longitude.
      *
      * @see org.apache.sis.referencing.factory.GeodeticObjectFactory#createPrimeMeridian(Map, double, Unit)
      */
@@ -172,7 +170,7 @@ public class DefaultPrimeMeridian extend
      *
      * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
      *
-     * @param meridian The prime meridian to copy.
+     * @param  meridian  the prime meridian to copy.
      *
      * @see #castOrCopy(PrimeMeridian)
      */
@@ -188,8 +186,8 @@ public class DefaultPrimeMeridian extend
      * Otherwise if the given object is already a SIS implementation, then the given object is returned unchanged.
      * Otherwise a new SIS implementation is created and initialized to the attribute values of the given object.
      *
-     * @param  object The object to get as a SIS implementation, or {@code null} if none.
-     * @return A SIS implementation containing the values of the given object (may be the
+     * @param  object  the object to get as a SIS implementation, or {@code null} if none.
+     * @return a SIS implementation containing the values of the given object (may be the
      *         given object itself), or {@code null} if the argument was null.
      */
     public static DefaultPrimeMeridian castOrCopy(final PrimeMeridian object) {
@@ -216,7 +214,7 @@ public class DefaultPrimeMeridian extend
     /**
      * Longitude of the prime meridian measured from the Greenwich meridian, positive eastward.
      *
-     * @return The prime meridian Greenwich longitude, in {@linkplain #getAngularUnit() angular unit}.
+     * @return the prime meridian Greenwich longitude, in {@linkplain #getAngularUnit() angular unit}.
      */
     @Override
     public double getGreenwichLongitude() {
@@ -232,8 +230,8 @@ public class DefaultPrimeMeridian extend
      *     double longitudeInDegrees = primeMeridian.getGreenwichLongitude(Units.DEGREE);
      * }
      *
-     * @param unit The unit in which to express longitude.
-     * @return The Greenwich longitude in the given units.
+     * @param  unit  the unit in which to express longitude.
+     * @return the Greenwich longitude in the given units.
      */
     public double getGreenwichLongitude(final Unit<Angle> unit) {
         return getAngularUnit().getConverterTo(unit).convert(getGreenwichLongitude());
@@ -242,7 +240,7 @@ public class DefaultPrimeMeridian extend
     /**
      * Returns the angular unit of the Greenwich longitude.
      *
-     * @return The angular unit of the {@linkplain #getGreenwichLongitude() Greenwich longitude}.
+     * @return the angular unit of the {@linkplain #getGreenwichLongitude() Greenwich longitude}.
      */
     @Override
     public Unit<Angle> getAngularUnit() {
@@ -252,7 +250,7 @@ public class DefaultPrimeMeridian extend
     /**
      * Compares this prime meridian with the specified object for equality.
      *
-     * @param  object The object to compare to {@code this}.
+     * @param  object  the object to compare to {@code this}.
      * @param  mode {@link ComparisonMode#STRICT STRICT} for performing a strict comparison, or
      *         {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} for comparing only properties
      *         relevant to coordinate transformations.
@@ -261,7 +259,7 @@ public class DefaultPrimeMeridian extend
     @Override
     public boolean equals(final Object object, final ComparisonMode mode) {
         if (object == this) {
-            return true; // Slight optimization.
+            return true;                                // Slight optimization.
         }
         if (super.equals(object, mode)) switch (mode) {
             case STRICT: {
@@ -301,7 +299,7 @@ public class DefaultPrimeMeridian extend
      * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()}
      * for more information.
      *
-     * @return The hash code value. This value may change in any future Apache SIS version.
+     * @return the hash code value. This value may change in any future Apache SIS version.
      */
     @Override
     protected long computeHashCode() {
@@ -376,7 +374,7 @@ public class DefaultPrimeMeridian extend
         if (!isWKT1) {
             unit = getAngularUnit();
             if (convention != Convention.INTERNAL) {
-                unit = PatchedUnitFormat.toFormattable(unit);
+                unit = WKTUtilities.toFormattable(unit);
             }
         }
         formatter.append(getGreenwichLongitude(unit));

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/InterpolatedTransform.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -20,7 +20,6 @@ import java.util.Arrays;
 import java.util.Objects;
 import javax.measure.Unit;
 import javax.measure.Quantity;
-import javax.measure.UnitConverter;
 import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
@@ -120,14 +119,14 @@ public class InterpolatedTransform exten
      * <code>{@linkplain #getContextualParameters()}.{@linkplain ContextualParameters#completeTransform
      * completeTransform}(factory, this)}</code>.
      *
-     * @param  <T> Dimension of the coordinate and the translation unit.
-     * @param  grid The grid of datum shifts from source to target datum.
+     * @param  <T>   dimension of the coordinate and the translation unit.
+     * @param  grid  the grid of datum shifts from source to target datum.
      * @throws NoninvertibleMatrixException if the conversion from geodetic coordinates
      *         to grid indices can not be inverted.
      *
      * @see #createGeodeticTransformation(MathTransformFactory, DatumShiftGrid)
      */
-    @SuppressWarnings("OverridableMethodCallDuringObjectConstruction")
+    @SuppressWarnings( {"OverridableMethodCallDuringObjectConstruction", "fallthrough"})
     protected <T extends Quantity<T>> InterpolatedTransform(final DatumShiftGrid<T,T> grid)
             throws NoninvertibleMatrixException
     {
@@ -164,12 +163,15 @@ public class InterpolatedTransform exten
         @SuppressWarnings("unchecked")
         final Unit<T> normalized = Units.isAngular(unit) ? (Unit<T>) Units.DEGREE : unit.getSystemUnit();
         if (!unit.equals(normalized)) {
-            final UnitConverter converter = normalized.getConverterTo(unit);
-            if (!converter.isLinear()) {
-                throw new IllegalArgumentException(Resources.format(Resources.Keys.NonLinearUnitConversion_2, normalized, unit));
+            Number scale  = 1.0;
+            Number offset = 0.0;
+            final Number[] coefficients = Units.coefficients(normalized.getConverterTo(unit));
+            switch (coefficients != null ? coefficients.length : -1) {
+                case 2:  scale  = coefficients[1];       // Fall through
+                case 1:  offset = coefficients[0];       // Fall through
+                case 0:  break;
+                default: throw new IllegalArgumentException(Resources.format(Resources.Keys.NonLinearUnitConversion_2, normalized, unit));
             }
-            final Double offset = converter.convert(0);
-            final Double scale  = Units.derivative(converter, 0);
             for (int j=0; j<dimension; j++) {
                 normalize.convertBefore(j, scale, offset);
             }
@@ -199,13 +201,13 @@ public class InterpolatedTransform exten
      *       coordinates in the unit given by {@link Unit#toSI()}.</li>
      * </ul>
      *
-     * @param <T>      Dimension of the coordinate and the translation unit.
-     * @param factory  The factory to use for creating the transform.
-     * @param grid     The grid of datum shifts from source to target datum.
-     *                 The {@link DatumShiftGrid#interpolateInCell DatumShiftGrid.interpolateInCell(…)}
-     *                 method shall compute translations from <em>source</em> to <em>target</em> as
-     *                 {@linkplain DatumShiftGrid#isCellValueRatio() ratio of offsets divided by cell sizes}.
-     * @return The transformation between geodetic coordinates.
+     * @param  <T>      dimension of the coordinate and the translation unit.
+     * @param  factory  the factory to use for creating the transform.
+     * @param  grid     the grid of datum shifts from source to target datum.
+     *                  The {@link DatumShiftGrid#interpolateInCell DatumShiftGrid.interpolateInCell(…)}
+     *                  method shall compute translations from <em>source</em> to <em>target</em> as
+     *                  {@linkplain DatumShiftGrid#isCellValueRatio() ratio of offsets divided by cell sizes}.
+     * @return the transformation between geodetic coordinates.
      * @throws FactoryException if an error occurred while creating a transform.
      */
     public static <T extends Quantity<T>> MathTransform createGeodeticTransformation(
@@ -229,7 +231,7 @@ public class InterpolatedTransform exten
      * Returns the number of input dimensions.
      * This fixed to {@link DatumShiftGrid#getTranslationDimensions()}.
      *
-     * @return The dimension of input points.
+     * @return the dimension of input points.
      */
     @Override
     public final int getSourceDimensions() {
@@ -240,7 +242,7 @@ public class InterpolatedTransform exten
      * Returns the number of target dimensions.
      * This fixed to {@link DatumShiftGrid#getTranslationDimensions()}.
      *
-     * @return The dimension of output points.
+     * @return the dimension of output points.
      */
     @Override
     public final int getTargetDimensions() {
@@ -353,7 +355,7 @@ public class InterpolatedTransform exten
      * Returns the inverse of this interpolated transform.
      * The source ellipsoid of the returned transform will be the target ellipsoid of this transform, and conversely.
      *
-     * @return A transform from the target ellipsoid to the source ellipsoid of this transform.
+     * @return a transform from the target ellipsoid to the source ellipsoid of this transform.
      */
     @Override
     public MathTransform inverse() {
@@ -429,7 +431,7 @@ public class InterpolatedTransform exten
          * Transforms a single coordinate in a list of ordinal values,
          * and optionally returns the derivative at that location.
          *
-         * @throws TransformException If there is no convergence.
+         * @throws TransformException if there is no convergence.
          */
         @Override
         public final Matrix transform(final double[] srcPts, final int srcOff, double[] dstPts, int dstOff,
@@ -450,7 +452,7 @@ public class InterpolatedTransform exten
                 final double oy = yi;
                 xi = x - vector[0];
                 yi = y - vector[1];
-                if (!(Math.abs(xi - ox) > tolerance ||    // Use '!' for catching NaN.
+                if (!(Math.abs(xi - ox) > tolerance ||          // Use '!' for catching NaN.
                       Math.abs(yi - oy) > tolerance))
                 {
                     if (dimension > GRID_DIMENSION) {
@@ -519,7 +521,7 @@ nextPoint:  while (--numPts >= 0) {
                     final double oy = yi;
                     xi = x - vector[0];
                     yi = y - vector[1];
-                    if (!(Math.abs(xi - ox) > tolerance ||    // Use '!' for catching NaN.
+                    if (!(Math.abs(xi - ox) > tolerance ||          // Use '!' for catching NaN.
                           Math.abs(yi - oy) > tolerance))
                     {
                         if (dimension > GRID_DIMENSION) {
@@ -536,7 +538,7 @@ nextPoint:  while (--numPts >= 0) {
                             do dstPts[dstOff + --i] += vector[i];
                             while (i > GRID_DIMENSION);
                         }
-                        dstPts[dstOff  ] = xi;      // Shall not be done before above loop.
+                        dstPts[dstOff  ] = xi;          // Shall not be done before above loop.
                         dstPts[dstOff+1] = yi;
                         dstOff += inc;
                         srcOff += inc;

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -33,7 +33,6 @@ 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.PatchedUnitFormat;
 import org.apache.sis.internal.referencing.provider.Affine;
 import org.apache.sis.internal.referencing.provider.LambertConformal2SP;
 import org.apache.sis.measure.Range;
@@ -486,8 +485,8 @@ public strictfp class CoordinateOperatio
      * or an empty string (never {@code null}) if none.
      */
     private static String getUnit(final ParameterDescriptor<?> param) {
-        final String unit = PatchedUnitFormat.toString(param.getUnit());
-        if (unit != null && !unit.isEmpty()) {
+        final String unit = param.getUnit().toString();
+        if (!unit.isEmpty()) {
             if (unit.equals("°")) {
                 return unit;
             }

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=1766204&r1=1766203&r2=1766204&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] Sat Oct 22 15:48:56 2016
@@ -20,7 +20,6 @@ import javax.measure.Unit;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.jaxb.gml.Measure;
-import org.apache.sis.internal.util.PatchedUnitFormat;
 
 
 /**
@@ -29,7 +28,7 @@ import org.apache.sis.internal.util.Patc
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.8
  * @module
  *
  * @see Measure
@@ -56,7 +55,7 @@ public class UnitAdapter extends XmlAdap
      */
     @Override
     public String marshal(final Unit<?> value) {
-        return PatchedUnitFormat.toString(value);
+        return (value != null) ? value.toString() : null;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -444,7 +444,7 @@ public abstract class CompoundFormat<T>
         } else if (valueType == Angle.class) {
             return AngleFormat.getInstance(locale);
         } else if (valueType == Unit.class) {
-            return UnitFormat.getInstance(locale);
+            return new UnitFormat(locale);
         } else if (valueType == Range.class) {
             return new RangeFormat(locale);
         } else if (valueType == Class.class) {

Added: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractConverter.java?rev=1766204&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractConverter.java (added)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractConverter.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -0,0 +1,70 @@
+/*
+ * 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 java.io.Serializable;
+import javax.measure.UnitConverter;
+
+
+/**
+ * Base class of unit converters.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+abstract class AbstractConverter implements UnitConverter, Serializable {
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -8480235641759297444L;
+
+    /**
+     * Creates a new converter.
+     */
+    AbstractConverter() {
+    }
+
+    /**
+     * If the conversion can be represented by a polynomial equation, returns the coefficients of that equation.
+     * Otherwise returns {@code null}.
+     */
+    Number[] coefficients() {
+        return isIdentity() ? new Number[0] : null;
+    }
+
+    /**
+     * Returns the derivative of the conversion function at the given value, or {@code NaN} if unknown.
+     */
+    public abstract double derivative(double value);
+
+    /**
+     * Delegates to {@link #derivative(double)} if the given converter is an Apache SIS implementation,
+     * or use a fallback otherwise.
+     */
+    static double derivative(final UnitConverter converter, final double value) {
+        if (converter != null) {
+            if (converter instanceof AbstractConverter) {
+                return ((AbstractConverter) converter).derivative(value);
+            } else if (converter.isLinear()) {
+                return converter.convert(1) - converter.convert(0);
+            }
+        }
+        return Double.NaN;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -18,7 +18,6 @@ package org.apache.sis.measure;
 
 import java.util.List;
 import java.util.ArrayList;
-import java.io.Serializable;
 import javax.measure.UnitConverter;
 import org.apache.sis.util.ArgumentChecks;
 
@@ -31,7 +30,7 @@ import org.apache.sis.util.ArgumentCheck
  * @version 0.8
  * @module
  */
-final class ConcatenatedConverter implements UnitConverter, Serializable {
+final class ConcatenatedConverter extends AbstractConverter {
     /**
      * For cross-version compatibility.
      */
@@ -109,6 +108,14 @@ final class ConcatenatedConverter implem
     }
 
     /**
+     * Returns the derivative of the conversion function at the given value, or {@code NaN} if unknown.
+     */
+    @Override
+    public double derivative(final double value) {
+        return derivative(c1, value) * derivative(c2, c1.convert(value));
+    }
+
+    /**
      * Concatenates this converter with another converter. The resulting converter is equivalent to first converting
      * by the specified converter (right converter), and then converting by this converter (left converter).
      */

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=1766204&r1=1766203&r2=1766204&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] Sat Oct 22 15:48:56 2016
@@ -18,7 +18,6 @@ package org.apache.sis.measure;
 
 import java.util.List;
 import java.util.Collections;
-import java.io.Serializable;
 import java.math.BigDecimal;
 import javax.measure.UnitConverter;
 import org.apache.sis.util.Debug;
@@ -46,7 +45,7 @@ import org.apache.sis.internal.util.Nume
  * @version 0.8
  * @module
  */
-final class LinearConverter implements UnitConverter, Serializable {
+final class LinearConverter extends AbstractConverter {
     /**
      * For cross-version compatibility.
      */
@@ -165,6 +164,21 @@ final class LinearConverter implements U
     }
 
     /**
+     * Returns the coefficient of this linear conversion.
+     */
+    @Override
+    @SuppressWarnings("fallthrough")
+    Number[] coefficients() {
+        final Number[] c = new Number[(scale != 1) ? 2 : (offset != 0) ? 1 : 0];
+        switch (c.length) {
+            case 2: c[1] = scale;
+            case 1: c[0] = offset;
+            case 0: break;
+        }
+        return c;
+    }
+
+    /**
      * Applies the linear conversion on the given IEEE 754 floating-point value.
      */
     @Override
@@ -204,6 +218,15 @@ final class LinearConverter implements U
     }
 
     /**
+     * Returns the derivative of the conversion at the given value.
+     * For a linear converter, the derivative is the same everywhere.
+     */
+    @Override
+    public double derivative(double value) {
+        return scale;
+    }
+
+    /**
      * Concatenates this converter with another converter. The resulting converter is equivalent to first converting
      * by the specified converter (right converter), and then converting by this converter (left converter).
      */

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Range.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -22,7 +22,6 @@ import java.util.FormattableFlags;
 import java.io.Serializable;
 import javax.measure.Unit;
 import org.apache.sis.internal.util.Utilities;
-import org.apache.sis.internal.util.PatchedUnitFormat;
 import org.apache.sis.util.collection.CheckedContainer;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Emptiable;
@@ -681,8 +680,8 @@ public class Range<E extends Comparable<
         }
         final Unit<?> unit = unit();
         if (unit != null) {
-            final String symbol = PatchedUnitFormat.toString(unit);
-            if (!symbol.isEmpty()) {
+            final String symbol = unit.toString();
+            if (symbol != null && !symbol.isEmpty()) {
                 if (Character.isLetterOrDigit(symbol.codePointAt(0))) {
                     buffer.append(' ');
                 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -342,7 +342,7 @@ public class RangeFormat extends Format
             unitFormat    = null;
         } else if (Number.class.isAssignableFrom(elementType)) {
             elementFormat = NumberFormat.getNumberInstance(locale);
-            unitFormat    = UnitFormat.getInstance(locale);
+            unitFormat    = new UnitFormat(locale);
         } else if (Date.class.isAssignableFrom(elementType)) {
             elementFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
             unitFormat    = null;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -18,36 +18,34 @@ package org.apache.sis.measure;
 
 import java.util.List;
 import java.util.Collections;
-import java.io.Serializable;
 import javax.measure.Unit;
 import javax.measure.quantity.Angle;
 import javax.measure.UnitConverter;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Vocabulary;
-import org.apache.sis.internal.util.PatchedUnitFormat;
 
 import static org.apache.sis.math.MathFunctions.truncate;
 
 
 /**
- * A converter from fractional degrees to sexagesimal degrees. Sexagesimal degrees are pseudo-unit
+ * A converter from decimal degrees to sexagesimal degrees. Sexagesimal degrees are pseudo-unit
  * in the <cite>sign - degrees - decimal point - minutes (two digits) - integer seconds (two digits) -
  * fraction of seconds (any precision)</cite> format.
  *
- * <p>When possible, Apache SIS always handles angles in radians, decimal degrees or any other
- * proportional units. Sexagesimal angles are considered a string representation issue (handled
- * by {@link AngleFormat}) rather than a unit issue. Unfortunately, this pseudo-unit is extensively
- * used in the EPSG database, so we have to support it.</p>
+ * <p>When possible, Apache SIS always handles angles in radians, decimal degrees or any other proportional units.
+ * Sexagesimal angles are considered a string representation issue (handled by {@link AngleFormat}) rather than a
+ * unit issue. Unfortunately, this pseudo-unit is extensively used in the EPSG database, so we have to support it.</p>
  *
  * <div class="section">Immutability and thread safety</div>
  * This class and all inner classes are immutable, and thus inherently thread-safe.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3
- * @version 0.6
+ * @version 0.8
  * @module
  */
-class SexagesimalConverter implements UnitConverter, Serializable {
+class SexagesimalConverter extends AbstractConverter {
     /**
      * Serial number for compatibility with different versions.
      */
@@ -70,12 +68,8 @@ class SexagesimalConverter implements Un
      * <p>This unit is non-linear and not practical for computation. Consequently, it should be
      * avoided as much as possible. This pseudo-unit is defined only because used in the EPSG
      * database (code 9111).</p>
-     *
-     * <p>This unit does not have an easily readable symbol because of the
-     * <a href="http://kenai.com/jira/browse/JSR_275-41">JSR-275 bug</a>.</p>
      */
-    static final Unit<Angle> DM = Units.DEGREE.transform(
-            new SexagesimalConverter(false, 100).inverse()).asType(Angle.class);//.alternate("D.M");
+    static final ConventionalUnit<Angle> DM;
 
     /**
      * Pseudo-unit for sexagesimal degree. Numbers in this pseudo-unit have the following format:
@@ -89,12 +83,8 @@ class SexagesimalConverter implements Un
      * <p>This unit is non-linear and not practical for computation. Consequently, it should be
      * avoided as much as possible. This pseudo-unit is defined only because extensively used in
      * the EPSG database (code 9110).</p>
-     *
-     * <p>This unit does not have an easily readable symbol because of the
-     * <a href="http://kenai.com/jira/browse/JSR_275-41">JSR-275 bug</a>.</p>
      */
-    static final Unit<Angle> DMS = Units.DEGREE.transform(
-            new SexagesimalConverter(true, 10000).inverse()).asType(Angle.class);//.alternate("D.MS");
+    static final Unit<Angle> DMS;
 
     /**
      * Pseudo-unit for degree - minute - second.
@@ -109,18 +99,19 @@ class SexagesimalConverter implements Un
      * <p>This unit is non-linear and not practical for computation. Consequently, it should be
      * avoided as much as possible. This pseudo-unit is defined only because extensively used in
      * EPSG database (code 9107).</p>
-     *
-     * <p>This unit does not have an easily readable symbol because of the
-     * <a href="http://kenai.com/jira/browse/JSR_275-41">JSR-275 bug</a>.</p>
-     */
-    static final Unit<Angle> DMS_SCALED = Units.DEGREE.transform(
-            new SexagesimalConverter(true, 1).inverse()).asType(Angle.class);//.alternate("DMS");
-
-    /*
-     * Declares the units that we were not able to declare in calls to Unit.alternate(String).
      */
+    static final Unit<Angle> DMS_SCALED;
     static {
-        PatchedUnitFormat.init(DM, "D.M", DMS, "D.MS", DMS_SCALED, "DMS");
+        final SystemUnit<Angle> rad = (SystemUnit<Angle>) Units.RADIAN;
+        final UnitConverter toRadian = Units.DEGREE.getConverterTo(rad);
+        DM = new ConventionalUnit<>(rad, new ConcatenatedConverter(
+                new SexagesimalConverter(false, 100).inverse(), toRadian), "D.M", (short) 9111);
+
+        DMS = new ConventionalUnit<>(rad, new ConcatenatedConverter(
+                new SexagesimalConverter(true, 10000).inverse(), toRadian), "D.MS", (short) 9110);
+
+        DMS_SCALED = new ConventionalUnit<>(rad, new ConcatenatedConverter(
+                new SexagesimalConverter(true, 1).inverse(), toRadian), "DMS", (short) 9107);
     }
 
     /**
@@ -225,11 +216,26 @@ class SexagesimalConverter implements Un
     }
 
     /**
-     * @todo not yet supported.
+     * Considers this converter as non-derivable. Actually it would be possible to provide a derivative value
+     * for input values other than the discontinuities points, but for now we presume that it is less dangerous
+     * to return NaN every time, so the user can not miss that this function is not derivable everywhere.
      */
     @Override
-    public UnitConverter concatenate(UnitConverter uc) {
-        throw new UnsupportedOperationException("Not supported yet.");
+    public final double derivative(double value) {
+        return Double.NaN;
+    }
+
+    /**
+     * Concatenates this converter with another converter. The resulting converter is equivalent to first converting
+     * by the specified converter (right converter), and then converting by this converter (left converter).
+     */
+    @Override
+    public UnitConverter concatenate(final UnitConverter converter) {
+        ArgumentChecks.ensureNonNull("converter", converter);
+        if (equals(converter.inverse())) {
+            return LinearConverter.IDENTITY;
+        }
+        return new ConcatenatedConverter(converter, this);
     }
 
     /**
@@ -250,7 +256,7 @@ class SexagesimalConverter implements Un
     }
 
     /**
-     * The inverse of {@link SexagesimalConverter}.
+     * The inverse of {@link SexagesimalConverter}, i.e. the converter from sexagesimal degrees to decimal degrees.
      */
     private static final class Inverse extends SexagesimalConverter {
         /**

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=1766204&r1=1766203&r2=1766204&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] Sat Oct 22 15:48:56 2016
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Locale;
 import java.text.Format;
 import java.text.FieldPosition;
@@ -39,6 +40,7 @@ import org.apache.sis.util.Characters;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.Localized;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.CorruptedObjectException;
 
 
 /**
@@ -46,18 +48,21 @@ import org.apache.sis.util.resources.Err
  * This class combines in a single class the API from {@link java.text} and the API from {@link javax.measure.format}.
  * In addition to the symbols of the <cite>Système international</cite> (SI), this class is also capable to handle
  * some symbols found in <cite>Well Known Text</cite> (WKT) definitions or in XML files.
-*
-* <div class="section">Parsing authority codes</div>
-* As a special case, if a character sequence given to the {@link #parse(CharSequence)} method is of the
-* {@code "EPSG:####"} or {@code "urn:ogc:def:uom:EPSG:####"} form (ignoring case and whitespaces),
-* then {@code "####"} is parsed as an integer and forwarded to the {@link Units#valueOfEPSG(int)} method.
-*
-* <div class="section">NetCDF unit symbols</div>
-* The attributes in NetCDF files often merge the axis direction with the angular unit,
-* as in {@code "degrees_east"} or {@code "degrees_north"}.
-* This class ignores those suffixes and unconditionally returns {@link Units#DEGREE} for all axis directions.
-* In particular, the units for {@code "degrees_west"} and {@code "degrees_east"} do <strong>not</strong> have
-* opposite sign. It is caller responsibility to handle the direction of axes associated to NetCDF units.
+ *
+ * <div class="section">Parsing authority codes</div>
+ * As a special case, if a character sequence given to the {@link #parse(CharSequence)} method is of the
+ * {@code "EPSG:####"} or {@code "urn:ogc:def:uom:EPSG:####"} form (ignoring case and whitespaces),
+ * then {@code "####"} is parsed as an integer and forwarded to the {@link Units#valueOfEPSG(int)} method.
+ *
+ * <div class="section">NetCDF unit symbols</div>
+ * The attributes in NetCDF files often merge the axis direction with the angular unit,
+ * as in {@code "degrees_east"} or {@code "degrees_north"}.
+ * This class ignores those suffixes and unconditionally returns {@link Units#DEGREE} for all axis directions.
+ * In particular, the units for {@code "degrees_west"} and {@code "degrees_east"} do <strong>not</strong> have
+ * opposite sign. It is caller responsibility to handle the direction of axes associated to NetCDF units.
+ *
+ * <div class="section">Multi-threading</div>
+ * {@code UnitFormat} is not thread-safe. Synchronization, if desired, is caller's responsibility.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.8
@@ -86,6 +91,8 @@ public class UnitFormat extends Format i
 
     /**
      * The default instance used by {@link Units#valueOf(String)} for parsing units of measurement.
+     * While {@code UnitFormat} is generally not thread-safe, this particular instance is safe if
+     * we never invoke any setter method.
      */
     static final UnitFormat INSTANCE = new UnitFormat();
 
@@ -146,26 +153,41 @@ public class UnitFormat extends Format i
     }
 
     /**
-     * Creates a new format for the given locale.
+     * Symbols or names to use for formatting unit in replacement of the default unit symbols or names.
      *
-     * @param   locale  the locale to use for parsing and formatting units.
-     * @return  a new {@code UnitFormat} instance using the given locale.
+     * @see #label(Unit, String)
      */
-    public static UnitFormat getInstance(final Locale locale) {
-        final UnitFormat f = new UnitFormat();
-        f.setLocale(locale);
-        return f;
-    }
+    private final Map<Unit<?>,String> labels;
 
     /**
-     * Creates a new format. This constructor is for subclasses only.
-     * Subclasses should {@linkplain #setLocale set the locale} to some default value.
+     * Units associated to a given label (in addition to the system-wide {@link UnitRegistry}).
+     * This map is the converse of {@link #labels}.
      *
-     * @see #getInstance(Locale)
+     * @see #label(Unit, String)
      */
-    protected UnitFormat() {
+    private final Map<String,Unit<?>> units;
+
+    /**
+     * Creates the unique {@link #INSTANCE}.
+     */
+    private UnitFormat() {
         locale = Locale.ROOT;
-        style = Style.SYMBOL;
+        style  = Style.SYMBOL;
+        labels = Collections.emptyMap();
+        units  = Collections.emptyMap();
+    }
+
+    /**
+     * Creates a new format for the given locale.
+     *
+     * @param   locale  the locale to use for parsing and formatting units.
+     */
+    public UnitFormat(final Locale locale) {
+        ArgumentChecks.ensureNonNull("locale", locale);
+        this.locale = locale;
+        style  = Style.SYMBOL;
+        labels = new HashMap<>();
+        units  = new HashMap<>();
     }
 
     /**
@@ -237,7 +259,20 @@ public class UnitFormat extends Format i
      */
     @Override
     public void label(final Unit<?> unit, final String label) {
-        // TODO
+        ArgumentChecks.ensureNonNull("unit",  unit);
+        ArgumentChecks.ensureNonNull("label", label);
+        final Unit<?> unitForOldLabel = units.remove(labels.put(unit, label));
+        final Unit<?> oldUnitForLabel = units.put(label, unit);
+        if (!unit.equals(oldUnitForLabel) && !label.equals(labels.remove(oldUnitForLabel))) {
+            // Assuming there is no bug in our algorithm, this exception should never happen
+            // unless this UnitFormat has been modified concurrently in another thread.
+            throw new CorruptedObjectException("labels");
+        }
+        if (unitForOldLabel != null && !unitForOldLabel.equals(unit)) {
+            // Assuming there is no bug in our algorithm, this exception should never happen
+            // unless this UnitFormat has been modified concurrently in another thread.
+            throw new CorruptedObjectException("units");
+        }
     }
 
     /**
@@ -250,10 +285,6 @@ public class UnitFormat extends Format i
      */
     @Override
     public Appendable format(final Unit<?> unit, final Appendable toAppendTo) throws IOException {
-        String symbol = org.apache.sis.internal.util.PatchedUnitFormat.getSymbol(unit);
-        if (symbol != null) {
-            return toAppendTo.append(symbol);
-        }
         if (style == Style.NAME) {
             /*
              * Following are specific to the WKT format, which is currently the only user of this method.
@@ -272,7 +303,7 @@ public class UnitFormat extends Format i
                 return toAppendTo.append("parts per million");
             }
         }
-        symbol = unit.getSymbol();
+        String symbol = unit.getSymbol();
         if (symbol != null) {
             return toAppendTo.append(symbol);
         }

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=1766204&r1=1766203&r2=1766204&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 Oct 22 15:48:56 2016
@@ -974,43 +974,87 @@ public final class Units extends Static
 
     /**
      * Returns the factor by which to multiply the standard unit in order to get the given unit.
-     * The "standard" unit is usually the SI unit on which the given unit is based.
+     * The "standard" unit is usually the SI unit on which the given unit is based, as given by
+     * {@link Unit#getSystemUnit()}.
      *
-     * <p><b>Example:</b> if the given unit is <var>kilometre</var>, then this method returns 1000
-     * since a measurement in kilometres must be multiplied by 1000 in order to give the equivalent
-     * measurement in the "standard" units (here <var>metres</var>).</p>
-     *
-     * @param  <Q>   the quantity measured by the unit.
-     * @param  unit  the unit for which we want the multiplication factor to standard unit.
-     * @return the factor by which to multiply a measurement in the given unit in order to
-     *         get an equivalent measurement in the standard unit.
+     * <div class="note"><b>Example:</b>
+     * if the given unit is {@link #KILOMETRE}, then this method returns 1000 since a measurement in kilometres
+     * must be multiplied by 1000 in order to give the equivalent measurement in the "standard" units
+     * (here {@link #METRE}).</div>
+     *
+     * If the given unit is {@code null} or if the conversion to the "standard" unit can not be expressed
+     * by a single multiplication factor, then this method returns {@link Double#NaN}.
+     *
+     * @param  <Q>   the quantity measured by the unit, or {@code null}.
+     * @param  unit  the unit for which we want the multiplication factor to standard unit, or {@code null}.
+     * @return the factor by which to multiply a measurement in the given unit in order to get an equivalent
+     *         measurement in the standard unit, or NaN if the conversion can not be expressed by a scale factor.
      */
-    @Workaround(library="JSR-275", version="0.9.3")
     public static <Q extends Quantity<Q>> double toStandardUnit(final Unit<Q> unit) {
-        return derivative(unit.getConverterTo(unit.getSystemUnit()), 0);
+        if (unit != null) {
+            final UnitConverter converter = unit.getConverterTo(unit.getSystemUnit());
+            if (converter.isLinear() && converter.convert(0) == 0) {
+                // Above check for converter(0) is a paranoiac check since
+                // JSR-363 said that a "linear" converter has no offset.
+                return converter.convert(1);
+            }
+        }
+        return Double.NaN;
     }
 
     /**
-     * Returns an estimation of the derivative of the given converter at the given value.
-     * This method is a workaround for a method which existed in previous JSR-275 API but
-     * have been removed in more recent releases.
+     * Returns the coefficients of the given converter expressed as a polynomial equation.
+     * This method returns the first of the following choices that apply:
      *
-     * <p>Current implementation computes the derivative as below:</p>
+     * <ul>
+     *   <li>If the given converter {@linkplain UnitConverter#isIdentity() is identity}, returns an empty array.</li>
+     *   <li>If the given converter shifts the values without scaling them (for example the conversion from Kelvin to
+     *       Celsius degrees), returns an array of length 1 containing only the offset.</li>
+     *   <li>If the given converter scales the values (optionally in addition to shifting them), returns an array of
+     *       length 2 containing the offset and scale factor, in that order.</li>
+     * </ul>
+     *
+     * This method returns {@code null} if it can not get the polynomial equation coefficients from the given converter.
+     *
+     * @param  converter  the converter from which to get the coefficients of the polynomial equation, or {@code null}.
+     * @return the polynomial equation coefficients (may be any length, including zero), or {@code null} if the given
+     *         converter is {@code null} or if this method can not get the coefficients.
      *
-     * {@preformat java
-     *     return converter.convert(value + 1) - converter.convert(value);
-     * }
-     *
-     * The above is exact for linear converters, which is the case of the vast majority of unit converters in use.
-     * It may not be exact for a few unusual converter like the one from sexagesimal degrees to decimal degrees.
+     * @since 0.8
+     */
+    public static Number[] coefficients(final UnitConverter converter) {
+        if (converter != null) {
+            if (converter instanceof AbstractConverter) {
+                return ((AbstractConverter) converter).coefficients();
+            }
+            if (converter.isIdentity()) {
+                return new Number[0];
+            }
+            if (converter.isLinear()) {
+                final double offset = converter.convert(0);  // Should be zero as per JSR-363 specification, but we are paranoiac.
+                final double scale  = converter.convert(1) - offset;
+                final Number[] c = new Number[(scale != 1) ? 2 : (offset != 0) ? 1 : 0];
+                switch (c.length) {
+                    case 2: c[1] = scale;
+                    case 1: c[0] = offset;
+                    case 0: break;
+                }
+                return c;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the derivative of the given converter at the given value,
+     * or {@code NaN} if this method can not compute it.
      *
-     * @param  converter  the converter for which we want the derivative at a given point.
+     * @param  converter  the converter for which we want the derivative at a given point, or {@code null}.
      * @param  value      the point at which to compute the derivative.
-     * @return the derivative at the given point.
+     * @return the derivative at the given point, or {@code NaN} if unknown.
      */
-    @Workaround(library="JSR-275", version="0.9.3")
     public static double derivative(final UnitConverter converter, final double value) {
-        return converter.convert(value + 1) - converter.convert(value);
+        return AbstractConverter.derivative(converter, value);
     }
 
     /**
@@ -1118,7 +1162,27 @@ public final class Units extends Static
      * @see org.apache.sis.referencing.factory.GeodeticAuthorityFactory#createUnit(String)
      */
     public static Unit<?> valueOfEPSG(final int code) {
-        return (code > 0 && code <= Short.MAX_VALUE) ? (Unit<?>) UnitRegistry.get((short) code) : null;
+        /*
+         * The switch for the SexagesimalConverter cases are needed since we did not put those units
+         * in the UnitRegistry map for reducing a little bit class loading in the common cases where
+         * those units are not needed. Other cases are redundant with the UnitRegistry check, but we
+         * add them opportunistically as a shortcut since those units are frequently used.
+         */
+        switch (code) {
+            case Constants.EPSG_PARAM_DEGREES:  // Fall through
+            case Constants.EPSG_AXIS_DEGREES:   return DEGREE;
+            case Constants.EPSG_METRE:          return METRE;
+
+            case 9107: // Fall through
+            case 9108: return SexagesimalConverter.DMS_SCALED;
+            case 9110: return SexagesimalConverter.DMS;
+            case 9111: return SexagesimalConverter.DM;
+            case 9203: // Fall through
+            case 9201: return UNITY;
+            default: {
+                return (code > 0 && code <= Short.MAX_VALUE) ? (Unit<?>) UnitRegistry.get((short) code) : null;
+            }
+        }
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -43,7 +43,9 @@ import static java.lang.Character.*;
 public final class StringBuilders extends Static {
     /**
      * Letters in the range 00C0 (192) to 00FF (255) inclusive with their accent removed, when possible.
-     * This string partially duplicates the work done by {@link java.text.Normalizer}.
+     * This string partially duplicates the work done by {@link Normalizer} with additional replacements.
+     * We use it for more direct character replacements (compared to using {@code Normalizer} than removing
+     * combining marks) for those common and easy cases.
      */
     private static final String ASCII = "AAAAAAÆCEEEEIIIIDNOOOOO*OUUUUYÞsaaaaaaæceeeeiiiionooooo/ouuuuyþy";
     // Original letters (with accent) = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -30,7 +30,6 @@ import java.util.ResourceBundle;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.lang.reflect.Modifier;
-import javax.measure.Unit;
 import org.opengis.util.CodeList;
 import org.opengis.util.ControlledVocabulary;
 import org.opengis.util.InternationalString;
@@ -42,7 +41,6 @@ import org.apache.sis.util.CharSequences
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.internal.system.Loggers;
-import org.apache.sis.internal.util.PatchedUnitFormat;
 
 
 /**
@@ -411,8 +409,6 @@ public class IndexedResourceBundle exten
                 replacement = Classes.getShortName(getPublicType((Class<?>) element));
             } else if (element instanceof ControlledVocabulary) {
                 replacement = Types.getCodeTitle((ControlledVocabulary) element).toString(getLocale());
-            } else if (element instanceof Unit<?>) {
-                replacement = PatchedUnitFormat.toString((Unit<?>) element);
             }
             // No need to check for Numbers or Dates instances, since they are
             // properly formatted in the ResourceBundle locale by MessageFormat.

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -19,7 +19,6 @@ package org.apache.sis.measure;
 import javax.measure.Unit;
 import javax.measure.Quantity;
 import javax.measure.UnitConverter;
-import org.apache.sis.internal.util.PatchedUnitFormat;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -94,13 +93,12 @@ public final strictfp class SexagesimalC
     }
 
     /**
-     * Tests {@link PatchedUnitFormat#toString(Unit)}.
-     * Tested here because it can be tested only after {@link SexagesimalConverter} initialization.
+     * Verifies the unit symbols.
      */
     @Test
-    public void testPatchedUnitFormat() {
-        assertEquals("D.M",  PatchedUnitFormat.toString(DM));
-        assertEquals("D.MS", PatchedUnitFormat.toString(DMS));
-        assertEquals("DMS",  PatchedUnitFormat.toString(DMS_SCALED));
+    public void testToString() {
+        assertEquals("D.M",  DM.toString());
+        assertEquals("D.MS", DMS.toString());
+        assertEquals("DMS",  DMS_SCALED.toString());
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java?rev=1766204&r1=1766203&r2=1766204&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java [UTF-8] Sat Oct 22 15:48:56 2016
@@ -119,5 +119,11 @@ public final strictfp class StringBuilde
         s.setLength(0);
         toASCII(s.append("℃, K, m⋅s"));
         assertEquals("°C, K, m*s", s.toString());
+        /*
+         * Tests the shortcut code path.
+         */
+        s.setLength(0);
+        toASCII(s.append("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"));
+        assertEquals(    "AAAAAAÆCEEEEIIIIDNOOOOO*OUUUUYÞsaaaaaaæceeeeiiiionooooo/ouuuuyþy", s.toString());
     }
 }



Mime
View raw message