jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1477671 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins: memory/ModifiedNodeState.java memory/MutableNodeState.java segment/SegmentWriter.java
Date Tue, 30 Apr 2013 14:44:30 GMT
Author: jukka
Date: Tue Apr 30 14:44:30 2013
New Revision: 1477671

URL: http://svn.apache.org/r1477671
Log:
OAK-781: Clarify / fix effects of MISSING_NODE as base state of NodeBuilder

Simplify MutableNodeState.snapshot() by moving the related logic to the ModifedNodeState constructor.
No more need for ModifiedNodeState.collapse() as we take care of the unwrapping already in
MutableNodeState.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.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=1477671&r1=1477670&r2=1477671&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
Tue Apr 30 14:44:30 2013
@@ -44,7 +44,6 @@ import org.apache.jackrabbit.oak.spi.sta
 
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
-import com.google.common.collect.Maps;
 
 /**
  * Immutable snapshot of a mutable node state.
@@ -141,34 +140,6 @@ public class ModifiedNodeState extends A
                     filterValues(nodes, notNull()).keySet());
         }
     }
-    static NodeState with(
-            NodeState base,
-            Map<String, PropertyState> properties,
-            Map<String, ? extends NodeState> nodes) {
-        if (properties.isEmpty() && nodes.isEmpty()) {
-            return base;
-        } else {
-            // TODO: Do we need collapse() here? See OAK-778
-            return collapse(new ModifiedNodeState(base, properties, nodes));
-        }
-    }
-
-    public static ModifiedNodeState collapse(ModifiedNodeState state) {
-        NodeState base = state.getBaseState();
-        if (base instanceof ModifiedNodeState) {
-            ModifiedNodeState mbase = collapse((ModifiedNodeState) base);
-
-            Map<String, PropertyState> properties = Maps.newHashMap(mbase.properties);
-            properties.putAll(state.properties);
-
-            Map<String, NodeState> nodes = Maps.newHashMap(mbase.nodes);
-            nodes.putAll(state.nodes);
-
-            return new ModifiedNodeState(mbase.getBaseState(), properties, nodes);
-        } else {
-            return state;
-        }
-    }
 
     /**
      * The base state.
@@ -185,7 +156,7 @@ public class ModifiedNodeState extends A
      * Set of added, modified or removed ({@code null} value)
      * child nodes.
      */
-    private final Map<String, ? extends NodeState> nodes;
+    private final Map<String, NodeState> nodes;
 
     private final Predicate<ChildNodeEntry> unmodifiedNodes = new Predicate<ChildNodeEntry>()
{
         @Override
@@ -201,13 +172,23 @@ public class ModifiedNodeState extends A
         }
     };
 
-    private ModifiedNodeState(
+    ModifiedNodeState(
             @Nonnull NodeState base,
             @Nonnull Map<String, PropertyState> properties,
-            @Nonnull Map<String, ? extends NodeState> nodes) {
+            @Nonnull Map<String, MutableNodeState> nodes) {
         this.base = checkNotNull(base);
-        this.properties = checkNotNull(properties);
-        this.nodes = checkNotNull(nodes);
+        this.properties = newHashMap(checkNotNull(properties));
+        this.nodes = newHashMap();
+        for (Entry<String, MutableNodeState> entry
+                : checkNotNull(nodes).entrySet()) {
+            String name = entry.getKey();
+            MutableNodeState child = entry.getValue();
+            if (child != null) {
+                this.nodes.put(name, child.snapshot());
+            } else {
+                this.nodes.put(name, null);
+            }
+        }
     }
 
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java?rev=1477671&r1=1477670&r2=1477671&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
Tue Apr 30 14:44:30 2013
@@ -23,7 +23,6 @@ import static com.google.common.base.Pre
 import static com.google.common.collect.Maps.newHashMap;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
-import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.with;
 
 import java.util.Iterator;
 import java.util.Map;
@@ -114,24 +113,11 @@ class MutableNodeState extends AbstractN
 
     NodeState snapshot() {
         assert base != null;
-
-        Map<String, NodeState> nodes = newHashMap();
-        for (Map.Entry<String, MutableNodeState> entry : this.nodes.entrySet()) {
-            String name = entry.getKey();
-            MutableNodeState node = entry.getValue();
-            NodeState before = base.getChildNode(name);
-            if (node == null) {
-                if (before.exists()) {
-                    nodes.put(name, null);
-                }
-            } else {
-                NodeState after = node.snapshot();
-                if (after != before) {
-                    nodes.put(name, after);
-                }
-            }
+        if (properties.isEmpty() && nodes.isEmpty()) {
+            return base;
+        } else {
+            return new ModifiedNodeState(base, properties, nodes);
         }
-        return with(base, newHashMap(this.properties), nodes);
     }
 
     private void reset(NodeState newBase) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java?rev=1477671&r1=1477670&r2=1477671&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
Tue Apr 30 14:44:30 2013
@@ -634,7 +634,7 @@ public class SegmentWriter {
         SegmentNodeState before = null;
         ModifiedNodeState after = null;
         if (state instanceof ModifiedNodeState) {
-            after = ModifiedNodeState.collapse((ModifiedNodeState) state);
+            after = (ModifiedNodeState) state;
             NodeState base = after.getBaseState();
             if (base instanceof SegmentNodeState) {
                 before = (SegmentNodeState) base;



Mime
View raw message