commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r819395 - in /commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/HierarchicalConfiguration.java src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java xdocs/changes.xml
Date Sun, 27 Sep 2009 20:05:51 GMT
Author: oheger
Date: Sun Sep 27 20:05:50 2009
New Revision: 819395

URL: http://svn.apache.org/viewvc?rev=819395&view=rev
Log:
CONFIGURATION-396: HierarchicalConfiguration.NodeVisitor is now passed the correct key to
its visitAfterChildren() method.

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

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=819395&r1=819394&r2=819395&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
Sun Sep 27 20:05:50 2009
@@ -1356,11 +1356,11 @@
                 }
             }
 
+            visitor.visitAfterChildren(this, key);
             if (key != null)
             {
                 key.setLength(length);
             }
-            visitor.visitAfterChildren(this, key);
         }
     }
 

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=819395&r1=819394&r2=819395&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
Sun Sep 27 20:05:50 2009
@@ -766,8 +766,27 @@
     {
         CountVisitor v = new CountVisitor();
         config.getRoot().visit(v, null);
-        assertEquals(28, v.beforeCount);
-        assertEquals(v.beforeCount, v.afterCount);
+        assertEquals("Wrong number of visits", 28, v.beforeCount);
+        assertEquals("Different number of before and after visits",
+                v.beforeCount, v.afterCount);
+    }
+
+    /**
+     * Tests the visitor mechanism if a ConfigurationKey is passed in.
+     */
+    public void testNodeVisitorKeys()
+    {
+        CountVisitor v = new CountVisitor();
+        ConfigurationKey configKey = new ConfigurationKey();
+        config.getRoot().visit(v, configKey);
+        for (Iterator it = config.getKeys(); it.hasNext();)
+        {
+            String key = (String) it.next();
+            assertTrue("Key not found in before keys: " + key, v.beforeKeys
+                    .contains(key));
+            assertTrue("Key not found in after keys: " + key, v.afterKeys
+                    .contains(key));
+        }
     }
 
     /**
@@ -1112,20 +1131,36 @@
      */
     static class CountVisitor extends HierarchicalConfiguration.NodeVisitor
     {
-        public int beforeCount;
+        /** The number of invocations of visitBeforeChildren(). */
+        int beforeCount;
+
+        /** The number of invocations of visitAfterChildren(). */
+        int afterCount;
 
-        public int afterCount;
+        /** A set with the keys passed to visitBeforeChildren(). */
+        final Set beforeKeys = new HashSet();
+
+        /** A set with the keys passed to visitAfterChildren(). */
+        final Set afterKeys = new HashSet();
 
         public void visitAfterChildren(Node node, ConfigurationKey key)
         {
             super.visitAfterChildren(node, key);
             afterCount++;
+            if (key != null)
+            {
+                afterKeys.add(key.toString());
+            }
         }
 
         public void visitBeforeChildren(Node node, ConfigurationKey key)
         {
             super.visitBeforeChildren(node, key);
             beforeCount++;
+            if (key != null)
+            {
+                beforeKeys.add(key.toString());
+            }
         }
     }
 }

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=819395&r1=819394&r2=819395&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Sun Sep 27 20:05:50 2009
@@ -23,6 +23,10 @@
 
   <body>
     <release version="1.7" date="in SVN" description="">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-396">
+        HierarchicalConfiguration.NodeVisitor is now passed the correct key to
+        its visitAfterChildren() method.
+      </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-393">
         BaseConfiguration.clone() now also clones collections stored in the
         internal map. This causes list properties to be handled correctly.



Mime
View raw message