commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1588818 - in /commons/proper/configuration/branches/immutableNodes/src: main/java/org/apache/commons/configuration/tree/ test/java/org/apache/commons/configuration/tree/
Date Sun, 20 Apr 2014 19:14:42 GMT
Author: oheger
Date: Sun Apr 20 19:14:41 2014
New Revision: 1588818

URL: http://svn.apache.org/r1588818
Log:
NodeModel.clearTree() now returns information about removed elements.

This is necessary to correctly populate a CLEAR_TREE event for hierarchical
configurations. InMemoryNodeModel here returns a list with QueryResult objects
for the nodes or attributes selected by the key passed to clearTree().

Modified:
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeModel.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java?rev=1588818&r1=1588817&r2=1588818&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
Sun Apr 20 19:14:41 2014
@@ -257,11 +257,13 @@ public class InMemoryNodeModel implement
     /**
      * {@inheritDoc} This implementation checks whether nodes become undefined
      * after subtrees have been removed. If this is the case, such nodes are
-     * removed, too.
+     * removed, too. Return value is a collection with {@code QueryResult}
+     * objects for the elements to be removed from the model.
      */
-    public void clearTree(String key, NodeKeyResolver<ImmutableNode> resolver)
+    public List<QueryResult<ImmutableNode>> clearTree(String key,
+            NodeKeyResolver<ImmutableNode> resolver)
     {
-        clearTree(key, null, resolver);
+        return clearTree(key, null, resolver);
     }
 
     /**
@@ -275,19 +277,25 @@ public class InMemoryNodeModel implement
      * @param selector the {@code NodeSelector} defining the root node (or
      *        <b>null</b>)
      * @param resolver the {@code NodeKeyResolver}
+     * @return a list with the results to be removed
      * @throws ConfigurationRuntimeException if the selector cannot be resolved
      */
-    public void clearTree(final String key, NodeSelector selector,
-            final NodeKeyResolver<ImmutableNode> resolver)
+    public List<QueryResult<ImmutableNode>> clearTree(final String key,
+            NodeSelector selector, final NodeKeyResolver<ImmutableNode> resolver)
     {
+        final List<QueryResult<ImmutableNode>> removedElements =
+                new LinkedList<QueryResult<ImmutableNode>>();
         updateModel(new TransactionInitializer()
         {
             public boolean initTransaction(ModelTransaction tx)
             {
                 boolean changes = false;
                 TreeData currentStructure = tx.getCurrentData();
-                for (QueryResult<ImmutableNode> result : resolver.resolveKey(
-                        tx.getQueryRoot(), key, currentStructure))
+                List<QueryResult<ImmutableNode>> results = resolver.resolveKey(
+                        tx.getQueryRoot(), key, currentStructure);
+                removedElements.clear();
+                removedElements.addAll(results);
+                for (QueryResult<ImmutableNode> result : results)
                 {
                     if (result.isAttributeResult())
                     {
@@ -311,6 +319,8 @@ public class InMemoryNodeModel implement
                 return changes;
             }
         }, selector, resolver);
+
+        return removedElements;
     }
 
     /**

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeModel.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeModel.java?rev=1588818&r1=1588817&r2=1588818&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeModel.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeModel.java
Sun Apr 20 19:14:41 2014
@@ -112,8 +112,9 @@ public interface NodeModel<T>
      *
      * @param key the key selecting the properties to be removed
      * @param resolver the {@code NodeKeyResolver}
+     * @return an object with information about the data removed
      */
-    void clearTree(String key, NodeKeyResolver<T> resolver);
+    Object clearTree(String key, NodeKeyResolver<T> resolver);
 
     /**
      * Clears the value of a property. This method is similar to

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java?rev=1588818&r1=1588817&r2=1588818&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java
Sun Apr 20 19:14:41 2014
@@ -321,7 +321,7 @@ public class TestInMemoryNodeModel
                 Collections.singletonList(result));
         EasyMock.replay(resolver);
 
-        model.clearTree(KEY, resolver);
+        List<QueryResult<ImmutableNode>> removed = model.clearTree(KEY, resolver);
         ImmutableNode node = nodeForKey(model, "Homer/Ilias");
         assertEquals("Wrong number of children", 2, node.getChildren().size());
         for (ImmutableNode c : node.getChildren())
@@ -329,6 +329,8 @@ public class TestInMemoryNodeModel
             assertNotEquals("Node still found", result.getNode().getNodeName(),
                     c.getNodeName());
         }
+        assertEquals("Wrong number of removed elements", 1, removed.size());
+        assertTrue("Wrong removed element", removed.contains(result));
     }
 
     /**
@@ -477,17 +479,20 @@ public class TestInMemoryNodeModel
         NodeKeyResolver<ImmutableNode> resolver = createResolver();
         InMemoryNodeModel model = new InMemoryNodeModel(ROOT_PERSONAE_TREE);
         final String nodeName = "Puck";
+        QueryResult<ImmutableNode> result = QueryResult.createAttributeResult(
+                nodeForKey(model, nodeName),
+                NodeStructureHelper.ATTR_AUTHOR);
         EasyMock.expect(
                 resolver.resolveKey(ROOT_PERSONAE_TREE, KEY,
                         model.getNodeHandler())).andReturn(
-                Collections.singletonList(QueryResult.createAttributeResult(
-                        nodeForKey(model, nodeName),
-                        NodeStructureHelper.ATTR_AUTHOR)));
+                Collections.singletonList(result));
         EasyMock.replay(resolver);
 
-        model.clearTree(KEY, resolver);
+        List<QueryResult<ImmutableNode>> removed = model.clearTree(KEY, resolver);
         ImmutableNode node = nodeForKey(model, nodeName);
         assertTrue("Got still attributes", node.getAttributes().isEmpty());
+        assertEquals("Wrong number of removed elements", 1, removed.size());
+        assertTrue("Wrong removed element", removed.contains(result));
     }
 
     /**
@@ -539,7 +544,7 @@ public class TestInMemoryNodeModel
         EasyMock.replay(resolver);
 
         TreeData treeDataOld = model.getTreeData();
-        model.clearTree(KEY, resolver);
+        assertTrue("Elements removed", model.clearTree(KEY, resolver).isEmpty());
         assertNotNull("No root node", model.getNodeHandler().getRootNode());
         assertSame("Data was changed", treeDataOld, model.getTreeData());
     }



Mime
View raw message