You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/08/12 18:13:09 UTC

svn commit: r1513186 - in /sis/branches/JDK7: core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-metadata/src/test/java/org/apache/sis/metadata/ core/sis-metadata/src/test/java/org/apache/sis/test/suite/ core/sis-utility/src/main/java/or...

Author: desruisseaux
Date: Mon Aug 12 16:13:09 2013
New Revision: 1513186

URL: http://svn.apache.org/r1513186
Log:
In string representation, format the GeographicBoundingBox values as longitudes/latitudes instead than plain doubles.

Added:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java   (with props)
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java   (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.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/PropertyInformation.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleTest.java
    sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -293,7 +293,12 @@ public class MetadataStandard implements
                     return null;
                 }
             }
-            final PropertyAccessor accessor = new PropertyAccessor(citation, type, implementation);
+            final PropertyAccessor accessor;
+            if (SpecialCases.isSpecialCase(type)) {
+                accessor = new SpecialCases(citation, type, implementation);
+            } else {
+                accessor = new PropertyAccessor(citation, type, implementation);
+            }
             accessors.put(implementation, accessor);
             return accessor;
         }

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=1513186&r1=1513185&r2=1513186&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] Mon Aug 12 16:13:09 2013
@@ -82,7 +82,7 @@ import static org.apache.sis.util.collec
  * @module
  */
 @ThreadSafe
-final class PropertyAccessor {
+class PropertyAccessor {
     /**
      * Getters shared between many instances of this class. Two different implementations
      * may share the same getters but different setters.
@@ -349,6 +349,24 @@ final class PropertyAccessor {
     }
 
     /**
+     * Sets the type of the given property. This method is invoked by the {@link SpecialCases} constructor only,
+     * and should never be invoked in any other context. This restriction exists because {@code PropertyAcessor}
+     * shall be immutable after construction.
+     *
+     * <p>Subclasses that invoke this method shall also override the {@link #get(int, Object)} and
+     * {@link #set(int, Object, Object, int)} methods.</p>
+     *
+     * @param  name The name of the property for which to modify the element type.
+     * @param  type The new element type for the named property.
+     * @return The index of the modified property.
+     */
+    final int setType(final String name, final Class<?> type) {
+        final int index = indexOf(name, true);
+        elementTypes[index] = type;
+        return index;
+    }
+
+    /**
      * Adds the given (name, index) pair to {@link #mapping}, making sure we don't
      * overwrite an existing entry with different value.
      */
@@ -599,8 +617,7 @@ final class PropertyAccessor {
             final Method   getter      = getters[index];
             ValueRange range = null;
             if (implementation != type) {
-                final int e = Numbers.getEnumConstant(elementType);
-                if (e >= Numbers.BYTE && e <= Numbers.DOUBLE) try {
+                if (Number.class.isAssignableFrom(elementType)) try {
                     range = implementation.getMethod(getter.getName(), (Class<?>[]) null)
                             .getAnnotation(ValueRange.class);
                 } catch (NoSuchMethodException error) {
@@ -633,7 +650,7 @@ final class PropertyAccessor {
      * @return The value, or {@code null} if none or if the given is out of bounds.
      * @throws BackingStoreException If the implementation threw a checked exception.
      */
-    final Object get(final int index, final Object metadata) throws BackingStoreException {
+    Object get(final int index, final Object metadata) throws BackingStoreException {
         return (index >= 0 && index < standardCount) ? get(getters[index], metadata) : null;
     }
 
@@ -680,7 +697,7 @@ final class PropertyAccessor {
      *                        new collection in their existing instance.</li>
      *   <li>APPEND:          Set the value only if it doesn't overwrite an existing value, then returns
      *                        {@link Boolean#TRUE} if the metadata changed as a result of this method call,
-     *                        {@code Boolean#FALSE} if the metadata didn't changed or {@code null} if the
+     *                        {@link Boolean#FALSE} if the metadata didn't changed or {@code null} if the
      *                        value can not be set because an other value already exists.</li>
      * </ul>
      *
@@ -704,7 +721,7 @@ final class PropertyAccessor {
      * @throws ClassCastException if the given value is not of the expected type.
      * @throws BackingStoreException if the implementation threw a checked exception.
      */
-    final Object set(final int index, final Object metadata, final Object value, final int mode)
+    Object set(final int index, final Object metadata, final Object value, final int mode)
             throws UnmodifiableMetadataException, ClassCastException, BackingStoreException
     {
         if (index < 0 || index >= standardCount) {
@@ -884,9 +901,7 @@ final class PropertyAccessor {
                 // Other cases: let the collection unchanged. It is likely to
                 // cause an exception later. The message should be appropriate.
             }
-            // Getter type (targetType) shall be the same than the setter type (elementType).
-            assert elementType == Numbers.primitiveToWrapper(targetType) : elementType;
-            targetType = elementType; // Ensure that we use primitive wrapper.
+            targetType = Numbers.primitiveToWrapper(targetType);
         } else {
             /*
              * We expect a collection. Collections are handled in one of the two ways below:

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -121,7 +121,7 @@ final class PropertyInformation<E> exten
      * @param  getter      The getter method defined in the interface.
      * @param  elementType The value type, either the method return type if not a collection,
      *                     or the type of elements in the collection otherwise.
-     * @param  valueRange  The range of valid values, or {@code null} if none. This information is associated to the
+     * @param  range       The range of valid values, or {@code null} if none. This information is associated to the
      *                     implementation method rather than the interface one, because it is specific to SIS.
      */
     @SuppressWarnings({"unchecked","rawtypes"})
@@ -250,6 +250,8 @@ final class PropertyInformation<E> exten
      * Returns the case type of values to be stored in the property.
      * If the property type is an array or a collection, then this method
      * returns the type of elements in the array or collection.
+     *
+     * @see TypeValuePolicy#ELEMENT_TYPE
      */
     @Override
     public Class<E> getElementType() {

Added: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java?rev=1513186&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java (added)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -0,0 +1,117 @@
+/*
+ * 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.metadata;
+
+import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.apache.sis.measure.Latitude;
+import org.apache.sis.measure.Longitude;
+import org.apache.sis.util.collection.BackingStoreException;
+
+
+/**
+ * Substitute on-the-fly the values of some properties handled in a special way.
+ * The current implementation handles only the longitude and latitude bounds of
+ * {@link GeographicBoundingBox}, which are returned as {@link Longitude} or
+ * {@link Latitude} instances instead of {@link Double}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+final class SpecialCases extends PropertyAccessor {
+    /**
+     * Index of properties to handle in a special way.
+     */
+    private final int westBoundLongitude, eastBoundLongitude, southBoundLatitude, northBoundLatitude;
+
+    /**
+     * Creates a new property accessor for the specified metadata implementation.
+     *
+     * @param  standard The standard which define the {@code type} interface.
+     * @param  type The interface implemented by the metadata, which must be
+     *         the value returned by {@link #getStandardType(Class, String)}.
+     * @param  implementation The class of metadata implementations, or {@code type} if none.
+     */
+    SpecialCases(final Citation standard, final Class<?> type, final Class<?> implementation) {
+        super(standard, type, implementation);
+        assert isSpecialCase(type) : type;
+        westBoundLongitude = setType("westBoundLongitude", Longitude.class);
+        eastBoundLongitude = setType("eastBoundLongitude", Longitude.class);
+        southBoundLatitude = setType("southBoundLatitude",  Latitude.class);
+        northBoundLatitude = setType("northBoundLatitude",  Latitude.class);
+    }
+
+    /**
+     * Returns {@code true} if the given class is a special case handled by the {@link SpecialCases} class.
+     *
+     * @param  type The interface implemented by the metadata.
+     * @return {@code true} if the given type is a special case.
+     */
+    static boolean isSpecialCase(final Class<?> type) {
+        return type == GeographicBoundingBox.class;
+    }
+
+    /**
+     * Delegates to {@link PropertyAccessor#get(int, Object)}, then substitutes the value for the properties
+     * handled in a special way.
+     */
+    @Override
+    Object get(final int index, final Object metadata) throws BackingStoreException {
+        Object value = super.get(index, metadata);
+        if (value != null) {
+            if (index == westBoundLongitude || index == eastBoundLongitude) {
+                value = new Longitude((Double) value);
+            } else if (index == southBoundLatitude || index == northBoundLatitude) {
+                value = new Latitude((Double) value);
+            }
+        }
+        return value;
+    }
+
+    /**
+     * Substitutes the value for the properties handled in a special way, then delegates to
+     * {@link #set(int, Object, Object, int)}.
+     */
+    @Override
+    Object set(final int index, final Object metadata, Object value, final int mode)
+            throws UnmodifiableMetadataException, ClassCastException, BackingStoreException
+    {
+        if ((index == westBoundLongitude || index == eastBoundLongitude)) {
+            if (value instanceof Longitude) {
+                value = ((Longitude) value).degrees();
+            }
+            value = super.set(index, metadata, value, mode);
+            if (value != null) {
+                value = new Longitude((Double) value);
+            }
+            return value;
+        } else if ((index == southBoundLatitude || index == northBoundLatitude)) {
+            if (value instanceof Latitude) {
+                value = ((Latitude) value).degrees();
+            }
+            value = super.set(index, metadata, value, mode);
+            if (value != null) {
+                value = new Latitude((Double) value);
+            }
+            return value;
+        } else {
+            return super.set(index, metadata, value, mode);
+        }
+    }
+}

Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/SpecialCases.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java?rev=1513186&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java (added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -0,0 +1,159 @@
+/*
+ * 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.metadata;
+
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.apache.sis.measure.Latitude;
+import org.apache.sis.measure.Longitude;
+import org.apache.sis.metadata.iso.citation.HardCodedCitations;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link SpecialCases}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+@DependsOn(PropertyAccessorTest.class)
+public final strictfp class SpecialCasesTest extends TestCase {
+    /**
+     * The tolerance factor for strict comparisons of floating point values.
+     */
+    private static final double STRICT = 0.0;
+
+    /**
+     * The accessor instance to be tested.
+     */
+    private final PropertyAccessor accessor;
+
+    /**
+     * An arbitrary bounding box to be used for testing purpose.
+     */
+    private final DefaultGeographicBoundingBox box;
+
+    /**
+     * Creates a new test case.
+     */
+    public SpecialCasesTest() {
+        accessor = new SpecialCases(HardCodedCitations.ISO_19115,
+                GeographicBoundingBox.class, DefaultGeographicBoundingBox.class);
+        box = new DefaultGeographicBoundingBox(-20, 30, -10, 40);
+    }
+
+    /**
+     * Invokes {@link SpecialCases#get(int, Object)} and ensure that the result is equals to the expected value.
+     */
+    private void assertPropertyEquals(final String name, final Object expected) {
+        assertEquals(name, expected, accessor.get(accessor.indexOf(name, true), box));
+    }
+
+    /**
+     * Invokes {@link SpecialCases#set(int, Object, Object, int)} in {@code RETURN_PREVIOUS} mode with the given
+     * {@code newValue}, and ensures that the return value is equals to the given {@code oldValue}.
+     */
+    private void assertPreviousEquals(final String name, final Object oldValue, final Object newValue) {
+        final Object value = accessor.set(accessor.indexOf(name, true), box, newValue, PropertyAccessor.RETURN_PREVIOUS);
+        assertEquals(name, oldValue, value);
+    }
+
+    /**
+     * Invokes {@link SpecialCases#set(int, Object, Object, int)} in {@code APPEND} mode with the given
+     * {@code newValue}, and ensures that the return value is equals to the given {@code changed}.
+     */
+    private void assertAppendResultEquals(final String name, final Boolean changed, final Object newValue) {
+        final Object value = accessor.set(accessor.indexOf(name, true), box, newValue, PropertyAccessor.APPEND);
+        assertEquals(name, changed, value);
+    }
+
+    /**
+     * Tests {@link SpecialCases#get(int, Object)}.
+     */
+    @Test
+    public void testGet() {
+        assertPropertyEquals("westBoundLongitude", new Longitude(-20));
+        assertPropertyEquals("eastBoundLongitude", new Longitude( 30));
+        assertPropertyEquals("southBoundLatitude", new Latitude (-10));
+        assertPropertyEquals("northBoundLatitude", new Latitude ( 40));
+        assertPropertyEquals("extentTypeCode",     Boolean.TRUE      );
+    }
+
+    /**
+     * Tests {@link SpecialCases#set(int, Object, Object, int)} in {@code RETURN_PREVIOUS} mode.
+     */
+    @Test
+    @DependsOnMethod("testGet")
+    public void testSet() {
+        assertPreviousEquals("westBoundLongitude", new Longitude(-20), new Longitude(-15));
+        assertPreviousEquals("eastBoundLongitude", new Longitude( 30), new Longitude( 25));
+        assertPreviousEquals("southBoundLatitude", new Latitude (-10), new Latitude ( -5));
+        assertPreviousEquals("northBoundLatitude", new Latitude ( 40), new Latitude ( 35));
+        assertPreviousEquals("extentTypeCode",     Boolean.TRUE,       Boolean.FALSE);
+
+        assertEquals("westBoundLongitude", -15, box.getWestBoundLongitude(), STRICT);
+        assertEquals("eastBoundLongitude",  25, box.getEastBoundLongitude(), STRICT);
+        assertEquals("southBoundLatitude",  -5, box.getSouthBoundLatitude(), STRICT);
+        assertEquals("northBoundLatitude",  35, box.getNorthBoundLatitude(), STRICT);
+        assertEquals("extentTypeCode", Boolean.FALSE, box.getInclusion());
+    }
+
+    /**
+     * Tests {@link SpecialCases#set(int, Object, Object, int)} in {@code RETURN_PREVIOUS} mode
+     * with {@link Double} values instead than {@link Longitude} or {@link Latitude}.
+     */
+    @Test
+    @DependsOnMethod("testSet")
+    public void testSetAsPrimitive() {
+        assertPreviousEquals("westBoundLongitude", new Longitude(-20), -14.0);
+        assertPreviousEquals("eastBoundLongitude", new Longitude( 30),  26  );
+        assertPreviousEquals("southBoundLatitude", new Latitude (-10),  -7f );
+        assertPreviousEquals("northBoundLatitude", new Latitude ( 40), (short) 33);
+
+        assertEquals("westBoundLongitude", -14, box.getWestBoundLongitude(), STRICT);
+        assertEquals("eastBoundLongitude",  26, box.getEastBoundLongitude(), STRICT);
+        assertEquals("southBoundLatitude",  -7, box.getSouthBoundLatitude(), STRICT);
+        assertEquals("northBoundLatitude",  33, box.getNorthBoundLatitude(), STRICT);
+        assertEquals("extentTypeCode", Boolean.TRUE, box.getInclusion());
+    }
+
+    /**
+     * Tests {@link SpecialCases#set(int, Object, Object, int)} in {@code APPEND} mode.
+     */
+    @Test
+    @DependsOnMethod("testSet")
+    public void testAppend() {
+        assertAppendResultEquals("westBoundLongitude", null, new Longitude(-20));
+        assertAppendResultEquals("eastBoundLongitude", null, new Longitude( 24));
+        assertAppendResultEquals("southBoundLatitude", null, new Latitude ( -6));
+        assertAppendResultEquals("northBoundLatitude", null, 40.0);
+        assertAppendResultEquals("extentTypeCode", false, Boolean.TRUE);
+
+        assertEquals("westBoundLongitude", -20, box.getWestBoundLongitude(), STRICT);
+        assertEquals("eastBoundLongitude",  30, box.getEastBoundLongitude(), STRICT);
+        assertEquals("southBoundLatitude", -10, box.getSouthBoundLatitude(), STRICT);
+        assertEquals("northBoundLatitude",  40, box.getNorthBoundLatitude(), STRICT);
+        assertEquals("extentTypeCode", Boolean.TRUE, box.getInclusion());
+    }
+}

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/SpecialCasesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -42,6 +42,7 @@ import org.junit.BeforeClass;
     // Classes using Java reflection.
     org.apache.sis.metadata.PropertyInformationTest.class,
     org.apache.sis.metadata.PropertyAccessorTest.class,
+    org.apache.sis.metadata.SpecialCasesTest.class,
     org.apache.sis.metadata.NameMapTest.class,
     org.apache.sis.metadata.TypeMapTest.class,
     org.apache.sis.metadata.InformationMapTest.class,

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/LocalizedParseException.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -54,7 +54,7 @@ public final class LocalizedParseExcepti
     private final Locale locale;
 
     /**
-     * The resources key as one of the {@link Errors.Keys} constant.
+     * The resources key as one of the {@code Errors.Keys} constant.
      */
     private final int key;
 
@@ -68,7 +68,7 @@ public final class LocalizedParseExcepti
      * and message arguments. This is the most generic constructor.
      *
      * @param locale      The locale for {@link #getLocalizedMessage()}.
-     * @param key         The resource key as one of the {@link Errors.Keys} constant.
+     * @param key         The resource key as one of the {@code Errors.Keys} constant.
      * @param arguments   The value of {@link #arguments(String, ParsePosition)}.
      * @param errorOffset The position where the error is found while parsing.
      */
@@ -85,7 +85,7 @@ public final class LocalizedParseExcepti
      * index, and uses that word as the single argument associated to the resource key.
      *
      * @param locale      The locale for {@link #getLocalizedMessage()}.
-     * @param key         The resource key as one of the {@link Errors.Keys} constant.
+     * @param key         The resource key as one of the {@code Errors.Keys} constant.
      * @param text        The full text that {@code Format} failed to parse.
      * @param errorOffset The position where the error is found while parsing.
      */

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -396,7 +396,9 @@ public abstract class CompoundFormat<T> 
             format.setTimeZone(getTimeZone());
             return format;
         } else if (valueType == Angle.class) {
-            return AngleFormat.getInstance(locale);
+            final AngleFormat format = AngleFormat.getInstance(locale);
+            format.applyPattern("#°##′##.#″");
+            return format;
         } else if (valueType == Class.class) {
             return ClassFormat.INSTANCE;
         }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -241,7 +241,7 @@ public class Angle implements Comparable
     private static Format getAngleFormat() {
         assert Thread.holdsLock(Angle.class);
         if (format == null) {
-            format = AngleFormat.getInstance(Locale.ROOT);
+            format = new AngleFormat(AngleFormat.AUTOMATIC_PATTERN, Locale.ROOT);
         }
         return format;
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -97,7 +97,7 @@ import java.util.Objects;
  *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
  * @since   0.3 (derived from geotk-1.0)
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see Angle
@@ -171,6 +171,14 @@ public class AngleFormat extends Format 
     private static final char[] SYMBOLS = {'D', 'M', 'S', '#'};
 
     /**
+     * The pattern for the automatic format. An {@code AngleFormat} in automatic mode determines
+     * the number of degrees/minutes/seconds fields and the number of digits from the angle value.
+     *
+     * @see #isAutomatic
+     */
+    static final String AUTOMATIC_PATTERN = "#°##′##.#″";
+
+    /**
      * Defines constants that are used as attribute keys in the iterator returned from
      * {@link AngleFormat#formatToCharacterIterator(Object)}.
      *
@@ -263,6 +271,14 @@ public class AngleFormat extends Format 
                    secondsSuffix;
 
     /**
+     * {@code true} if this {@code AngleFormat} is in automatic mode. An {@code AngleFormat} in automatic mode
+     * determines the number of degrees/minutes/seconds fields and the number of digits from the angle value.
+     *
+     * @see #AUTOMATIC_PATTERN
+     */
+    private boolean isAutomatic;
+
+    /**
      * {@code true} if the {@link #parse(String, ParsePosition)} method is allowed to fallback
      * on the build-in default symbols if the string to parse doesn't match the pattern.
      *
@@ -360,14 +376,21 @@ public class AngleFormat extends Format 
     public AngleFormat(final Locale locale) {
         ArgumentChecks.ensureNonNull("locale", locale);
         this.locale = locale;
-        degreesFieldWidth     = 1;
-        minutesFieldWidth     = 2;
-        secondsFieldWidth     = 2;
-        fractionFieldWidth    = 16;  // Number of digits for accurate representation of 1″ ULP.
-        degreesSuffix         = "°";
-        minutesSuffix         = "′";
-        secondsSuffix         = "″";
-        useDecimalSeparator   = true;
+        setDefaultPattern();
+    }
+
+    /**
+     * Sets the pattern to the default value.
+     */
+    private void setDefaultPattern() {
+        degreesFieldWidth   = 1;
+        minutesFieldWidth   = 2;
+        secondsFieldWidth   = 2;
+        fractionFieldWidth  = 16;  // Number of digits for accurate representation of 1″ ULP.
+        degreesSuffix       = "°";
+        minutesSuffix       = "′";
+        secondsSuffix       = "″";
+        useDecimalSeparator = true;
     }
 
     /**
@@ -390,6 +413,7 @@ public class AngleFormat extends Format 
      * @throws IllegalArgumentException If the specified pattern is illegal.
      */
     public AngleFormat(final String pattern, final Locale locale) throws IllegalArgumentException {
+        ArgumentChecks.ensureNonEmpty("pattern", pattern);
         ArgumentChecks.ensureNonNull("locale", locale);
         this.locale = locale;
         applyPattern(pattern, SYMBOLS, '.');
@@ -406,6 +430,7 @@ public class AngleFormat extends Format 
      * @see #setMaximumFractionDigits(int)
      */
     public void applyPattern(final String pattern) throws IllegalArgumentException {
+        ArgumentChecks.ensureNonEmpty("pattern", pattern);
         applyPattern(pattern, SYMBOLS, '.');
     }
 
@@ -419,7 +444,6 @@ public class AngleFormat extends Format 
      */
     @SuppressWarnings("fallthrough")
     private void applyPattern(final String pattern, final char[] symbols, final int decimalSeparator) {
-        ArgumentChecks.ensureNonEmpty("pattern", pattern);
         degreesFieldWidth     = 1;
         minutesFieldWidth     = 0;
         secondsFieldWidth     = 0;
@@ -431,6 +455,11 @@ public class AngleFormat extends Format 
         minutesSuffix         = null;
         secondsSuffix         = null;
         useDecimalSeparator   = true;
+        isAutomatic = pattern.equals(AUTOMATIC_PATTERN);
+        if (isAutomatic) {
+            setDefaultPattern();
+            return;
+        }
         int expectedField     = PREFIX_FIELD;
         int endPreviousField  = 0;
         boolean parseFinished = false;
@@ -557,6 +586,9 @@ scan:   for (int i=0; i<length;) {
      * @param decimalSeparator The code point which represent decimal separator in the pattern.
      */
     private String toPattern(final char[] symbols, final int decimalSeparator) {
+        if (isAutomatic) {
+            return AUTOMATIC_PATTERN;
+        }
         char symbol = 0;
         final StringBuilder buffer = new StringBuilder();
         for (int field=DEGREES_FIELD; field<=FRACTION_FIELD; field++) {
@@ -809,6 +841,25 @@ scan:   for (int i=0; i<length;) {
             }
             return toAppendTo;
         }
+        /*
+         * The 'minutesFieldWidth' and 'secondsFieldWidth' local variables below have the same values
+         * than the corresponding fields, except in automatic mode where the values may be set to 0.
+         * After the 'isAutomatic' check, those variables shall be considered as read-only.
+         */
+        int minutesFieldWidth = this.minutesFieldWidth;
+        int secondsFieldWidth = this.secondsFieldWidth;
+        int maximumFractionDigits = fractionFieldWidth;
+        if (isAutomatic) {
+            double r = abs(angle) * 60;
+            if (r == Math.floor(r)) {
+                maximumFractionDigits = 0;
+                secondsFieldWidth = 0;
+                r = abs(angle);
+                if (r == Math.floor(r)) {
+                    minutesFieldWidth = 0;
+                }
+            }
+        }
         double degrees = angle;
         /*
          * Computes the numerical values of minutes and seconds fields.
@@ -843,7 +894,6 @@ scan:   for (int i=0; i<length;) {
          * fraction digits for a 'double' value. The intend is to avoid non-significant garbage
          * that are pure artifacts from the conversion from base 2 to base 10.
          */
-        int maximumFractionDigits = fractionFieldWidth;
         if (maximumFractionDigits != minimumFractionDigits) {
             if      (secondsFieldWidth != 0) angle *= 3600;
             else if (minutesFieldWidth != 0) angle *=   60;
@@ -1633,9 +1683,9 @@ BigBoss:    switch (skipSuffix(source, p
      */
     @Override
     public int hashCode() {
-        return Objects.hash(degreesFieldWidth, minutesFieldWidth, secondsFieldWidth,
-                fractionFieldWidth, minimumFractionDigits, useDecimalSeparator, isFallbackAllowed,
-                locale, prefix, degreesSuffix, minutesSuffix, secondsSuffix) ^ (int) serialVersionUID;
+        return Objects.hash(degreesFieldWidth, minutesFieldWidth, secondsFieldWidth, fractionFieldWidth,
+                minimumFractionDigits, useDecimalSeparator, isFallbackAllowed, isAutomatic, locale,
+                prefix, degreesSuffix, minutesSuffix, secondsSuffix) ^ (int) serialVersionUID;
     }
 
     /**
@@ -1657,14 +1707,14 @@ BigBoss:    switch (skipSuffix(source, p
                    minimumFractionDigits == cast.minimumFractionDigits &&
                    useDecimalSeparator   == cast.useDecimalSeparator   &&
                    isFallbackAllowed     == cast.isFallbackAllowed     &&
+                   isAutomatic           == cast.isAutomatic           &&
                    Objects.equals(locale,        cast.locale)          &&
                    Objects.equals(prefix,        cast.prefix)          &&
                    Objects.equals(degreesSuffix, cast.degreesSuffix)   &&
                    Objects.equals(minutesSuffix, cast.minutesSuffix)   &&
                    Objects.equals(secondsSuffix, cast.secondsSuffix);
-        } else {
-            return false;
         }
+        return false;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/converter/StringConverterTest.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -189,7 +189,8 @@ public final strictfp class StringConver
     @Test
     public void testAngle() {
         final ObjectConverter<String,Angle> c = new StringConverter.Angle();
-        runInvertibleConversion(c, "42°30′00″", new Angle(42.5));
+        runInvertibleConversion(c, "42°30′",       new Angle(42.5));
+        runInvertibleConversion(c, "42°30′56.25″", new Angle(42.515625));
         tryUnconvertibleValue(c);
         assertSerializedEquals(c);
     }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -33,7 +33,7 @@ import static org.apache.sis.test.TestUt
  *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
  * @since   0.3 (derived from geotk-2.0)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @DependsOn({
@@ -130,6 +130,20 @@ public final strictfp class AngleFormatT
     }
 
     /**
+     * Tests with optional minutes and seconds fields.
+     */
+    @Test
+    @DependsOnMethod("testDegreeMinutesSeconds")
+    public void testOptionalFields() {
+        final AngleFormat f = new AngleFormat(AngleFormat.AUTOMATIC_PATTERN, Locale.CANADA);
+        assertEquals(AngleFormat.AUTOMATIC_PATTERN, f.toPattern());
+        assertEquals("12°",          formatAndParse(f, new Angle(12)));
+        assertEquals("12°30′",       formatAndParse(f, new Angle(12.5)));
+        assertEquals("12°00′36″",    formatAndParse(f, new Angle(12.01)));
+        assertEquals("12°30′56.25″", formatAndParse(f, new Angle(12.515625)));
+    }
+
+    /**
      * Tests with optional digits.
      */
     @Test

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleTest.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/measure/AngleTest.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -29,7 +29,7 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
  * @since   0.3 (derived from geotk-2.0)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @DependsOn(AngleFormatTest.class)
@@ -39,9 +39,11 @@ public final strictfp class AngleTest ex
      */
     @Test
     public void testToString() {
-        assertEquals("45°30′00″",  new Angle    (45.5).toString());
-        assertEquals("45°30′00″N", new Latitude (45.5).toString());
-        assertEquals("45°30′00″E", new Longitude(45.5).toString());
+        assertEquals("45°",           new Angle    (45  ).toString());
+        assertEquals("45°30′",        new Angle    (45.5).toString());
+        assertEquals("45°30′N",       new Latitude (45.5).toString());
+        assertEquals("45°30′E",       new Longitude(45.5).toString());
+        assertEquals("45°30′56.25″E", new Longitude(45.515625).toString());
 
         // Angle out of expected range.
         assertEquals( "720.0°E", new Longitude( 720).toString());
@@ -59,6 +61,7 @@ public final strictfp class AngleTest ex
      */
     @Test
     public void testParse() {
+        assertEquals(new Angle    (45.5), new Angle    ("45°30′"));
         assertEquals(new Angle    (45.5), new Angle    ("45°30′00″"));
         assertEquals(new Latitude (45.5), new Latitude ("45°30′00″N"));
         assertEquals(new Longitude(45.5), new Longitude("45°30′00″E"));

Modified: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1513186&r1=1513185&r2=1513186&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] Mon Aug 12 16:13:09 2013
@@ -107,10 +107,10 @@ public final strictfp class MetadataRead
             "  │   ├─Spatial representation type……………………………… Grid\n" +
             "  │   ├─Extent\n" +
             "  │   │   ├─Geographic element\n" +
-            "  │   │   │   ├─West bound longitude…………………………… -180.0\n" +
-            "  │   │   │   ├─East bound longitude…………………………… 180.0\n" +
-            "  │   │   │   ├─South bound latitude…………………………… -90.0\n" +
-            "  │   │   │   ├─North bound latitude…………………………… 90.0\n" +
+            "  │   │   │   ├─West bound longitude…………………………… 180°W\n" +
+            "  │   │   │   ├─East bound longitude…………………………… 180°E\n" +
+            "  │   │   │   ├─South bound latitude…………………………… 90°S\n" +
+            "  │   │   │   ├─North bound latitude…………………………… 90°N\n" +
             "  │   │   │   └─Extent type code……………………………………… true\n" +
             "  │   │   └─Vertical element\n" +
             "  │   │       ├─Minimum value……………………………………………… 0.0\n" +