sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1547939 [1/2] - in /sis/branches/JDK7: core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/ c...
Date Wed, 04 Dec 2013 22:34:19 GMT
Author: desruisseaux
Date: Wed Dec  4 22:34:18 2013
New Revision: 1547939

URL: http://svn.apache.org/r1547939
Log:
Consolidation before to work on the GML versions problem.

Added:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java
      - copied, changed from r1546824, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/SexagesimalConverterTest.java
      - copied, changed from r1546824, sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/CodeListMarshallingTest.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/UnitsTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/XMLTestCase.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/IOUtilitiesTest.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -18,6 +18,7 @@ package org.apache.sis.internal.jaxb.gml
 
 import javax.xml.bind.annotation.XmlID;
 import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
 import org.apache.sis.util.Version;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.IdentifierMap;
@@ -39,6 +40,7 @@ import org.apache.sis.xml.IdentifiedObje
  * @version 0.4
  * @module
  */
+@XmlTransient
 public abstract class GMLAdapter {
     /**
      * A GML version suitable for calls to {@link org.apache.sis.internal.jaxb.Context#isGMLVersion}.

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -470,7 +470,8 @@ class PropertyAccessor {
              * most of the time the key name will have exactly the expected case and using
              * directly the given String instance allow usage of its cached hash code value.
              */
-            final String key = CharSequences.trimWhitespaces(name.replace(" ", "").toLowerCase(Locale.ROOT));
+            final String key = CharSequences.trimWhitespaces(
+                    CharSequences.replace(name, " ", "").toString().toLowerCase(Locale.ROOT));
             if (key == name || (index = mapping.get(key)) == null) { // Identity comparison is okay here.
                 if (!mandatory) {
                     return -1;

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -56,8 +56,7 @@ public class DefaultResolution extends I
     private static final long serialVersionUID = 3856547985745400172L;
 
     /**
-     * Either the scale as a {@link RepresentativeFraction} instance or the distance
-     * as a {@code Double} instance.
+     * Either the scale as a {@link RepresentativeFraction} instance or the distance as a {@code Double} instance.
      */
     private Object scaleOrDistance;
 

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/CodeListMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/CodeListMarshallingTest.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/CodeListMarshallingTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/CodeListMarshallingTest.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -153,16 +153,13 @@ public final strictfp class CodeListMars
      */
     @Test
     public void testExtraCodes() throws JAXBException {
-        final MarshallerPool pool = getMarshallerPool();
-        final Marshaller marshaller = pool.acquireMarshaller();
         final DefaultDataIdentification id = new DefaultDataIdentification();
         id.setTopicCategories(Arrays.asList(
                 TopicCategory.valueOf("oceans"), // New code
                 TopicCategory.valueOf("OCEANS"), // Existing code with UML id="oceans"
                 TopicCategory.valueOf("test"))); // New code
 
-        final String xml = marshal(marshaller, id);
-        pool.recycle(marshaller);
+        final String xml = marshal(id);
 
         // "OCEANS" is marshalled as "oceans" because is contains a UML id, which is lower-case.
         assertEquals(2, CharSequences.count(xml, "<gmd:MD_TopicCategoryCode>oceans</gmd:MD_TopicCategoryCode>"));

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/MetadataMarshallingTest.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -19,8 +19,6 @@ package org.apache.sis.xml;
 import java.util.Locale;
 import java.net.URL;
 import java.io.IOException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
 import org.opengis.util.InternationalString;
 import org.apache.sis.util.iso.SimpleInternationalString;
@@ -102,11 +100,8 @@ public final strictfp class MetadataMars
      */
     @Test
     public void testPositionalAccuracy() throws IOException, JAXBException {
-        final MarshallerPool pool         = getMarshallerPool();
-        final Marshaller     marshaller   = pool.acquireMarshaller();
-        final Unmarshaller   unmarshaller = pool.acquireUnmarshaller();
-        final URL            resource     = getResource("PositionalAccuracy.xml");
-        final Object         metadata     = XML.unmarshal(resource);
+        final URL    resource = getResource("PositionalAccuracy.xml");
+        final Object metadata = XML.unmarshal(resource);
         assertInstanceOf("PositionalAccuracy.xml", AbstractElement.class, metadata);
         final InternationalString nameOfMeasure = getSingleton(((AbstractElement) metadata).getNamesOfMeasure());
         /*
@@ -125,9 +120,7 @@ public final strictfp class MetadataMars
         /*
          * Final comparison: ensure that we didn't lost any information.
          */
-        assertXmlEquals(resource, marshal(marshaller, metadata), "xmlns:*", "xsi:schemaLocation", "xsi:type");
-        pool.recycle(unmarshaller);
-        pool.recycle(marshaller);
+        assertXmlEquals(resource, marshal(metadata), "xmlns:*", "xsi:schemaLocation", "xsi:type");
     }
 
     /**
@@ -141,9 +134,6 @@ public final strictfp class MetadataMars
      */
     @Test
     public void testProcessStep() throws IOException, JAXBException {
-        final MarshallerPool     pool         = getMarshallerPool();
-        final Marshaller         marshaller   = pool.acquireMarshaller();
-        final Unmarshaller       unmarshaller = pool.acquireUnmarshaller();
         final DefaultProcessing  processing   = new DefaultProcessing();
         final DefaultProcessStep processStep  = new DefaultProcessStep("Some process step.");
         processing.setProcedureDescription(new SimpleInternationalString("Some procedure."));
@@ -151,15 +141,13 @@ public final strictfp class MetadataMars
         /*
          * XML marshalling, and compare with the content of "ProcessStep.xml" file.
          */
-        final String xml = marshal(marshaller, processStep);
+        final String xml = marshal(processStep);
         assertTrue(xml.startsWith("<?xml"));
         assertXmlEquals(getResource("ProcessStep.xml"), xml, "xmlns:*", "xsi:schemaLocation");
         /*
          * Final comparison: ensure that we didn't lost any information.
          */
-        assertEquals(processStep, unmarshal(unmarshaller, xml));
-        pool.recycle(unmarshaller);
-        pool.recycle(marshaller);
+        assertEquals(processStep, unmarshal(DefaultProcessStep.class, xml));
     }
 
     /**
@@ -176,9 +164,6 @@ public final strictfp class MetadataMars
      */
     @Test
     public void testExtent() throws IOException, JAXBException {
-        final MarshallerPool pool         = getMarshallerPool();
-        final Marshaller     marshaller   = pool.acquireMarshaller();
-        final Unmarshaller   unmarshaller = pool.acquireUnmarshaller();
         final DefaultGeographicBoundingBox bbox = new DefaultGeographicBoundingBox(-99, -79, 14.9844, 31);
         bbox.getIdentifierMap().put(IdentifierSpace.ID, "bbox");
         final DefaultTemporalExtent temporal = new DefaultTemporalExtent();
@@ -190,14 +175,12 @@ public final strictfp class MetadataMars
         /*
          * XML marshalling, and compare with the content of "ProcessStep.xml" file.
          */
-        final String xml = marshal(marshaller, extent);
+        final String xml = marshal(extent);
         assertTrue(xml.startsWith("<?xml"));
         assertXmlEquals(getResource("Extent.xml"), xml, "xmlns:*", "xsi:schemaLocation");
         /*
          * Final comparison: ensure that we didn't lost any information.
          */
-        assertEquals(extent, unmarshal(unmarshaller, xml));
-        pool.recycle(unmarshaller);
-        pool.recycle(marshaller);
+        assertEquals(extent, unmarshal(DefaultExtent.class, xml));
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -923,7 +923,7 @@ public final class Matrices extends Stat
                      */
                     int s = element.lastIndexOf('.');
                     if (s < 0) {
-                        element = element.replace("Infinity", "∞");
+                        element = CharSequences.replace(element, "Infinity", "∞").toString();
                         width = spacing + element.length();
                         widthBeforeFraction[i] = (byte) Math.max(widthBeforeFraction[i], width);
                     } else {

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -17,7 +17,11 @@
 package org.apache.sis.referencing.datum;
 
 import javax.measure.unit.NonSI;
+import javax.xml.bind.Marshaller;
 import javax.xml.bind.JAXBException;
+import org.apache.sis.xml.Namespaces;
+import org.apache.sis.xml.MarshallerPool;
+import org.apache.sis.util.CharSequences;
 import org.junit.Test;
 
 import static org.apache.sis.referencing.Assert.*;
@@ -43,6 +47,49 @@ public final strictfp class DefaultPrime
     }
 
     /**
+     * Compares the given XML representation of Greenwich prime meridian against the expected XML.
+     * The XML is expected to use the given GML namespace URI.
+     *
+     * @param namespace The expected GML namespace.
+     * @param actual XML representation of Greenwich prime meridian to test.
+     */
+    private static void assertGreenwichXmlEquals(final String namespace, final String actual) {
+        assertXmlEquals(CharSequences.replace(
+                "<gml:PrimeMeridian xmlns:gml=\"" + Namespaces.GML + "\">\n" +
+                "  <gml:name codeSpace=\"test\">Greenwich</gml:name>\n" +
+                "  <gml:greenwichLongitude uom=\"urn:ogc:def:uom:EPSG::9102\">0.0</gml:greenwichLongitude>\n" +
+                "</gml:PrimeMeridian>\n",
+                Namespaces.GML, namespace).toString(), actual, "xmlns:*", "xsi:schemaLocation");
+    }
+
+    /**
+     * Tests marshalling in the default namespace.
+     *
+     * @throws JAXBException If an error occurred during marshalling.
+     */
+    @Test
+    public void testMarshall() throws JAXBException {
+        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
+        assertGreenwichXmlEquals(Namespaces.GML, marshal(pm));
+    }
+
+    /**
+     * Tests marshalling in the GML 3.1 namespace.
+     *
+     * @throws JAXBException If an error occurred during marshalling.
+     */
+    @Test
+    @org.junit.Ignore
+    public void testMarshallGML31() throws JAXBException {
+        final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
+        final MarshallerPool pool = getMarshallerPool();
+        final Marshaller marshaller = pool.acquireMarshaller();
+        final String xml = marshal(marshaller, pm);
+        pool.recycle(marshaller);
+        assertGreenwichXmlEquals("http://www.opengis.net/gml", marshal(pm));
+    }
+
+    /**
      * Tests unmarshalling.
      *
      * @throws JAXBException If an error occurred during unmarshalling.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Distance.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -58,6 +58,7 @@ public final class GO_Distance extends X
      */
     private GO_Distance(final Double value) {
         distance = new Measure(value, SI.METRE);
+        distance.asXPointer = true;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Measure.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -58,6 +58,7 @@ public final class GO_Measure extends Xm
      */
     private GO_Measure(final Double value) {
         measure = new Measure(value, SI.METRE);
+        measure.asXPointer = true;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -25,6 +25,7 @@ import javax.xml.bind.annotation.XmlAttr
 import org.apache.sis.internal.jaxb.gmd.CodeListProxy;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.measure.Units;
 
 
 /**
@@ -62,9 +63,6 @@ import org.apache.sis.util.resources.Err
  * @module
  *
  * @see org.apache.sis.measure.Measure
- *
- * @todo We should annotate {@link org.apache.sis.measure.Measure} directly
- *       if we can find some way to use {@code @XmlValue} with that class.
  */
 public final class Measure {
     /**
@@ -79,6 +77,12 @@ public final class Measure {
     public Unit<?> unit;
 
     /**
+     * {@code true} if the units shall be formatted as {@code xpointer}.
+     * If {@code false} (the default), then this class will try to format the units using the GML syntax.
+     */
+    boolean asXPointer;
+
+    /**
      * Default empty constructor for JAXB. The value is initialized to NaN,
      * but JAXB will overwrite this value if a XML value is presents.
      */
@@ -101,7 +105,13 @@ public final class Measure {
     /**
      * Constructs a string representation of the units as defined in the ISO-19103 standard.
      * This method is invoked during XML marshalling. For example in the units are "metre",
-     * then this method returns:
+     * then this method returns one of the following strings, in preference order:
+     *
+     * {@preformat text
+     *     urn:ogc:def:uom:EPSG::9001
+     * }
+     *
+     * or
      *
      * {@preformat text
      *     http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])
@@ -119,16 +129,20 @@ public final class Measure {
     @XmlAttribute(required = true)
     public String getUOM() {
         final Unit<?> unit = this.unit;
-        final String symbol;
         if (unit == null || unit.equals(Unit.ONE)) {
-            symbol = "";
-        } else if (unit.equals(NonSI.PIXEL)) {
-            symbol = "pixel";
-        } else {
-            symbol = Context.schema(Context.current(), "gmd", CodeListProxy.DEFAULT_SCHEMA)
-                    .append("resources/uom/gmxUom.xml#xpointer(//*[@gml:id='").append(unit).append("'])").toString();
+            return "";
+        }
+        if (unit.equals(NonSI.PIXEL)) {
+            return "pixel"; // TODO: maybe not the most appropriate unit.
+        }
+        if (!asXPointer) {
+            final Integer code = Units.getEpsgCode(unit);
+            if (code != null) {
+                return "urn:ogc:def:uom:EPSG::" + code;
+            }
         }
-        return symbol;
+        return Context.schema(Context.current(), "gmd", CodeListProxy.DEFAULT_SCHEMA)
+                .append("resources/uom/gmxUom.xml#xpointer(//*[@gml:id='").append(unit).append("'])").toString();
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/SexagesimalConverter.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -18,7 +18,9 @@ package org.apache.sis.measure;
 
 import java.math.BigDecimal;
 import java.math.MathContext;
-import java.io.ObjectStreamException;
+import javax.measure.unit.Unit;
+import javax.measure.unit.NonSI;
+import javax.measure.quantity.Angle;
 import javax.measure.converter.UnitConverter;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.util.resources.Errors;
@@ -56,21 +58,73 @@ class SexagesimalConverter extends UnitC
     static final double EPS = 1E-10;
 
     /**
-     * The converter for DMS units.
+     * Pseudo-unit for sexagesimal degree. Numbers in this pseudo-unit have the following format:
+     *
+     * <cite>sign - degrees - decimal point - minutes (two digits) - fraction of minutes (any precision)</cite>.
+     *
+     * Using this unit is loosely equivalent to formatting decimal degrees with the
+     * {@code "D.MMm"} {@link AngleFormat} pattern.
+     *
+     * <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 = NonSI.DEGREE_ANGLE.transform(
+            new SexagesimalConverter(false, 100).inverse()).asType(Angle.class);//.alternate("D.M");
+
+    /**
+     * Pseudo-unit for sexagesimal degree. Numbers in this pseudo-unit have the following format:
+     *
+     * <cite>sign - degrees - decimal point - minutes (two digits) - integer seconds (two digits) -
+     * fraction of seconds (any precision)</cite>.
+     *
+     * Using this unit is loosely equivalent to formatting decimal degrees with the
+     * {@code "D.MMSSs"} {@link AngleFormat} pattern.
+     *
+     * <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 = NonSI.DEGREE_ANGLE.transform(
+            new SexagesimalConverter(true, 10000).inverse()).asType(Angle.class);//.alternate("D.MS");
+
+    /**
+     * Pseudo-unit for degree - minute - second.
+     * Numbers in this pseudo-unit have the following format:
+     *
+     * <cite>signed degrees (integer) - arc-minutes (integer) - arc-seconds
+     * (real, any precision)</cite>.
+     *
+     * Using this unit is loosely equivalent to formatting decimal degrees with the
+     * {@code "DMMSS.s"} {@link AngleFormat} pattern.
+     *
+     * <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 SexagesimalConverter INTEGER = new SexagesimalConverter(1);
+    static final Unit<Angle> DMS_SCALED = NonSI.DEGREE_ANGLE.transform(
+            new SexagesimalConverter(true, 1).inverse()).asType(Angle.class);//.alternate("DMS");
 
     /**
-     * The converter for D.MS units.
+     * {@code true} if the seconds field is present.
      */
-    static final SexagesimalConverter FRACTIONAL = new SexagesimalConverter(10000);
+    final boolean hasSeconds;
 
     /**
      * The value to divide DMS unit by.
      * For "degree minute second" (EPSG code 9107), this is 1.
      * For "sexagesimal degree" (EPSG code 9110), this is 10000.
      */
-    final int divider;
+    final double divider;
 
     /**
      * The inverse of this converter.
@@ -80,22 +134,25 @@ class SexagesimalConverter extends UnitC
     /**
      * Constructs a converter for sexagesimal units.
      *
+     * @param hasSeconds {@code true} if the seconds field is present.
      * @param divider The value to divide DMS unit by.
      *        For "degree minute second" (EPSG code 9107), this is 1.
      *        For "sexagesimal degree" (EPSG code 9110), this is 10000.
      */
-    private SexagesimalConverter(final int divider) {
-        this.divider = divider;
-        this.inverse = new Inverse(this);
+    private SexagesimalConverter(final boolean hasSeconds, final double divider) {
+        this.hasSeconds = hasSeconds;
+        this.divider    = divider;
+        this.inverse    = new Inverse(this);
     }
 
     /**
      * Constructs a converter for sexagesimal units.
      * This constructor is for {@link Inverse} usage only.
      */
-    private SexagesimalConverter(final int divider, final UnitConverter inverse) {
-        this.divider = divider;
-        this.inverse = inverse;
+    private SexagesimalConverter(final SexagesimalConverter inverse) {
+        this.hasSeconds = inverse.hasSeconds;
+        this.divider    = inverse.divider;
+        this.inverse    = inverse;
     }
 
     /**
@@ -111,11 +168,16 @@ class SexagesimalConverter extends UnitC
      */
     @Override
     public double convert(double angle) {
-        final double deg,min,sec;  deg = truncate(angle);
-        angle = (angle-deg)*60;    min = truncate(angle);
-        angle = (angle-min)*60;    sec = truncate(angle);
-        angle -= sec; // The remainer (fraction of seconds)
-        return (((deg*100 + min)*100 + sec) + angle) / divider;
+        final double deg = truncate(angle);
+        angle = (angle - deg) * 60;
+        if (hasSeconds) {
+            final double min = truncate(angle);
+            angle  = (angle - min) * 60; // Secondes
+            angle += (deg*100 + min)*100;
+        } else {
+            angle += deg * 100;
+        }
+        return angle / divider;
     }
 
     /**
@@ -141,27 +203,8 @@ class SexagesimalConverter extends UnitC
      * Returns a hash value for this converter.
      */
     @Override
-    public int hashCode() {
-        return divider ^ (int) serialVersionUID;
-    }
-
-    /**
-     * On deserialization, returns an existing instance.
-     */
-    protected final Object readResolve() throws ObjectStreamException {
-        UnitConverter candidate = INTEGER;
-        for (int i=0; i<4; i++) {
-            switch (i) {
-                case 0:  break; // Do nothing since candidate is already set to INTEGER.
-                case 1:  // Fallthrough
-                case 3:  candidate = candidate.inverse(); break;
-                case 2:  candidate = FRACTIONAL; break;
-            }
-            if (equals(candidate)) {
-                return candidate;
-            }
-        }
-        return this;
+    public final int hashCode() {
+        return ((int) divider) ^ getClass().hashCode();
     }
 
     /**
@@ -178,7 +221,7 @@ class SexagesimalConverter extends UnitC
          * Constructs a converter.
          */
         public Inverse(final SexagesimalConverter inverse) {
-            super(inverse.divider, inverse);
+            super(inverse);
         }
 
         /**
@@ -189,9 +232,16 @@ class SexagesimalConverter extends UnitC
         @Override
         public double convert(final double angle) throws IllegalArgumentException {
             double deg,min,sec;
-            sec = angle * divider;
-            deg = truncate(sec/10000); sec -= 10000*deg;
-            min = truncate(sec/  100); sec -=   100*min;
+            if (hasSeconds) {
+                sec = angle * divider;
+                deg = truncate(sec/10000); sec -= 10000*deg;
+                min = truncate(sec/  100); sec -=   100*min;
+            } else {
+                sec = 0;
+                min = angle * divider;
+                deg = truncate(min / 100);
+                min -= deg * 100;
+            }
             if (min <= -60 || min >= 60) {  // Do not enter for NaN
                 if (Math.abs(Math.abs(min) - 100) <= (EPS * 100)) {
                     if (min >= 0) deg++; else deg--;
@@ -222,13 +272,5 @@ class SexagesimalConverter extends UnitC
         private static IllegalArgumentException illegalField(final double value, final double field, final int unit) {
             return new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentField_4, "angle", value, unit, field));
         }
-
-        /**
-         * Returns a hash value for this converter.
-         */
-        @Override
-        public int hashCode() {
-            return divider ^ (int) serialVersionUID;
-        }
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -16,10 +16,6 @@
  */
 package org.apache.sis.measure;
 
-import java.util.Map;
-import java.util.HashMap;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
 import javax.measure.unit.SI;
 import javax.measure.unit.NonSI;
 import javax.measure.unit.Unit;
@@ -72,45 +68,6 @@ public final class Units extends Static 
     public static final Unit<Duration> MILLISECOND = SI.MetricPrefix.MILLI(SI.SECOND);
 
     /**
-     * Pseudo-unit for sexagesimal degree. Numbers in this pseudo-unit have the following format:
-     *
-     * <cite>sign - degrees - decimal point - minutes (two digits) - integer seconds (two digits) -
-     * fraction of seconds (any precision)</cite>.
-     *
-     * Using this unit is loosely equivalent to formatting decimal degrees with the
-     * {@code "D.MMSSs"} {@link AngleFormat} pattern.
-     *
-     * <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> SEXAGESIMAL_DMS = NonSI.DEGREE_ANGLE.transform(
-            SexagesimalConverter.FRACTIONAL.inverse()).asType(Angle.class);//.alternate("D.MS");
-
-    /**
-     * Pseudo-unit for degree - minute - second.
-     * Numbers in this pseudo-unit have the following format:
-     *
-     * <cite>signed degrees (integer) - arc-minutes (integer) - arc-seconds
-     * (real, any precision)</cite>.
-     *
-     * Using this unit is loosely equivalent to formatting decimal degrees with the
-     * {@code "DMMSS.s"} {@link AngleFormat} pattern.
-     *
-     * <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> DEGREE_MINUTE_SECOND = NonSI.DEGREE_ANGLE.transform(
-            SexagesimalConverter.INTEGER.inverse()).asType(Angle.class);//.alternate("DMS");
-
-    /**
      * Parts per million.
      *
      * <p>This unit does not have an easily readable symbol because of the
@@ -119,33 +76,6 @@ public final class Units extends Static 
     public static final Unit<Dimensionless> PPM = Unit.ONE.times(1E-6);//.alternate("ppm");
 
     /**
-     * A few units commonly used in GIS.
-     */
-    private static final Map<Unit<?>,Unit<?>> COMMONS = new HashMap<>(48);
-    static {
-        COMMONS.put(PPM, PPM);
-        boolean nonSI = false;
-        do for (final Field field : (nonSI ? NonSI.class : SI.class).getFields()) {
-            final int modifiers = field.getModifiers();
-            if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) {
-                final Object value;
-                try {
-                    value = field.get(null);
-                } catch (IllegalAccessException e) {
-                    // Should not happen since we asked only for public static constants.
-                    throw new AssertionError(e);
-                }
-                if (value instanceof Unit<?>) {
-                    final Unit<?> unit = (Unit<?>) value;
-                    if (isLinear(unit) || isAngular(unit) || isScale(unit)) {
-                        COMMONS.put(unit, unit);
-                    }
-                }
-            }
-        } while ((nonSI = !nonSI) == true);
-    }
-
-    /**
      * Returns {@code true} if the given unit is a linear unit.
      * Linear units are convertible to {@link NonSI#DEGREE_ANGLE}.
      *
@@ -328,23 +258,7 @@ public final class Units extends Static 
                 unit = unit.times(factor);
             }
         }
-        return canonicalize(unit);
-    }
-
-    /**
-     * Returns a unique instance of the given units if possible, or the units unchanged otherwise.
-     *
-     * @param  <A>    The quantity measured by the unit.
-     * @param  unit   The unit to canonicalize.
-     * @return A unit equivalents to the given unit, canonicalized if possible.
-     */
-    @SuppressWarnings({"unchecked","rawtypes"})
-    private static <A extends Quantity> Unit<A> canonicalize(final Unit<A> unit) {
-        final Unit<?> candidate = COMMONS.get(unit);
-        if (candidate != null) {
-            return (Unit) candidate;
-        }
-        return unit;
+        return UnitsMap.canonicalize(unit);
     }
 
     /**
@@ -495,7 +409,7 @@ public final class Units extends Static 
             // Provides a better error message than the default JSR-275 0.9.4 implementation.
             throw Exceptions.setMessage(e, Errors.format(Errors.Keys.IllegalArgumentValue_2, "uom", uom), true);
         }
-        return canonicalize(unit);
+        return UnitsMap.canonicalize(unit);
     }
 
     /**
@@ -607,15 +521,28 @@ public final class Units extends Static 
             case 9103: return NonSI.MINUTE_ANGLE;
             case 9104: return NonSI.SECOND_ANGLE;
             case 9105: return NonSI.GRADE;
-            case 9107: return Units.DEGREE_MINUTE_SECOND;
-            case 9108: return Units.DEGREE_MINUTE_SECOND;
+            case 9107: // Fall through
+            case 9108: return SexagesimalConverter.DMS_SCALED;
             case 9109: return SI.MetricPrefix.MICRO(SI.RADIAN);
-            case 9111: // Sexagesimal DM: use DMS.
-            case 9110: return Units.SEXAGESIMAL_DMS;
+            case 9111: return SexagesimalConverter.DM;
+            case 9110: return SexagesimalConverter.DMS;
             case 9203: // Fall through
             case 9201: return Unit .ONE;
             case 9202: return Units.PPM;
             default:   return null;
         }
     }
+
+    /**
+     * Returns the EPSG code of the given units, or {@code null} if unknown.
+     * This method is the converse of {@link #valueOfEPSG(int)}.
+     *
+     * @param  unit The unit for which to get the EPSG code.
+     * @return The EPSG code of the given units, or {@code null} if unknown.
+     *
+     * @since 0.4
+     */
+    public static Integer getEpsgCode(final Unit<?> unit) {
+        return UnitsMap.EPSG_CODES.get(unit);
+    }
 }

Copied: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java (from r1546824, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java?p2=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java&p1=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java&r1=1546824&r2=1547939&rev=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Units.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -23,100 +23,41 @@ import java.lang.reflect.Modifier;
 import javax.measure.unit.SI;
 import javax.measure.unit.NonSI;
 import javax.measure.unit.Unit;
-import javax.measure.quantity.Angle;
-import javax.measure.quantity.Length;
-import javax.measure.quantity.Duration;
-import javax.measure.quantity.Dimensionless;
 import javax.measure.quantity.Quantity;
-import javax.measure.converter.UnitConverter;
 import org.apache.sis.util.Static;
-import org.apache.sis.util.Workaround;
-import org.apache.sis.util.ArraysExt;
-import org.apache.sis.util.Exceptions;
-import org.apache.sis.util.CharSequences;
-import org.apache.sis.util.resources.Errors;
-import org.apache.sis.internal.util.URIParser;
 
-import static java.lang.Math.PI;
-import static java.lang.Math.abs;
-import static org.apache.sis.measure.SexagesimalConverter.EPS;
-import static org.apache.sis.util.CharSequences.trimWhitespaces;
+import static org.apache.sis.measure.Units.*;
 
 
 /**
- * Static methods working on {@link Unit} instances, and some constants in addition to the
- * {@link SI} and {@link NonSI} ones.
+ * Map of units, defined in a separated class in order to avoid too-early class loading.
+ * This class may be removed in a future SIS version if we provide our own units framework.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3 (derived from geotk-2.1)
  * @version 0.4
  * @module
  */
-public final class Units extends Static {
-    /**
-     * The suffixes that NetCDF files sometime put after the "degrees" unit.
-     * Suffix at even index are for axes having the standard geometric direction,
-     * while suffix at odd index are for axes having the reverse direction.
-     */
-    private static final String[] DEGREE_SUFFIXES = {"east", "west", "north", "south"};
-
+final class UnitsMap extends Static {
     /**
      * Do not allows instantiation of this class.
      */
-    private Units() {
+    private UnitsMap() {
     }
 
     /**
-     * Unit for milliseconds. Useful for conversion from and to {@link java.util.Date} objects.
-     */
-    public static final Unit<Duration> MILLISECOND = SI.MetricPrefix.MILLI(SI.SECOND);
-
-    /**
-     * Pseudo-unit for sexagesimal degree. Numbers in this pseudo-unit have the following format:
-     *
-     * <cite>sign - degrees - decimal point - minutes (two digits) - integer seconds (two digits) -
-     * fraction of seconds (any precision)</cite>.
-     *
-     * Using this unit is loosely equivalent to formatting decimal degrees with the
-     * {@code "D.MMSSs"} {@link AngleFormat} pattern.
-     *
-     * <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> SEXAGESIMAL_DMS = NonSI.DEGREE_ANGLE.transform(
-            SexagesimalConverter.FRACTIONAL.inverse()).asType(Angle.class);//.alternate("D.MS");
-
-    /**
-     * Pseudo-unit for degree - minute - second.
-     * Numbers in this pseudo-unit have the following format:
-     *
-     * <cite>signed degrees (integer) - arc-minutes (integer) - arc-seconds
-     * (real, any precision)</cite>.
-     *
-     * Using this unit is loosely equivalent to formatting decimal degrees with the
-     * {@code "DMMSS.s"} {@link AngleFormat} pattern.
-     *
-     * <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>
+     * EPSG codes of some units. This map is the reverse of {@link Units#valueOfEPSG(int)}.
+     * The map is defined in this class rather than in the {@code Units} class in order to
+     * avoid loading the {@code SexagesimalConverter} class before needed, since their
+     * constants appear in this map.
      */
-    static final Unit<Angle> DEGREE_MINUTE_SECOND = NonSI.DEGREE_ANGLE.transform(
-            SexagesimalConverter.INTEGER.inverse()).asType(Angle.class);//.alternate("DMS");
-
-    /**
-     * Parts per million.
-     *
-     * <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>
-     */
-    public static final Unit<Dimensionless> PPM = Unit.ONE.times(1E-6);//.alternate("ppm");
+    static final Map<Unit<?>,Integer> EPSG_CODES = new HashMap<>(20);
+    static {
+        final int[] codes = {9001, 9002, 9030, 9036, 9101, 9102, 9103, 9104, 9105, 9108, 9109, 9111, 9110, 9201, 9202};
+        for (final int code : codes) {
+            EPSG_CODES.put(Units.valueOfEPSG(code), code);
+        }
+    }
 
     /**
      * A few units commonly used in GIS.
@@ -146,192 +87,6 @@ public final class Units extends Static 
     }
 
     /**
-     * Returns {@code true} if the given unit is a linear unit.
-     * Linear units are convertible to {@link NonSI#DEGREE_ANGLE}.
-     *
-     * <p>Angular units are dimensionless, which may be a cause of confusion with other
-     * dimensionless units like {@link Unit#ONE} or {@link #PPM}. This method take care
-     * of differentiating angular units from other dimensionless units.</p>
-     *
-     * @param unit The unit to check (may be {@code null}).
-     * @return {@code true} if the given unit is non-null and angular.
-     *
-     * @see #ensureAngular(Unit)
-     */
-    public static boolean isAngular(final Unit<?> unit) {
-        return (unit != null) && unit.toSI().equals(SI.RADIAN);
-    }
-
-    /**
-     * Returns {@code true} if the given unit is a linear unit.
-     * Linear units are convertible to {@link SI#METRE}.
-     *
-     * @param unit The unit to check (may be {@code null}).
-     * @return {@code true} if the given unit is non-null and linear.
-     *
-     * @see #ensureLinear(Unit)
-     */
-    public static boolean isLinear(final Unit<?> unit) {
-        return (unit != null) && unit.toSI().equals(SI.METRE);
-    }
-
-    /**
-     * Returns {@code true} if the given unit is a pressure unit.
-     * Pressure units are convertible to {@link SI#PASCAL}.
-     * Those units are sometime used instead of linear units for altitude measurements.
-     *
-     * @param unit The unit to check (may be {@code null}).
-     * @return {@code true} if the given unit is non-null and a pressure unit.
-     */
-    public static boolean isPressure(final Unit<?> unit) {
-        return (unit != null) && unit.toSI().equals(SI.PASCAL);
-    }
-
-    /**
-     * Returns {@code true} if the given unit is a temporal unit.
-     * Temporal units are convertible to {@link SI#SECOND}.
-     *
-     * @param unit The unit to check (may be {@code null}).
-     * @return {@code true} if the given unit is non-null and temporal.
-     *
-     * @see #ensureTemporal(Unit)
-     */
-    public static boolean isTemporal(final Unit<?> unit) {
-        return (unit != null) && unit.toSI().equals(SI.SECOND);
-    }
-
-    /**
-     * Returns {@code true} if the given unit is a dimensionless scale unit.
-     * This include {@link Unit#ONE} and {@link #PPM}.
-     *
-     * @param unit The unit to check (may be {@code null}).
-     * @return {@code true} if the given unit is non-null and a dimensionless scale.
-     *
-     * @see #ensureScale(Unit)
-     */
-    public static boolean isScale(final Unit<?> unit) {
-        return (unit != null) && unit.toSI().equals(Unit.ONE);
-    }
-
-    /**
-     * Makes sure that the specified unit is either null or an angular unit.
-     * This method is used for argument checks in constructors and setter methods.
-     *
-     * @param  unit The unit to check, or {@code null} if none.
-     * @return The given {@code unit} argument, which may be null.
-     * @throws IllegalArgumentException if {@code unit} is non-null and not an angular unit.
-     *
-     * @see #isAngular(Unit)
-     */
-    @SuppressWarnings({"unchecked","rawtypes"})
-    public static Unit<Angle> ensureAngular(final Unit<?> unit) throws IllegalArgumentException {
-        if (unit != null && !isAngular(unit)) {
-            throw new IllegalArgumentException(Errors.format(Errors.Keys.NonAngularUnit_1, unit));
-        }
-        return (Unit) unit;
-    }
-
-    /**
-     * Makes sure that the specified unit is either null or a linear unit.
-     * This method is used for argument checks in constructors and setter methods.
-     *
-     * @param  unit The unit to check, or {@code null} if none.
-     * @return The given {@code unit} argument, which may be null.
-     * @throws IllegalArgumentException if {@code unit} is non-null and not a linear unit.
-     *
-     * @see #isLinear(Unit)
-     */
-    @SuppressWarnings({"unchecked","rawtypes"})
-    public static Unit<Length> ensureLinear(final Unit<?> unit) throws IllegalArgumentException {
-        if (unit != null && !isLinear(unit)) {
-            throw new IllegalArgumentException(Errors.format(Errors.Keys.NonLinearUnit_1, unit));
-        }
-        return (Unit) unit;
-    }
-
-    /**
-     * Makes sure that the specified unit is either null or a temporal unit.
-     * This method is used for argument checks in constructors and setter methods.
-     *
-     * @param  unit The unit to check, or {@code null} if none.
-     * @return The given {@code unit} argument, which may be null.
-     * @throws IllegalArgumentException if {@code unit} is non-null and not a temporal unit.
-     *
-     * @see #isTemporal(Unit)
-     */
-    @SuppressWarnings({"unchecked","rawtypes"})
-    public static Unit<Duration> ensureTemporal(final Unit<?> unit) throws IllegalArgumentException {
-        if (unit != null && !isTemporal(unit)) {
-            throw new IllegalArgumentException(Errors.format(Errors.Keys.NonTemporalUnit_1, unit));
-        }
-        return (Unit) unit;
-    }
-
-    /**
-     * Makes sure that the specified unit is either null or a scale unit.
-     * This method is used for argument checks in constructors and setter methods.
-     *
-     * @param  unit The unit to check, or {@code null} if none.
-     * @return The given {@code unit} argument, which may be null.
-     * @throws IllegalArgumentException if {@code unit} is non-null and not a scale unit.
-     *
-     * @see #isScale(Unit)
-     */
-    @SuppressWarnings({"unchecked","rawtypes"})
-    public static Unit<Dimensionless> ensureScale(final Unit<?> unit) throws IllegalArgumentException {
-        if (unit != null && !isScale(unit)) {
-            throw new IllegalArgumentException(Errors.format(Errors.Keys.NonScaleUnit_1, unit));
-        }
-        return (Unit) unit;
-    }
-
-    /**
-     * Multiplies the given unit by the given factor. For example multiplying {@link SI#METRE}
-     * by 1000 gives {@link SI#KILOMETRE}. Invoking this method is equivalent to invoking
-     * {@link Unit#times(double)} except for the following:
-     *
-     * <ul>
-     *   <li>A small tolerance factor is applied for a few factors commonly used in GIS.
-     *       For example {@code multiply(SI.RADIANS, 0.0174532925199...)} will return
-     *       {@link NonSI#DEGREE_ANGLE} even if the given numerical value is slightly
-     *       different than {@linkplain Math#PI pi}/180. The tolerance factor and the
-     *       set of units handled especially may change in future SIS versions.</li>
-     *   <li>This method tries to returns unique instances for some common units.</li>
-     * </ul>
-     *
-     * @param  <A>    The quantity measured by the unit.
-     * @param  unit   The unit to multiply.
-     * @param  factor The multiplication factor.
-     * @return The unit multiplied by the given factor.
-     */
-    @Workaround(library="JSR-275", version="0.9.3")
-    @SuppressWarnings({"unchecked","rawtypes"})
-    public static <A extends Quantity> Unit<A> multiply(Unit<A> unit, final double factor) {
-        if (SI.RADIAN.equals(unit)) {
-            if (abs(factor - (PI / 180)) <= (EPS * PI/180)) {
-                return (Unit) NonSI.DEGREE_ANGLE;
-            }
-            if (abs(factor - (PI / 200)) <= (EPS * PI/200)) {
-                return (Unit) NonSI.GRADE;
-            }
-        }
-        if (abs(factor - 1) > EPS) {
-            final long fl = (long) factor;
-            if (fl == factor) {
-                /*
-                 * Invoke the Unit.times(long) overloaded method, not Unit.scale(double),
-                 * because as of JSR-275 0.9.3 the method with the long argument seems to
-                 * do a better work of detecting when the result is an existing unit.
-                 */
-                unit = unit.times(fl);
-            } else {
-                unit = unit.times(factor);
-            }
-        }
-        return canonicalize(unit);
-    }
-
-    /**
      * Returns a unique instance of the given units if possible, or the units unchanged otherwise.
      *
      * @param  <A>    The quantity measured by the unit.
@@ -339,283 +94,11 @@ public final class Units extends Static 
      * @return A unit equivalents to the given unit, canonicalized if possible.
      */
     @SuppressWarnings({"unchecked","rawtypes"})
-    private static <A extends Quantity> Unit<A> canonicalize(final Unit<A> unit) {
+    static <A extends Quantity> Unit<A> canonicalize(final Unit<A> unit) {
         final Unit<?> candidate = COMMONS.get(unit);
         if (candidate != null) {
             return (Unit) candidate;
         }
         return unit;
     }
-
-    /**
-     * 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.
-     *
-     * <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  <A>  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.
-     */
-    @Workaround(library="JSR-275", version="0.9.3")
-    public static <A extends Quantity> double toStandardUnit(final Unit<A> unit) {
-        return derivative(unit.getConverterTo(unit.toSI()), 0);
-    }
-
-    /**
-     * 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. This method will be deprecated if the
-     * removed API is reinserted in future JSR-275 release.
-     *
-     * <p>Current implementation computes the derivative as below:</p>
-     *
-     * {@preformat java
-     *     return converter.convert(value + 1) - converter.convert(value);
-     * }
-     *
-     * The above is exact for {@linkplain javax.measure.converter.LinearConverter 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 {@link #SEXAGESIMAL_DMS} to decimal degrees for
-     * example.
-     *
-     * @param  converter The converter for which we want the derivative at a given point.
-     * @param  value The point at which to compute the derivative.
-     * @return The derivative at the given point.
-     */
-    @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);
-    }
-
-    /**
-     * Parses the given symbol. This method is similar to {@link Unit#valueOf(CharSequence)}, but
-     * hands especially a few symbols found in WKT parsing or in XML files. The list of symbols
-     * handled especially is implementation-dependent and may change in future SIS versions.
-     *
-     * {@section Parsing authority codes}
-     * As a special case, if the given {@code uom} arguments is of the form {@code "EPSG:####"}
-     * or {@code "urn:ogc:def:uom:EPSG:####"} (ignoring case and whitespaces), then {@code "####"}
-     * is parsed as an integer and forwarded to the {@link #valueOfEPSG(int)} method.
-     *
-     * {@section NetCDF unit symbols}
-     * The attributes in NetCDF files often merge the axis direction with the angular unit,
-     * as in {@code "degrees_east"} or {@code "degrees_north"}. This {@code valueOf} method
-     * ignores those suffixes and unconditionally returns {@link NonSI#DEGREE_ANGLE} 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.
-     *
-     * @param  uom The symbol to parse, or {@code null}.
-     * @return The parsed symbol, or {@code null} if {@code uom} was null.
-     * @throws IllegalArgumentException if the given symbol can not be parsed.
-     */
-    public static Unit<?> valueOf(String uom) throws IllegalArgumentException {
-        if (uom == null) {
-            return null;
-        }
-        uom = trimWhitespaces(CharSequences.toASCII(uom)).toString();
-        final int length = uom.length();
-        /*
-         * Check for authority codes (currently only EPSG, but more could be added later).
-         * If the unit is not an authority code (which is the most common case), then we
-         * will check for hard-coded unit symbols.
-         *
-         * URIParser.codeOf(…) returns 'uom' directly (provided that whitespaces were already trimmed)
-         * if no ':' character were found, in which case the string is assumed to be the code directly.
-         * This is the intended behavior for AuthorityFactory, but in the particular case of this method
-         * we want to try to parse as a xpointer before to give up.
-         */
-        if (isURI(uom)) {
-            String code = URIParser.codeOf("uom", "EPSG", uom);
-            if (code != null && code != uom) try { // Really identity check, see above comment.
-                return valueOfEPSG(Integer.parseInt(code));
-            } catch (NumberFormatException e) {
-                throw new IllegalArgumentException(Errors.format(
-                        Errors.Keys.IllegalArgumentValue_2, "uom", uom), e);
-            }
-            code = URIParser.xpointer("uom", uom);
-            if (code != null) {
-                uom = code;
-            }
-        }
-        /*
-         * Check for degrees units. Note that "deg" could be both angular and Celsius degrees.
-         * We try to resolve this ambiguity in the code below by looking for the "Celsius" suffix.
-         * Other suffixes commonly found in NetCDF files are "west", "east", "north" or "south".
-         * Those suffixes are ignored.
-         */
-        if (uom.regionMatches(true, 0, "deg", 0, 3)) {
-            if (length == 3) {
-                return NonSI.DEGREE_ANGLE; // Exactly "deg"
-            }
-            String prefix = uom;
-            boolean isTemperature = false;
-            final int s = Math.max(uom.lastIndexOf(' '), uom.lastIndexOf('_'));
-            if (s >= 1) {
-                final String suffix = (String) trimWhitespaces(uom, s+1, length);
-                if (ArraysExt.containsIgnoreCase(DEGREE_SUFFIXES, suffix) || (isTemperature = isCelsius(suffix))) {
-                    prefix = (String) trimWhitespaces(uom, 0, s); // Remove the suffix only if we recognized it.
-                }
-            }
-            if (equalsIgnorePlural(prefix, "degree")) {
-                return isTemperature ? SI.CELSIUS : NonSI.DEGREE_ANGLE;
-            }
-        } else {
-            /*
-             * Check for unit symbols that do not begin with "deg". If a symbol begins
-             * with "deg", then the check should be put in the above block instead.
-             */
-            if (uom.equals("°")                      || equalsIgnorePlural(uom, "decimal_degree")) return NonSI.DEGREE_ANGLE;
-            if (uom.equalsIgnoreCase("arcsec"))                                                    return NonSI.SECOND_ANGLE;
-            if (uom.equalsIgnoreCase("rad")          || equalsIgnorePlural(uom, "radian"))         return SI.RADIAN;
-            if (equalsIgnorePlural(uom, "kilometer") || equalsIgnorePlural(uom, "kilometre"))      return SI.KILOMETRE;
-            if (equalsIgnorePlural(uom, "meter")     || equalsIgnorePlural(uom, "metre"))          return SI.METRE;
-            if (equalsIgnorePlural(uom, "week"))   return NonSI.WEEK;
-            if (equalsIgnorePlural(uom, "day"))    return NonSI.DAY;
-            if (equalsIgnorePlural(uom, "hour"))   return NonSI.HOUR;
-            if (equalsIgnorePlural(uom, "minute")) return NonSI.MINUTE;
-            if (equalsIgnorePlural(uom, "second")) return SI   .SECOND;
-            if (equalsIgnorePlural(uom, "pixel"))  return NonSI.PIXEL;
-            if (isCelsius(uom))                    return SI.CELSIUS;
-            if (uom.isEmpty() ||
-                uom.equalsIgnoreCase("psu") ||   // Pratical Salinity Scale (oceanography)
-                uom.equalsIgnoreCase("level"))   // Sigma level (oceanography)
-            {
-                return Unit.ONE;
-            }
-        }
-        final Unit<?> unit;
-        try {
-            unit = Unit.valueOf(uom);
-        } catch (IllegalArgumentException e) {
-            // Provides a better error message than the default JSR-275 0.9.4 implementation.
-            throw Exceptions.setMessage(e, Errors.format(Errors.Keys.IllegalArgumentValue_2, "uom", uom), true);
-        }
-        return canonicalize(unit);
-    }
-
-    /**
-     * Returns {@code true} if the given {@code uom} is equals to the given expected string,
-     * ignoring trailing {@code 's'} character (if any).
-     */
-    @SuppressWarnings("fallthrough")
-    private static boolean equalsIgnorePlural(final String uom, final String expected) {
-        final int length = expected.length();
-        switch (uom.length() - length) {
-            case 0:  break; // uom has exactly the expected length.
-            case 1:  if (Character.toLowerCase(uom.charAt(length)) == 's') break; // else fallthrough.
-            default: return false;
-        }
-        return uom.regionMatches(true, 0, expected, 0, length);
-    }
-
-    /**
-     * Returns {@code true} if the given {@code uom} is equals to {@code "Celsius"} or
-     * {@code "Celcius"}. The later is a common misspelling.
-     */
-    private static boolean isCelsius(final String uom) {
-        return uom.equalsIgnoreCase("Celsius") || uom.equalsIgnoreCase("Celcius");
-    }
-
-    /**
-     * Returns {@code true} if the given unit seems to be an URI. Example:
-     * <ul>
-     *   <li>{@code "urn:ogc:def:uom:EPSG::9102"}</li>
-     *   <li>{@code "http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])"}</li>
-     * </ul>
-     */
-    private static boolean isURI(final String uom) {
-        for (int i=uom.length(); --i>=0;) {
-            final char c = uom.charAt(i);
-            if (c == ':' || c == '#') {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Returns a hard-coded unit from an EPSG code. The {@code code} argument given to this
-     * method shall be a code identifying a record in the {@code "Unit of Measure"} table of
-     * the EPSG database. If this method does not recognize the given code, then it returns
-     * {@code null}.
-     *
-     * <p>The list of units recognized by this method is not exhaustive. This method recognizes
-     * the base units declared in the {@code [TARGET_UOM_CODE]} column of the above-cited table,
-     * and some frequently-used units. The list of recognized units may be updated in any future
-     * version of SIS.</p>
-     *
-     * <p>The {@link org.apache.sis.referencing.factory.epsg.DirectEpsgFactory} uses this method
-     * for fetching the base units, and derives automatically other units from the information
-     * found in the EPSG database. This method is also used by other code not directly related
-     * to the EPSG database, like {@link org.apache.sis.referencing.factory.web.AutoCRSFactory}
-     * which uses EPSG code for identifying units.</p>
-     *
-     * <p>The values currently recognized are:</p>
-     * <table class="sis">
-     *   <tr>
-     *     <th>Linear units</th>
-     *     <th class="sep">Angular units</th>
-     *     <th class="sep">Scale units</th>
-     *   </tr><tr>
-     *     <td><table class="compact">
-     *       <tr><td width="40"><b>Code</b></td><td><b>Unit</b></td></tr>
-     *       <tr><td>9001</td><td>metre</td></tr>
-     *       <tr><td>9002</td><td>foot</td></tr>
-     *       <tr><td>9030</td><td>nautical mile</td></tr>
-     *       <tr><td>9036</td><td>kilometre</td></tr>
-     *     </table></td>
-     *     <td class="sep"><table class="compact">
-     *       <tr><td width="40"><b>Code</b></td><td><b>Unit</b></td></tr>
-     *       <tr><td>9101</td><td>radian</td></tr>
-     *       <tr><td>9102</td><td>decimal degree</td></tr>
-     *       <tr><td>9103</td><td>minute</td></tr>
-     *       <tr><td>9104</td><td>second</td></tr>
-     *       <tr><td>9105</td><td>grade</td></tr>
-     *       <tr><td>9107</td><td>degree-minute-second</td></tr>
-     *       <tr><td>9108</td><td>degree-minute-second</td></tr>
-     *       <tr><td>9109</td><td>microradian</td></tr>
-     *       <tr><td>9110</td><td>sexagesimal degree-minute-second</td></tr>
-     *       <tr><td>9111</td><td>sexagesimal degree-minute</td></tr>
-     *       <tr><td>9122</td><td>decimal degree</td></tr>
-     *     </table></td>
-     *     <td class="sep"><table class="compact">
-     *       <tr><td width="40"><b>Code</b></td><td><b>Unit</b></td></tr>
-     *       <tr><td>9201</td><td>one</td></tr>
-     *       <tr><td>9202</td><td>part per million</td></tr>
-     *       <tr><td>9203</td><td>one</td></tr>
-     *     </table></td>
-     *   </tr>
-     * </table>
-     *
-     * @param  code The EPSG code for a unit of measurement.
-     * @return The unit, or {@code null} if the code is unrecognized.
-     */
-    public static Unit<?> valueOfEPSG(final int code) {
-        switch (code) {
-            case 9001: return SI   .METRE;
-            case 9002: return NonSI.FOOT;
-            case 9030: return NonSI.NAUTICAL_MILE;
-            case 9036: return SI   .KILOMETRE;
-            case 9101: return SI   .RADIAN;
-            case 9122: // Fall through
-            case 9102: return NonSI.DEGREE_ANGLE;
-            case 9103: return NonSI.MINUTE_ANGLE;
-            case 9104: return NonSI.SECOND_ANGLE;
-            case 9105: return NonSI.GRADE;
-            case 9107: return Units.DEGREE_MINUTE_SECOND;
-            case 9108: return Units.DEGREE_MINUTE_SECOND;
-            case 9109: return SI.MetricPrefix.MICRO(SI.RADIAN);
-            case 9111: // Sexagesimal DM: use DMS.
-            case 9110: return Units.SEXAGESIMAL_DMS;
-            case 9203: // Fall through
-            case 9201: return Unit .ONE;
-            case 9202: return Units.PPM;
-            default:   return null;
-        }
-    }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -20,7 +20,6 @@ import java.util.Arrays;
 import java.nio.CharBuffer;
 
 import static java.lang.Character.*;
-import static org.apache.sis.util.StringBuilders.replace;
 
 
 /**
@@ -950,7 +949,7 @@ search:     for (; fromIndex <= toIndex;
      *
      * @param  text The text to scan for Unicode characters to replace by ASCII characters,
      *         or {@code null}.
-     * @return The given text with substitution applied, or {@code text} if no replacement
+     * @return The given text with substitutions applied, or {@code text} if no replacement
      *         has been applied, or {@code null} if the given text was null.
      *
      * @see StringBuilders#toASCII(StringBuilder)
@@ -1250,16 +1249,16 @@ searchWordBreak:    while (true) {
                 return ((String) identifier).replace('_', '-');
             }
             buffer = new StringBuilder(identifier);
-            replace(buffer, '_', '-');
+            StringBuilders.replace(buffer, '_', '-');
         } else {
             buffer = (StringBuilder) camelCaseToWords(identifier, true);
             final int length = buffer.length();
             if (length != 0) {
-                replace(buffer, '_', ' ');
+                StringBuilders.replace(buffer, '_', ' ');
                 final int c = buffer.codePointAt(0);
                 final int up = toUpperCase(c);
                 if (c != up) {
-                    replace(buffer, 0, charCount(c), toChars(up));
+                    StringBuilders.replace(buffer, 0, charCount(c), toChars(up));
                 }
             }
         }
@@ -1317,7 +1316,7 @@ searchWordBreak:    while (true) {
                     final int c = buffer.codePointAt(pos);
                     final int low = toLowerCase(c);
                     if (c != low) {
-                        replace(buffer, pos, pos + charCount(c), toChars(low));
+                        StringBuilders.replace(buffer, pos, pos + charCount(c), toChars(low));
                     }
                 }
                 last = i;
@@ -1386,7 +1385,7 @@ searchWordBreak:    while (true) {
                     final int c = buffer.codePointAt(0);
                     final int up = toUpperCase(c);
                     if (c != up) {
-                        replace(buffer, 0, charCount(c), toChars(up));
+                        StringBuilders.replace(buffer, 0, charCount(c), toChars(up));
                     }
                 }
                 if (!equals(text, buffer)) {
@@ -1964,9 +1963,53 @@ cmp:    while (ia < lga) {
     }
 
     /**
+     * Replaces all occurrences of a given string in the given character sequence. If no occurrence of
+     * {@code toSearch} is found in the given text, then this method returns the {@code text} unchanged.
+     * Otherwise this method returns a new character sequence with all occurrences replaced by {@code replaceBy}.
+     *
+     * <p>This method is similar to {@link String#replace(CharSequence, CharSequence)} except for the following:</p>
+     * <ul>
+     *   <li>This method accepts arbitrary {@code CharSequence} objects.</li>
+     *   <li>This method <strong>does not use regular expression</strong>.
+     *       The {@code toSearch} value is searched verbatim.</li>
+     * </ul>
+     *
+     * @param  text      The character sequence in which to perform the replacements, or {@code null}.
+     * @param  toSearch  The string to replace.
+     * @param  replaceBy The replacement for the searched string.
+     * @return The given text with replacements applied, or {@code text} if no replacement has been applied,
+     *         or {@code null} if the given text was null
+     *
+     * @see String#replace(char, char)
+     * @see StringBuilders#replace(StringBuilder, String, String)
+     * @see String#replace(CharSequence, CharSequence)
+     *
+     * @since 0.4
+     */
+    public static CharSequence replace(final CharSequence text, final CharSequence toSearch, final CharSequence replaceBy) {
+        ArgumentChecks.ensureNonEmpty("toSearch",  toSearch);
+        ArgumentChecks.ensureNonNull ("replaceBy", replaceBy);
+        if (text != null && !toSearch.equals(replaceBy)) {
+            final int length = text.length();
+            int i = indexOf(text, toSearch, 0, length);
+            if (i >= 0) {
+                int p = 0;
+                final int sl = toSearch.length();
+                final StringBuilder buffer = new StringBuilder(length + (replaceBy.length() - sl));
+                do {
+                    buffer.append(text, p, i).append(replaceBy);
+                    i = indexOf(text, toSearch, p = i + sl, length);
+                } while (i >= 0);
+                return buffer.append(text, p, length);
+            }
+        }
+        return text;
+    }
+
+    /**
      * Copies a sequence of characters in the given {@code char[]} array.
      *
-     * @param src       The character sequences from which to copy characters.
+     * @param src       The characters sequence from which to copy characters.
      * @param srcOffset Index of the first character from {@code src} to copy.
      * @param dst       The array where to copy the characters.
      * @param dstOffset Index where to write the first character in {@code dst}.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -86,7 +86,7 @@ public final class StringBuilders extend
      * @throws IllegalArgumentException If the {@code toSearch} argument is empty.
      *
      * @see String#replace(char, char)
-     * @see String#replace(CharSequence, CharSequence)
+     * @see CharSequences#replace(CharSequence, String, String)
      * @see StringBuilder#replace(int, int, String)
      */
     public static void replace(final StringBuilder buffer, final String toSearch, final String replaceBy) {

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -109,7 +109,7 @@ public final class Namespaces extends St
     /**
      * The <code>{@value}</code> URL.
      * The usual prefix for this namespace is {@code "gml"}.
-     * The current version is 3.2, but this may change in any future SIS release.
+     * The current version is 3.2 (ISO 19136), but this may change in any future SIS release.
      *
      * @category OGC
      */

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java?rev=1547939&r1=1547938&r2=1547939&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java [UTF-8] Wed Dec  4 22:34:18 2013
@@ -44,14 +44,20 @@ public final strictfp class MeasureTest 
         final Measure measure = new Measure();
         measure.setUOM("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#m");
         assertEquals(SI.METRE, measure.unit);
+        assertEquals("urn:ogc:def:uom:EPSG::9001", measure.getUOM());
+        measure.asXPointer = true;
         assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])", measure.getUOM());
 
         measure.unit = null;
+        measure.asXPointer = false;
         measure.setUOM("../uom/ML_gmxUom.xml#xpointer(//*[@gml:id='deg'])");
         assertEquals(NonSI.DEGREE_ANGLE, measure.unit);
+        assertEquals("urn:ogc:def:uom:EPSG::9102", measure.getUOM());
+        measure.asXPointer = true;
         assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='deg'])", measure.getUOM());
 
         measure.unit = null;
+        measure.asXPointer = true;
         measure.setUOM("gmxUom.xml#kg"); // Not really an existing unit in 'gmxUom'.
         assertEquals(SI.KILOGRAM, measure.unit);
         assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='kg'])", measure.getUOM());



Mime
View raw message