Author: oheger
Date: Tue Aug 2 20:15:46 2011
New Revision: 1153263
URL: http://svn.apache.org/viewvc?rev=1153263&view=rev
Log:
[CONFIGURATION-458] Provide a specific implementation of clear() in
AbstractHierarchicalConfiguration. Ported fix to branch.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractHierarchicalConfiguration.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml?rev=1153263&r1=1153262&r2=1153263&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml
Tue Aug 2 20:15:46 2011
@@ -79,6 +79,11 @@
</release>
<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/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractHierarchicalConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractHierarchicalConfiguration.java?rev=1153263&r1=1153262&r2=1153263&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractHierarchicalConfiguration.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractHierarchicalConfiguration.java
Tue Aug 2 20:15:46 2011
@@ -528,6 +528,33 @@ public abstract class AbstractHierarchic
}
/**
+ * 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.
+ */
+ @Override
+ public void clear()
+ {
+ fireEvent(EVENT_CLEAR, null, null, true);
+ List<T> children =
+ new ArrayList<T>(getNodeHandler().getChildren(getRootNode()));
+ for (T child : children)
+ {
+ getNodeHandler().removeChild(getRootNode(), child);
+ }
+
+ List<String> attrs =
+ new ArrayList<String>(getNodeHandler().getAttributes(
+ getRootNode()));
+ for (String attr : attrs)
+ {
+ getNodeHandler().removeAttribute(getRootNode(), attr);
+ }
+ getNodeHandler().setValue(getRootNode(), 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
* "foo" and a property with the key "foo.bar", a call
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java?rev=1153263&r1=1153262&r2=1153263&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java
Tue Aug 2 20:15:46 2011
@@ -179,6 +179,14 @@ public class TestInMemoryConfiguration e
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");