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 2014/09/30 18:15:06 UTC

svn commit: r1628479 - in /sis/branches/JDK8/core/sis-feature: pom.xml src/main/java/org/apache/sis/feature/DenseFeature.java src/test/java/org/apache/sis/feature/DefaultAttributeTypeTest.java src/test/java/org/apache/sis/feature/FeatureTestCase.java

Author: desruisseaux
Date: Tue Sep 30 16:15:06 2014
New Revision: 1628479

URL: http://svn.apache.org/r1628479
Log:
Bug fix: first property value was always null.
Bug identification and patch by Marc le Bihan.
https://issues.apache.org/jira/browse/SIS-178

Modified:
    sis/branches/JDK8/core/sis-feature/pom.xml
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTypeTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java

Modified: sis/branches/JDK8/core/sis-feature/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/pom.xml?rev=1628479&r1=1628478&r2=1628479&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/pom.xml (original)
+++ sis/branches/JDK8/core/sis-feature/pom.xml Tue Sep 30 16:15:06 2014
@@ -58,7 +58,26 @@ Representations of geographic features.
         <role>developer</role>
       </roles>
     </developer>
+    <developer>
+      <name>Martin Desruisseaux</name>
+      <id>desruisseaux</id>
+      <email>desruisseaux@apache.org</email>
+      <organization>Geomatys</organization>
+      <organizationUrl>http://www.geomatys.com</organizationUrl>
+      <timezone>+1</timezone>
+      <roles>
+        <role>developer</role>
+      </roles>
+    </developer>
   </developers>
+  <contributors>
+    <contributor>
+      <name>Marc le Bihan</name>
+      <roles>
+        <role>developer</role>
+      </roles>
+    </contributor>
+  </contributors>
 
 
   <!-- ===========================================================

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java?rev=1628479&r1=1628478&r2=1628479&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java [UTF-8] Tue Sep 30 16:15:06 2014
@@ -36,6 +36,7 @@ import org.opengis.feature.FeatureAssoci
  * all (or almost all) elements in the array will be assigned a value.
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Marc le Bihan
  * @since   0.5
  * @version 0.5
  * @module
@@ -101,17 +102,21 @@ final class DenseFeature extends Abstrac
     @Override
     public Property getProperty(final String name) throws IllegalArgumentException {
         ArgumentChecks.ensureNonNull("name", name);
-        final int index = getIndex(name);
-        if (properties instanceof Property[]) {
-            final Property property = ((Property[]) properties)[index];
-            if (property != null) {
-                return property;
-            }
-        } else {
+        final int index = getIndex(name); // Invoked first because this method checks name validity.
+
+        // Are the properties currently initialized? If not, wrap the values we can find.
+        if (!(properties instanceof Property[])) {
             wrapValuesInProperties();
         }
-        final Property property = createProperty(name);
-        properties[index] = property;
+
+        // Find the wanted property.
+        Property property = ((Property[]) properties)[index];
+
+        // If the property still have a null value, we create it, but we can only tell its type.
+        if (property == null) {
+            property = createProperty(name);
+            properties[index] = property;
+        }
         return property;
     }
 

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTypeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTypeTest.java?rev=1628479&r1=1628478&r2=1628479&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTypeTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAttributeTypeTest.java [UTF-8] Tue Sep 30 16:15:06 2014
@@ -91,9 +91,7 @@ public final strictfp class DefaultAttri
      * @return An attribute type for the name of the parliament in a capital.
      */
     public static DefaultAttributeType<String> parliament() {
-        return new DefaultAttributeType<>(
-                singletonMap(DefaultAttributeType.NAME_KEY, "parliament"),
-                String.class, 1, 1, null);
+        return attribute("parliament");
     }
 
     /**
@@ -109,6 +107,14 @@ public final strictfp class DefaultAttri
     }
 
     /**
+     * Creates a mandatory attribute type of type {@link String}.
+     * This is the kind of attribute created by the ShapeFile reader.
+     */
+    static DefaultAttributeType<String> attribute(final String name) {
+        return new DefaultAttributeType<>(singletonMap(DefaultAttributeType.NAME_KEY, name), String.class, 1, 1, null);
+    }
+
+    /**
      * Tests the creation of a simple {@link DefaultAttributeType} instance for a mandatory singleton.
      */
     @Test

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java?rev=1628479&r1=1628478&r2=1628479&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java [UTF-8] Tue Sep 30 16:15:06 2014
@@ -36,6 +36,7 @@ import static org.apache.sis.test.Assert
  * Tests common to {@link DenseFeatureTest} and {@link SparseFeatureTest}.
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Marc le Bihan
  * @since   0.5
  * @version 0.5
  * @module
@@ -129,11 +130,44 @@ public abstract strictfp class FeatureTe
     }
 
     /**
+     * Tests the {@link AbstractFeature#getProperty(String)} method. This test uses a very simple and
+     * straightforward {@code FeatureType} similar to the ones obtained when reading a ShapeFile.
+     *
+     * <div class="note">In a previous SIS version, the first property value was always {@code null}
+     * if the implementation was {@link DenseFeature} (see SIS-178). This test reproduced the bug,
+     * and now aim to avoid regression.</div>
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-178">SIS-178</a>
+     */
+    @Test
+    public void testGetProperty() {
+        final DefaultFeatureType type = new DefaultFeatureType(
+                Collections.singletonMap(DefaultFeatureType.NAME_KEY, "My shapefile"), false, (DefaultFeatureType[]) null,
+                DefaultAttributeTypeTest.attribute("COMMUNE"),
+                DefaultAttributeTypeTest.attribute("REF_INSEE"),
+                DefaultAttributeTypeTest.attribute("CODE_POSTAL"));
+
+        feature = createFeature(type);
+        feature.setPropertyValue("COMMUNE",     "Bagneux");
+        feature.setPropertyValue("REF_INSEE",   "92007");
+        feature.setPropertyValue("CODE_POSTAL", "92220");
+
+        assertEquals("CODE_POSTAL", "92220",   feature.getProperty("CODE_POSTAL").getValue());
+        assertEquals("REF_INSEE",   "92007",   feature.getProperty("REF_INSEE")  .getValue());
+        assertEquals("COMMUNE",     "Bagneux", feature.getProperty("COMMUNE")    .getValue());
+
+        assertEquals("CODE_POSTAL", "92220",   feature.getPropertyValue("CODE_POSTAL"));
+        assertEquals("REF_INSEE",   "92007",   feature.getPropertyValue("REF_INSEE"));
+        assertEquals("COMMUNE",     "Bagneux", feature.getPropertyValue("COMMUNE"));
+    }
+
+    /**
      * Tests the {@link AbstractFeature#getPropertyValue(String)} method on a simple feature without super-types.
      * This method also tests that attempts to set a value of the wrong type throw an exception and leave the
      * previous value unchanged, that the feature is cloneable and that serialization works.
      */
     @Test
+    @DependsOnMethod("testGetProperty")
     public void testSimpleValues() {
         feature = createFeature(DefaultFeatureTypeTest.city());
         setAttributeValue("city", "Utopia", "Atlantide");