jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1469250 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
Date Thu, 18 Apr 2013 09:51:51 GMT
Author: jukka
Date: Thu Apr 18 09:51:50 2013
New Revision: 1469250

URL: http://svn.apache.org/r1469250
Log:
OAK-778: Recursive wrapping of ModifiedNodeState

Add ModifiedNodeState.compareAgainstBaseState(NodeStateDiff) to make common comparisons easier

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java?rev=1469250&r1=1469249&r2=1469250&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
Thu Apr 18 09:51:50 2013
@@ -276,47 +276,45 @@ public class ModifiedNodeState extends A
     @Override
     public void compareAgainstBaseState(
             NodeState base, final NodeStateDiff diff) {
-        if (this.base != base) {
-            this.base.compareAgainstBaseState(base, new NodeStateDiff() {
-                @Override
-                public void propertyAdded(PropertyState after) {
-                    if (!properties.containsKey(after.getName())) {
-                        diff.propertyAdded(after);
-                    }
-                }
-                @Override
-                public void propertyChanged(
-                        PropertyState before, PropertyState after) {
-                    if (!properties.containsKey(before.getName())) {
-                        diff.propertyChanged(before, after);
-                    }
-                }
-                @Override
-                public void propertyDeleted(PropertyState before) {
-                    if (!properties.containsKey(before.getName())) {
-                        diff.propertyDeleted(before);
-                    }
-                }
-                @Override
-                public void childNodeAdded(String name, NodeState after) {
-                    if (!nodes.containsKey(name)) {
-                        diff.childNodeAdded(name, after);
-                    }
-                }
-                @Override
-                public void childNodeChanged(String name, NodeState before, NodeState after)
{
-                    if (!nodes.containsKey(name)) {
-                        diff.childNodeChanged(name, before, after);
-                    }
-                }
-                @Override
-                public void childNodeDeleted(String name, NodeState before) {
-                    if (!nodes.containsKey(name)) {
-                        diff.childNodeDeleted(name, before);
-                    }
+        this.base.compareAgainstBaseState(base, new NodeStateDiff() {
+            @Override
+            public void propertyAdded(PropertyState after) {
+                if (!properties.containsKey(after.getName())) {
+                    diff.propertyAdded(after);
                 }
-            });
-        }
+            }
+            @Override
+            public void propertyChanged(
+                    PropertyState before, PropertyState after) {
+                if (!properties.containsKey(before.getName())) {
+                    diff.propertyChanged(before, after);
+                }
+            }
+            @Override
+            public void propertyDeleted(PropertyState before) {
+                if (!properties.containsKey(before.getName())) {
+                    diff.propertyDeleted(before);
+                }
+            }
+            @Override
+            public void childNodeAdded(String name, NodeState after) {
+                if (!nodes.containsKey(name)) {
+                    diff.childNodeAdded(name, after);
+                }
+            }
+            @Override
+            public void childNodeChanged(String name, NodeState before, NodeState after)
{
+                if (!nodes.containsKey(name)) {
+                    diff.childNodeChanged(name, before, after);
+                }
+            }
+            @Override
+            public void childNodeDeleted(String name, NodeState before) {
+                if (!nodes.containsKey(name)) {
+                    diff.childNodeDeleted(name, before);
+                }
+            }
+        });
 
         for (Map.Entry<String, ? extends PropertyState> entry : properties.entrySet())
{
             PropertyState before = base.getProperty(entry.getKey());
@@ -348,4 +346,34 @@ public class ModifiedNodeState extends A
         }
     }
 
+    public void compareAgainstBaseState(NodeStateDiff diff) {
+        for (Map.Entry<String, ? extends PropertyState> entry
+                : properties.entrySet()) {
+            PropertyState before = base.getProperty(entry.getKey());
+            PropertyState after = entry.getValue();
+            if (after == null) {
+                diff.propertyDeleted(before);
+            } else if (before == null) {
+                diff.propertyAdded(after);
+            } else if (!before.equals(after)) { // TODO: can we assume this?
+                diff.propertyChanged(before, after);
+            }
+        }
+
+        for (Map.Entry<String, ? extends NodeState> entry : nodes.entrySet()) {
+            String name = entry.getKey();
+            NodeState before = base.getChildNode(name);
+            NodeState after = entry.getValue();
+            if (after == null) {
+                if (before.exists()) { // TODO: can we assume this?
+                    diff.childNodeDeleted(name, before);
+                }
+            } else if (!before.exists()) {
+                diff.childNodeAdded(name, after);
+            } else if (!before.equals(after)) { // TODO: can we assume this?
+                diff.childNodeChanged(name, before, after);
+            }
+        }
+    }
+
 }
\ No newline at end of file



Mime
View raw message