commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1152923 - in /commons/proper/configuration/trunk/src: changes/changes.xml java/org/apache/commons/configuration/HierarchicalConfiguration.java test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Date Mon, 01 Aug 2011 20:28:05 GMT
Author: oheger
Date: Mon Aug  1 20:28:03 2011
New Revision: 1152923

URL: http://svn.apache.org/viewvc?rev=1152923&view=rev
Log:
[CONFIGURATION-458] Provide a specific implementation of clear() in HierarchicalConfiguration.

Modified:
    commons/proper/configuration/trunk/src/changes/changes.xml
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java

Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1152923&r1=1152922&r2=1152923&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Mon Aug  1 20:28:03 2011
@@ -23,6 +23,11 @@
 
   <body>
     <release version="1.7" date="in SVN" description="">
+      <action dev="oheger" type="add" issue="CONFIGURATION-458">
+        HierarchicalConfiguration now provides a specific implementation of the
+        clear() method. This is more efficient and also solves some other
+        problems related to clearing a SubnodeConfiguration.
+      </action>
       <action dev="oheger" type="add" issue="CONFIGURATION-452">
         XPathExpressionEngine now provides better support for the setProperty()
         method.

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java?rev=1152923&r1=1152922&r2=1152923&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
Mon Aug  1 20:28:03 2011
@@ -770,6 +770,20 @@ public class HierarchicalConfiguration e
     }
 
     /**
+     * Clears this configuration. This is a more efficient implementation than
+     * the one inherited from the base class. It directly removes all data from
+     * the root node.
+     */
+    public void clear()
+    {
+        fireEvent(EVENT_CLEAR, null, null, true);
+        getRootNode().removeAttributes();
+        getRootNode().removeChildren();
+        getRootNode().setValue(null);
+        fireEvent(EVENT_CLEAR, null, null, false);
+    }
+
+    /**
      * Removes all values of the property with the given name and of keys that
      * start with this name. So if there is a property with the key
      * &quot;foo&quot; and a property with the key &quot;foo.bar&quot;, a
call

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=1152923&r1=1152922&r2=1152923&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Mon Aug  1 20:28:03 2011
@@ -189,6 +189,14 @@ public class TestHierarchicalConfigurati
         assertEquals(42, config.getInt("test.items.item"));
     }
 
+    public void testClear()
+    {
+        config.setProperty(null, "value");
+        config.addProperty("[@attr]", "defined");
+        config.clear();
+        assertTrue("Configuration not empty", config.isEmpty());
+    }
+
     public void testClearProperty()
     {
         config.clearProperty("tables.table(0).fields.field(0).name");
@@ -580,6 +588,24 @@ public class TestHierarchicalConfigurati
     }
 
     /**
+     * Tests whether a sub configuration obtained by configurationAt() can be
+     * cleared.
+     */
+    public void testConfigurationAtClear()
+    {
+        config.addProperty("test.sub.test", "fail");
+        assertEquals("Wrong index (1)", 0, config.getMaxIndex("test"));
+        SubnodeConfiguration sub = config.configurationAt("test.sub");
+        assertEquals("Wrong value", "fail", sub.getString("test"));
+        sub.clear();
+        assertNull("Key still found", config.getString("test.sub.key"));
+        sub.setProperty("test", "success");
+        assertEquals("Property not set", "success",
+                config.getString("test.sub.test"));
+        assertEquals("Wrong index (2)", 0, config.getMaxIndex("test"));
+    }
+
+    /**
      * Tests the configurationsAt() method.
      */
     public void testConfigurationsAt()



Mime
View raw message