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 2014/02/23 19:37:18 UTC

svn commit: r1571051 - in /commons/proper/configuration/branches/immutableNodes/src: main/java/org/apache/commons/configuration/tree/NodeUpdateData.java test/java/org/apache/commons/configuration/tree/TestNodeUpdateData.java

Author: oheger
Date: Sun Feb 23 18:37:17 2014
New Revision: 1571051

URL: http://svn.apache.org/r1571051
Log:
Changed some method signatures in NodeUpdateData.

An instance has to store QueryResult objects rather than plain nodes.

Modified:
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeUpdateData.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeUpdateData.java

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeUpdateData.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeUpdateData.java?rev=1571051&r1=1571050&r2=1571051&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeUpdateData.java (original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/NodeUpdateData.java Sun Feb 23 18:37:17 2014
@@ -31,13 +31,13 @@ import java.util.Map;
  * The {@code Configuration} interface provides a method for setting the value
  * of a given key. The passed in value can be a single object or a collection of
  * values. This makes an update operation rather complicated because a
- * collection of nodes identified by the passed in key has to be matched to
- * another collection of values - and both collections can have different sizes.
- * Therefore, an update operation may involve changing of existing nodes, adding
- * new nodes (if there are more values than currently existing nodes), and
- * removing nodes (if there are more existing nodes than provided values). This
- * class collects all this information making it possible to actually perform
- * the update based on a passed in instance.
+ * collection of query results selected by the passed in key has to be matched
+ * to another collection of values - and both collections can have different
+ * sizes. Therefore, an update operation may involve changing of existing nodes,
+ * adding new nodes (if there are more values than currently existing nodes),
+ * and removing nodes (if there are more existing nodes than provided values).
+ * This class collects all this information making it possible to actually
+ * perform the update based on a passed in instance.
  * </p>
  *
  * @version $Id$
@@ -46,14 +46,14 @@ import java.util.Map;
  */
 public class NodeUpdateData<T>
 {
-    /** The map with the nodes whose value has to be changed. */
-    private final Map<T, Object> changedValues;
+    /** The map with the query results whose value has to be changed. */
+    private final Map<QueryResult<T>, Object> changedValues;
 
     /** The collection with the new values to be added. */
     private final Collection<Object> newValues;
 
-    /** The collection with the nodes to be removed. */
-    private final Collection<T> removedNodes;
+    /** The collection with query results about the nodes to be removed. */
+    private final Collection<QueryResult<T>> removedNodes;
 
     /** The key of the current update operation. */
     private final String key;
@@ -68,8 +68,9 @@ public class NodeUpdateData<T>
      * @param removedNodes the collection with the nodes to be removed
      * @param key the key of the update operation
      */
-    public NodeUpdateData(Map<T, Object> changedValues,
-            Collection<Object> newValues, Collection<T> removedNodes, String key)
+    public NodeUpdateData(Map<QueryResult<T>, Object> changedValues,
+            Collection<Object> newValues,
+            Collection<QueryResult<T>> removedNodes, String key)
     {
         this.changedValues = copyMap(changedValues);
         this.newValues = copyCollection(newValues);
@@ -79,12 +80,12 @@ public class NodeUpdateData<T>
 
     /**
      * Returns an unmodifiable map with the values to be changed. The keys of
-     * the map are the nodes affected, the values are the new values to be
-     * assigned to these nodes.
+     * the map are the query results for the nodes affected, the values are the
+     * new values to be assigned to these nodes.
      *
      * @return the map with values to be changed
      */
-    public Map<T, Object> getChangedValues()
+    public Map<QueryResult<T>, Object> getChangedValues()
     {
         return changedValues;
     }
@@ -108,7 +109,7 @@ public class NodeUpdateData<T>
      *
      * @return the collection with nodes to be removed
      */
-    public Collection<T> getRemovedNodes()
+    public Collection<QueryResult<T>> getRemovedNodes()
     {
         return removedNodes;
     }

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeUpdateData.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeUpdateData.java?rev=1571051&r1=1571050&r2=1571051&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeUpdateData.java (original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeUpdateData.java Sun Feb 23 18:37:17 2014
@@ -48,19 +48,33 @@ public class TestNodeUpdateData
     }
 
     /**
+     * Convenience method for creating a query result object.
+     *
+     * @param value the value of this result
+     * @return the result object
+     */
+    private static QueryResult<Object> result(Object value)
+    {
+        return QueryResult.createNodeResult(value);
+    }
+
+    /**
      * Tests whether a defensive copy is created from the changed values.
      */
     @Test
     public void testInitChangedValuesDefensiveCopy()
     {
-        Map<Object, Object> map = new HashMap<Object, Object>();
-        map.put("test", "value");
+        Map<QueryResult<Object>, Object> map =
+                new HashMap<QueryResult<Object>, Object>();
+        map.put(result("test"), "value");
         NodeUpdateData<Object> data =
                 new NodeUpdateData<Object>(map, null, null, null);
-        map.put("anotherTest", "anotherValue");
-        Map<Object, Object> changedValues = data.getChangedValues();
+        map.put(result("anotherTest"), "anotherValue");
+        Map<QueryResult<Object>, Object> changedValues =
+                data.getChangedValues();
         assertEquals("Wrong number of changed values", 1, changedValues.size());
-        assertEquals("Wrong changed value", "value", changedValues.get("test"));
+        assertEquals("Wrong changed value", "value",
+                changedValues.get(result("test")));
     }
 
     /**
@@ -85,14 +99,16 @@ public class TestNodeUpdateData
     @Test
     public void testInitRemovedNodesDefensiveCopy()
     {
-        Collection<Object> col = new LinkedList<Object>();
-        col.add("n1");
+        Collection<QueryResult<Object>> col =
+                new LinkedList<QueryResult<Object>>();
+        col.add(result("n1"));
         NodeUpdateData<Object> data =
                 new NodeUpdateData<Object>(null, null, col, null);
-        col.add("n2");
-        Collection<Object> removedNodes = data.getRemovedNodes();
+        col.add(result("n2"));
+        Collection<QueryResult<Object>> removedNodes = data.getRemovedNodes();
         assertEquals("Wrong number of new values", 1, removedNodes.size());
-        assertEquals("Wrong value", "n1", removedNodes.iterator().next());
+        assertEquals("Wrong value", result("n1"), removedNodes.iterator()
+                .next());
     }
 
     /**
@@ -101,11 +117,12 @@ public class TestNodeUpdateData
     @Test(expected = UnsupportedOperationException.class)
     public void testGetChangedValuesModify()
     {
-        Map<Object, Object> map = new HashMap<Object, Object>();
-        map.put("n1", 42);
+        Map<QueryResult<Object>, Object> map =
+                new HashMap<QueryResult<Object>, Object>();
+        map.put(result("n1"), 42);
         NodeUpdateData<Object> data =
                 new NodeUpdateData<Object>(map, null, null, null);
-        data.getChangedValues().put("n2", 43);
+        data.getChangedValues().put(result("n2"), 43);
     }
 
     /**
@@ -127,10 +144,11 @@ public class TestNodeUpdateData
     @Test(expected = UnsupportedOperationException.class)
     public void testGetRemovedNodesModify()
     {
-        Collection<String> col = new LinkedList<String>();
-        col.add("n1");
-        NodeUpdateData<String> data =
-                new NodeUpdateData<String>(null, null, col, null);
-        data.getRemovedNodes().add("newNode");
+        Collection<QueryResult<Object>> col =
+                new LinkedList<QueryResult<Object>>();
+        col.add(result("n1"));
+        NodeUpdateData<Object> data =
+                new NodeUpdateData<Object>(null, null, col, null);
+        data.getRemovedNodes().add(result("newNode"));
     }
 }