You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2008/03/25 20:48:22 UTC

svn commit: r640958 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/expr/ test/java/org/apache/commons/configuration2/expr/

Author: oheger
Date: Tue Mar 25 12:48:21 2008
New Revision: 640958

URL: http://svn.apache.org/viewvc?rev=640958&view=rev
Log:
Added a getChildrenCount() method to the NodeHandler interface.

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java?rev=640958&r1=640957&r2=640958&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/ConfigurationNodeHandler.java Tue Mar 25 12:48:21 2008
@@ -262,4 +262,16 @@
     {
         return node.getValue() != null || !node.getAttributes().isEmpty();
     }
+
+    /**
+     * Returns the number of children of the specified node.
+     *
+     * @param node the node
+     * @param name the name of the children to take into account or <b>null</b>
+     * @return the number of children
+     */
+    public int getChildrenCount(ConfigurationNode node, String name)
+    {
+        return node.getChildrenCount(name);
+    }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java?rev=640958&r1=640957&r2=640958&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/expr/NodeHandler.java Tue Mar 25 12:48:21 2008
@@ -106,6 +106,23 @@
     T getChild(T node, int index);
 
     /**
+     * Returns the number of children of the specified node with the given name.
+     * This method exists for performance reasons: for some node implementations
+     * it may be by far more efficient to count the children than to query a
+     * list of all children and determine its size. A concrete implementation
+     * can choose the most efficient way to determine the number of children. If
+     * a child name is passed in, only the children with this name are taken
+     * into account. If the name <b>null</b> is passed, the total number of
+     * children must be returned.
+     *
+     * @param node the node
+     * @param name the name of the children in question (can be <b>null</b> for
+     *        all children)
+     * @return the number of the selected children
+     */
+    int getChildrenCount(T node, String name);
+
+    /**
      * Removes the specified child from the given node.
      *
      * @param node the node
@@ -147,13 +164,13 @@
      * <code>NodeHandler</code> implementation supports this). In contrast to
      * <code>setAttributeValue()</code>, an existing attribute value is not
      * removed, but the new value is added to the existing values.
-     * 
+     *
      * @param node the parent node
      * @param name the name of the attribute
      * @param value the value to be added
      */
     void addAttributeValue(T node, String name, Object value);
-    
+
     /**
      * Removes the attribute with the specified name from the given node.
      *

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java?rev=640958&r1=640957&r2=640958&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/expr/TestConfigurationNodeHandler.java Tue Mar 25 12:48:21 2008
@@ -357,4 +357,18 @@
         assertFalse("Node is defined", handler.isDefined(node));
         EasyMock.verify(node);
     }
+
+    /**
+     * Tests querying the number of children.
+     */
+    public void testGetChildrenCount()
+    {
+        ConfigurationNode node = mockNode();
+        final Integer count = 42;
+        EasyMock.expect(node.getChildrenCount(NAME)).andReturn(count);
+        EasyMock.replay(node);
+        assertEquals("Wrong number of children", count.intValue(), handler
+                .getChildrenCount(node, NAME));
+        EasyMock.verify(node);
+    }
 }