commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1578584 - in /commons/proper/configuration/branches/immutableNodes/src: main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Date Mon, 17 Mar 2014 21:13:15 GMT
Author: oheger
Date: Mon Mar 17 21:13:14 2014
New Revision: 1578584

URL: http://svn.apache.org/r1578584
Log:
Implemented childConfigurationsAt() in BaseHierarchicalConfiguration.

Modified:
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java?rev=1578584&r1=1578583&r2=1578584&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
Mon Mar 17 21:13:14 2014
@@ -20,6 +20,7 @@ package org.apache.commons.configuration
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -291,6 +292,23 @@ public class BaseHierarchicalConfigurati
     }
 
     /**
+     * Returns an initialized sub configuration for this configuration that is
+     * based on another {@code BaseHierarchicalConfiguration}. Thus, it is
+     * independent from this configuration.
+     *
+     * @param node the root node for the sub configuration
+     * @return the initialized sub configuration
+     */
+    private BaseHierarchicalConfiguration createIndependentSubConfigurationForNode(
+            ImmutableNode node)
+    {
+        BaseHierarchicalConfiguration sub =
+                new BaseHierarchicalConfiguration(new InMemoryNodeModel(node));
+        initSubConfiguration(sub);
+        return sub;
+    }
+
+    /**
      * Executes a query on the specified key and filters it for node results.
      *
      * @param key the key
@@ -359,9 +377,7 @@ public class BaseHierarchicalConfigurati
         for (ImmutableNode node : nodes)
         {
             BaseHierarchicalConfiguration sub =
-                    new BaseHierarchicalConfiguration(new InMemoryNodeModel(
-                            node));
-            initSubConfiguration(sub);
+                    createIndependentSubConfigurationForNode(node);
             results.add(sub);
         }
 
@@ -385,33 +401,25 @@ public class BaseHierarchicalConfigurati
      * given key. If not a single node is selected, an empty list is returned.
      * Otherwise, sub configurations for each child of the node are created.
      */
-    public List<HierarchicalConfiguration<ImmutableNode>> childConfigurationsAt(String
key)
+    public List<HierarchicalConfiguration<ImmutableNode>> childConfigurationsAt(
+            String key)
     {
-        beginWrite(false);
-        try
+        List<ImmutableNode> nodes = fetchFilteredNodeResults(key);
+        if (nodes.size() != 1)
         {
-//            List<ConfigurationNode> nodes = fetchNodeList(key);
-//            if (nodes.size() != 1)
-//            {
-//                return Collections.emptyList();
-//            }
-//
-//            ConfigurationNode parent = nodes.get(0);
-//            List<SubnodeConfiguration> subs =
-//                    new ArrayList<SubnodeConfiguration>(
-//                            parent.getChildrenCount());
-//            for (ConfigurationNode c : parent.getChildren())
-//            {
-//                subs.add(createAndInitializeSubnodeConfiguration(c, null, false));
-//            }
-//            return subs;
-            //TODO implementation
-            return null;
+            return Collections.emptyList();
         }
-        finally
+
+        ImmutableNode parent = nodes.get(0);
+        List<HierarchicalConfiguration<ImmutableNode>> subs =
+                new ArrayList<HierarchicalConfiguration<ImmutableNode>>(parent
+                        .getChildren().size());
+        for (ImmutableNode node : parent.getChildren())
         {
-            endWrite();
+            subs.add(createIndependentSubConfigurationForNode(node));
         }
+
+        return subs;
     }
 
     /**

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=1578584&r1=1578583&r2=1578584&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Mon Mar 17 21:13:14 2014
@@ -407,6 +407,17 @@ public class TestHierarchicalConfigurati
                 .isEmpty());
     }
 
+    /**
+     * Tests configurationsAt() if an attribute key is passed in.
+     */
+    @Test
+    public void testConfigurationsAtAttributeKey()
+    {
+        String attrKey = "tables.table(0)[@type]";
+        config.addProperty(attrKey, "user");
+        assertTrue("Got configurations", config.configurationsAt(attrKey).isEmpty());
+    }
+
     @Test
     public void testClone()
     {
@@ -522,7 +533,7 @@ public class TestHierarchicalConfigurati
         HierarchicalConfiguration<ImmutableNode> sub = children.get(0);
         String newTabName = "otherTabe";
         sub.setProperty(null, newTabName);
-        assertEquals("Table name not changed", newTabName,
+        assertEquals("Table name changed in parent", NodeStructureHelper.table(0),
                 config.getString("tables.table(0).name"));
     }
 



Mime
View raw message