sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1477811 - in /sis/branches/JDK7/sis-metadata/src: main/java/org/apache/sis/metadata/MetadataTreeChildren.java test/java/org/apache/sis/metadata/MetadataTreeChildrenTest.java
Date Tue, 30 Apr 2013 20:25:54 GMT
Author: desruisseaux
Date: Tue Apr 30 20:25:54 2013
New Revision: 1477811

URL: http://svn.apache.org/r1477811
Log:
Override the default 'clear()' method with a more efficient implementation (easy).

Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataTreeChildren.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTreeChildrenTest.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataTreeChildren.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataTreeChildren.java?rev=1477811&r1=1477810&r2=1477811&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataTreeChildren.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataTreeChildren.java
[UTF-8] Tue Apr 30 20:25:54 2013
@@ -123,6 +123,13 @@ final class MetadataTreeChildren extends
      * value policy. To check if the element shall be considered as removed (for example
      * in order to update index), invoke {@code isSkipped(value)} after this method.</p>
      *
+     * {@section Implementation note}
+     * This method sets the property to {@code null}. This is not strictly correct for collections,
+     * since we should rather set the property to an empty collection. However this approach
would
+     * force us to check if the expected collection type is actually a list, a set or any
other type.
+     * Passing null avoid the type check and is safe at least with SIS implementation. We
may revisit
+     * later if this appears to be a problem with other implementations.
+     *
      * @param index The index in the accessor (<em>not</em> the index in this
collection).
      */
     final void clearAt(final int index) {
@@ -232,6 +239,18 @@ final class MetadataTreeChildren extends
     }
 
     /**
+     * Clears all properties in the metadata object. Note that this collection will effectively
+     * by empty after this method call only if the value existence policy is {@code NON_EMPTY},
+     * which is the default.
+     */
+    @Override
+    public void clear() {
+        for (int i=childCount(); --i>=0;) {
+            clearAt(i);
+        }
+    }
+
+    /**
      * Returns an iterator over the nodes in the collection of children.
      */
     @Override

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTreeChildrenTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTreeChildrenTest.java?rev=1477811&r1=1477810&r2=1477811&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTreeChildrenTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTreeChildrenTest.java
[UTF-8] Tue Apr 30 20:25:54 2013
@@ -194,6 +194,20 @@ public final strictfp class MetadataTree
         testRemove(createRandomNumberGenerator("testRemoveWithMultiOccurrences"), children);
     }
 
+    /**
+     * Tests the {@link MetadataTreeChildren#clear()} method.
+     */
+    @Test
+    public void testClear() {
+        final DefaultCitation      citation = metadataWithSingletonInCollections();
+        final MetadataTreeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
+        assertFalse(children.isEmpty());
+        children.clear();
+        assertTrue(children.isEmpty());
+        assertNull(citation.getTitle());
+        assertTrue(citation.getAlternateTitles().isEmpty());
+    }
+
 
     // ------------------------ Support methods for the above tests ------------------------
 
@@ -259,5 +273,6 @@ public final strictfp class MetadataTree
                 }
             }
         } while (!reference.isEmpty());
+        assertTrue(children.isEmpty());
     }
 }



Mime
View raw message