jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1357275 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/test/java/org/apache/jackrabbit/oak/core/ oak-http/src/main/java/org/apache/jackr...
Date Wed, 04 Jul 2012 14:16:24 GMT
Author: mduerig
Date: Wed Jul  4 14:16:23 2012
New Revision: 1357275

URL: http://svn.apache.org/viewvc?rev=1357275&view=rev
Log:
OAK-164: Replace Tree.remove(String) with Tree.remove()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/DefaultConflictHandlerTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java
    jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java Wed
Jul  4 14:16:23 2012
@@ -189,11 +189,10 @@ public interface Tree {
     Tree addChild(String name);
 
     /**
-     * Remove a child with the given {@code name}. Does nothing if no such child exists.
-     * @param name  name of the child to remove
-     * @return  {@code false} iff no such child exists.
+     * Remove this sub tree if not root.
+     * @return  {@code false} iff this is the root.
      */
-    boolean removeChild(String name);
+    boolean remove();
 
     /**
      * Set a single valued property state

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
Wed Jul  4 14:16:23 2012
@@ -44,7 +44,7 @@ public class ReadOnlyTree implements Tre
 
     private ReadOnlyTree(Tree parent, String name, NodeState state) {
         assert name != null;
-        assert name.length() > 0 || parent == null;
+        assert !name.isEmpty() || parent == null;
         assert state != null;
         this.parent = parent;
         this.name = name;
@@ -66,7 +66,7 @@ public class ReadOnlyTree implements Tre
         if (parent == null) {
             return "";
         } else {
-            return parent.getPath() + "/" + name;
+            return parent.getPath() + '/' + name;
         }
     }
 
@@ -167,7 +167,7 @@ public class ReadOnlyTree implements Tre
     }
 
     @Override
-    public boolean removeChild(String name) {
+    public boolean remove() {
         throw new UnsupportedOperationException();
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Wed Jul  4 14:16:23 2012
@@ -469,7 +469,9 @@ public class RootImpl implements Root {
 
                 switch (resolution) {
                     case OURS:
-                        target.removeChild(name);
+                        if (n != null) {
+                            n.remove();
+                        }
                         break;
                     case THEIRS:
                     case MERGED:

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Wed Jul  4 14:16:23 2012
@@ -98,7 +98,6 @@ public class TreeImpl implements Tree, P
     public boolean isRoot() {
         return parent == null;
     }
-
     @Override
     public String getPath() {
         // Shortcut for root
@@ -286,17 +285,8 @@ public class TreeImpl implements Tree, P
     }
 
     @Override
-    public boolean removeChild(String name) {
-        if (hasChild(name)) {
-            NodeStateBuilder builder = getNodeStateBuilder();
-            builder.removeNode(name);
-            children.remove(name);
-            updateParentState(builder.getNodeState());
-            return true;
-    }
-        else {
-            return false;
-        }
+    public boolean remove() {
+        return !isRoot() && parent.removeChild(name);
     }
 
     @Override
@@ -384,6 +374,19 @@ public class TreeImpl implements Tree, P
 
     //------------------------------------------------------------< private >---
 
+    private boolean removeChild(String name) {
+        if (hasChild(name)) {
+            NodeStateBuilder builder = getNodeStateBuilder();
+            builder.removeNode(name);
+            children.remove(name);
+            updateParentState(builder.getNodeState());
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+
     private synchronized NodeStateBuilder getNodeStateBuilder() {
         if (nodeStateBuilder == null) {
             nodeStateBuilder = root.getBuilder(getNodeState());

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/DefaultConflictHandlerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/DefaultConflictHandlerTest.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/DefaultConflictHandlerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/DefaultConflictHandlerTest.java
Wed Jul  4 14:16:23 2012
@@ -116,7 +116,7 @@ public class DefaultConflictHandlerTest 
 
     @Test
     public void testChangeDeletedNodeOurs() throws CommitFailedException {
-        theirRoot.getTree("/").removeChild("x");
+        theirRoot.getTree("/x").remove();
         ourRoot.getTree("/x").setProperty("p", ourValue);
 
         theirRoot.commit(DefaultConflictHandler.OURS);
@@ -130,7 +130,7 @@ public class DefaultConflictHandlerTest 
     @Test
     public void testDeleteChangedNodeOurs() throws CommitFailedException {
         theirRoot.getTree("/x").setProperty("p", theirValue);
-        ourRoot.getTree("/").removeChild("x");
+        ourRoot.getTree("/x").remove();
 
         theirRoot.commit(DefaultConflictHandler.OURS);
         ourRoot.commit(DefaultConflictHandler.OURS);
@@ -205,7 +205,7 @@ public class DefaultConflictHandlerTest 
 
     @Test
     public void testChangeDeletedNodeTheirs() throws CommitFailedException {
-        theirRoot.getTree("/").removeChild("x");
+        theirRoot.getTree("/x").remove();
         ourRoot.getTree("/x").setProperty("p", ourValue);
 
         theirRoot.commit(DefaultConflictHandler.THEIRS);
@@ -218,7 +218,7 @@ public class DefaultConflictHandlerTest 
     @Test
     public void testDeleteChangedNodeTheirs() throws CommitFailedException {
         theirRoot.getTree("/x").setProperty("p", theirValue);
-        ourRoot.getTree("/").removeChild("x");
+        ourRoot.getTree("/").remove();
 
         theirRoot.commit(DefaultConflictHandler.THEIRS);
         ourRoot.commit(DefaultConflictHandler.THEIRS);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java
Wed Jul  4 14:16:23 2012
@@ -166,7 +166,7 @@ public class RootImplFuzzIT {
             void apply(RootImpl root) {
                 String parentPath = PathUtils.getParentPath(path);
                 String name = PathUtils.getName(path);
-                root.getTree(parentPath).removeChild(name);
+                root.getTree(parentPath).getChild(name).remove();
             }
 
             @Override

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java
Wed Jul  4 14:16:23 2012
@@ -161,7 +161,7 @@ public class RootImplTest extends Abstra
         Tree tree = root.getTree("/");
 
         assertTrue(tree.hasChild("x"));
-        tree.removeChild("x");
+        tree.getChild("x").remove();
         assertFalse(tree.hasChild("x"));
 
         root.commit(DefaultConflictHandler.OURS);
@@ -310,7 +310,7 @@ public class RootImplTest extends Abstra
 
         assertEquals(3, tree.getChildrenCount());
 
-        tree.removeChild("x");
+        tree.getChild("x").remove();
         assertEquals(2, tree.getChildrenCount());
 
         tree.addChild("a");
@@ -375,7 +375,7 @@ public class RootImplTest extends Abstra
 
         tree = root.getTree("/");
         assertEquals(Status.EXISTING, tree.getChildStatus("new"));
-        tree.getChild("new").removeChild("another");
+        tree.getChild("new").getChild("another").remove();
         assertEquals(Status.MODIFIED, tree.getChildStatus("new"));
         assertEquals(Status.REMOVED, tree.getChild("new").getChildStatus("another"));
         root.commit(DefaultConflictHandler.OURS);
@@ -442,7 +442,7 @@ public class RootImplTest extends Abstra
         checkEqual(root1.getTree("/"), (root2.getTree("/")));
 
         Tree one = root2.getTree("/one");
-        one.removeChild("two");
+        one.getChild("two").remove();
         one.addChild("four");
         root2.commit(DefaultConflictHandler.OURS);
 

Modified: jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
(original)
+++ jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
Wed Jul  4 14:16:23 2012
@@ -31,6 +31,11 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.smile.SmileFactory;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
@@ -42,13 +47,6 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryValueFactory;
 
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.smile.SmileFactory;
-
 public class OakServlet extends HttpServlet {
 
     private static final JsonFactory JSON_FACTORY = new JsonFactory();
@@ -112,7 +110,7 @@ public class OakServlet extends HttpServ
         }
     }
 
-    private void post(JsonNode node, Tree tree) {
+    private static void post(JsonNode node, Tree tree) {
         Iterator<Entry<String, JsonNode>> iterator = node.fields();
         while (iterator.hasNext()) {
             Entry<String, JsonNode> entry = iterator.next();
@@ -128,8 +126,9 @@ public class OakServlet extends HttpServ
                 }
                 post(value, child);
             } else {
-                if (tree.hasChild(name)) {
-                    tree.removeChild(name);
+                Tree child = tree.getChild(name);
+                if (child != null) {
+                    child.remove();
                 }
                 CoreValueFactory vf = MemoryValueFactory.INSTANCE;
                 if (value.isNull()) {
@@ -158,7 +157,10 @@ public class OakServlet extends HttpServ
             Tree tree = (Tree) request.getAttribute("tree");
             Tree parent = tree.getParent();
             if (parent != null) {
-                parent.removeChild(tree.getName());
+                Tree child = parent.getChild(tree.getName());
+                if (child != null) {
+                    child.remove();
+                }
                 root.commit(DefaultConflictHandler.OURS);
                 response.sendError(HttpServletResponse.SC_OK);
             } else {
@@ -170,7 +172,7 @@ public class OakServlet extends HttpServ
         }
     }
 
-    private int getDepth(HttpServletRequest request) {
+    private static int getDepth(HttpServletRequest request) {
         String d = request.getParameter("depth");
         if (d == null) {
             d = request.getParameter("d");
@@ -185,7 +187,7 @@ public class OakServlet extends HttpServ
         return 1;
     }
 
-    private JsonGenerator getRenderer(
+    private static JsonGenerator getRenderer(
             HttpServletRequest request, HttpServletResponse response)
             throws IOException {
         AcceptHeader accept = new AcceptHeader(request.getHeader("Accept"));
@@ -201,8 +203,8 @@ public class OakServlet extends HttpServ
         }
     }
 
-    private void render(Tree tree, int depth, JsonGenerator generator)
-            throws JsonGenerationException, IOException {
+    private static void render(Tree tree, int depth, JsonGenerator generator)
+            throws IOException {
         generator.writeStartObject();
         if (depth > 0) {
             for (PropertyState property : tree.getProperties()) {
@@ -217,8 +219,8 @@ public class OakServlet extends HttpServ
         generator.close();
     }
 
-    private void render(PropertyState property, JsonGenerator generator)
-            throws JsonGenerationException, IOException {
+    private static void render(PropertyState property, JsonGenerator generator)
+            throws IOException {
         generator.writeFieldName(property.getName());
         if (property.isArray()) {
             generator.writeStartArray();
@@ -231,8 +233,8 @@ public class OakServlet extends HttpServ
         }
     }
 
-    private void render(CoreValue value, JsonGenerator generator)
-            throws JsonGenerationException, IOException {
+    private static void render(CoreValue value, JsonGenerator generator)
+            throws IOException {
         // TODO: Type info?
         if (value.getType() == PropertyType.BOOLEAN) {
             generator.writeBoolean(value.getBoolean());

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java?rev=1357275&r1=1357274&r2=1357275&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
Wed Jul  4 14:16:23 2012
@@ -220,10 +220,7 @@ public class NodeDelegate extends ItemDe
      * Remove the node if not root. Does nothing otherwise
      */
     public void remove() throws InvalidItemStateException {
-        Tree parentTree = getParentTree();
-        if (parentTree != null) {
-            parentTree.removeChild(getName());
-        }
+        getTree().remove();
     }
 
     // -----------------------------------------------------------< private >---



Mime
View raw message