jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1504057 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: SegmentNodeState.java Template.java
Date Wed, 17 Jul 2013 08:56:59 GMT
Author: jukka
Date: Wed Jul 17 08:56:59 2013
New Revision: 1504057

URL: http://svn.apache.org/r1504057
Log:
OAK-630: SegmentMK: Implement compareAgainstBaseState

Avoid the AbstractNodeState.equals() fallback when comparing two SegmentNodeStates

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java?rev=1504057&r1=1504056&r2=1504057&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
Wed Jul 17 08:56:59 2013
@@ -145,21 +145,21 @@ public class SegmentNodeState extends Ab
         }
     }
 
+    @Override
     public boolean equals(Object object) {
         if (this == object) {
             return true;
-        } else if (object instanceof NodeState) {
-            if (object instanceof SegmentNodeState) {
-                SegmentNodeState that = (SegmentNodeState) object;
-                if (recordId.equals(that.recordId)) {
-                    return true;
-                } else if (!getTemplate().equals(that.getTemplate())) {
-                    return false;
-                }
+        } else if (object instanceof SegmentNodeState) {
+            SegmentNodeState that = (SegmentNodeState) object;
+            if (recordId.equals(that.recordId)) {
+                return true;
+            } else {
+                Template template = getTemplate();
+                return template.equals(that.getTemplate())
+                        && template.compare(store, recordId, that.recordId);
             }
-            return super.equals(object);
         } else {
-            return false;
+            return super.equals(object);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java?rev=1504057&r1=1504056&r2=1504057&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
Wed Jul 17 08:56:59 2013
@@ -346,6 +346,54 @@ public class Template {
         }
     }
 
+    public boolean compare(
+            SegmentStore store, RecordId thisId, RecordId thatId) {
+        checkNotNull(thisId);
+        checkNotNull(thatId);
+
+        // Compare properties
+        for (int i = 0; i < properties.length; i++) {
+            PropertyState thisProperty = getProperty(store, thisId, i);
+            PropertyState thatProperty = getProperty(store, thatId, i);
+            if (!thisProperty.equals(thatProperty)) {
+                return false;
+            }
+        }
+
+        // Compare child nodes
+        if (hasNoChildNodes()) {
+            return true;
+        } else if (hasOneChildNode()) {
+            NodeState thisChild = getChildNode(childName, store, thisId);
+            NodeState thatChild = getChildNode(childName, store, thatId);
+            return thisChild.equals(thatChild);
+        } else {
+            // TODO: Leverage the HAMT data structure for the comparison
+            MapRecord thisMap = getChildNodeMap(store, thisId);
+            MapRecord thatMap = getChildNodeMap(store, thatId);
+            if (thisMap.getRecordId().equals(thatMap.getRecordId())) {
+                return true; // shortcut
+            } else if (thisMap.size() != thatMap.size()) {
+                return false; // shortcut
+            } else {
+                // TODO: can this be optimized?
+                for (MapEntry entry : thisMap.getEntries()) {
+                    String name = entry.getName();
+                    RecordId thisChild = entry.getValue();
+                    RecordId thatChild = thatMap.getEntry(name);
+                    if (thatChild == null) {
+                        return false;
+                    } else if (!thisChild.equals(thatChild)
+                            && !new SegmentNodeState(store, thisChild).equals(
+                                    new SegmentNodeState(store, thatChild))) {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        }
+    }
+
     public boolean compareAgainstBaseState(
             SegmentStore store, RecordId afterId,
             Template beforeTemplate, RecordId beforeId,



Mime
View raw message