jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1373877 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/test/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Thu, 16 Aug 2012 15:10:51 GMT
Author: mduerig
Date: Thu Aug 16 15:10:51 2012
New Revision: 1373877

URL: http://svn.apache.org/viewvc?rev=1373877&view=rev
Log:
OAK-221: Clarify nature of 'path' parameter in oak-api
 Tree.getPath() returns path with leading forward slash

Modified:
    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/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.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/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=1373877&r1=1373876&r2=1373877&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
Thu Aug 16 15:10:51 2012
@@ -30,7 +30,7 @@ import org.apache.jackrabbit.oak.spi.sta
 public class ReadOnlyTree implements Tree {
 
     /** Parent of this tree, {@code null} for the root */
-    private final Tree parent;
+    private final ReadOnlyTree parent;
 
     /** Name of this tree */
     private final String name;
@@ -38,8 +38,6 @@ public class ReadOnlyTree implements Tre
     /** Underlying node state */
     private final NodeState state;
 
-    private final String path;
-
     public ReadOnlyTree(NodeState root) {
         this(null, "", root);
     }
@@ -52,7 +50,6 @@ public class ReadOnlyTree implements Tre
         this.parent = parent;
         this.name = name;
         this.state = state;
-        this.path = (parent == null) ? "" : parent.getPath() + '/' + name;
     }
 
     @Override
@@ -67,7 +64,21 @@ public class ReadOnlyTree implements Tre
 
     @Override
     public String getPath() {
-        return path;
+        if (isRoot()) {
+            // shortcut
+            return "/";
+        }
+
+        StringBuilder sb = new StringBuilder();
+        buildPath(sb);
+        return sb.toString();
+    }
+
+    private void buildPath(StringBuilder sb) {
+        if (!isRoot()) {
+            parent.buildPath(sb);
+            sb.append('/').append(name);
+        }
     }
 
     @Override

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=1373877&r1=1373876&r2=1373877&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
Thu Aug 16 15:10:51 2012
@@ -104,9 +104,9 @@ public class TreeImpl implements Tree, P
 
     @Override
     public String getPath() {
-        // Shortcut for root
-        if (parent == null) {
-            return "";
+        if (isRoot()) {
+            // shortcut
+            return "/";
         }
 
         StringBuilder sb = new StringBuilder();
@@ -430,12 +430,9 @@ public class TreeImpl implements Tree, P
             throw new IllegalStateException("Cannot build the path of a removed tree");
         }
 
-        if (parent != null) {
+        if (!isRoot()) {
             parent.buildPath(sb);
-            if (sb.length() > 0) {
-                sb.append('/');
-            }
-            sb.append(name);
+            sb.append('/').append(name);
         }
     }
 

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=1373877&r1=1373876&r2=1373877&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
Thu Aug 16 15:10:51 2012
@@ -49,13 +49,11 @@ public class RootImplTest extends Abstra
         RootImpl root = createRootImpl(null);
 
         List<String> validPaths = new ArrayList<String>();
-        validPaths.add("");
-        validPaths.add("x");
-        validPaths.add("x/xx");
-        validPaths.add("y");
-        validPaths.add("z");
-        //validPaths.add("/");  FIXME: see OAK-221
-        //validPaths.add("/x"); FIXME: see OAK-221
+        validPaths.add("/");
+        validPaths.add("/x");
+        validPaths.add("/x/xx");
+        validPaths.add("/y");
+        validPaths.add("/z");
 
         for (String treePath : validPaths) {
             Tree tree = root.getTree(treePath);
@@ -64,10 +62,8 @@ public class RootImplTest extends Abstra
         }
 
         List<String> invalidPaths = new ArrayList<String>();
-        invalidPaths.add("any");
-        invalidPaths.add("x/any");
-        //invalidPaths.add("/");      FIXME: see OAK-221
-        //invalidPaths.add("/x/xx");  FIXME: see OAK-221
+        invalidPaths.add("/any");
+        invalidPaths.add("/x/any");
 
         for (String treePath : invalidPaths) {
             assertNull(root.getTree(treePath));

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java?rev=1373877&r1=1373876&r2=1373877&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
Thu Aug 16 15:10:51 2012
@@ -85,7 +85,7 @@ public class TreeImplTest extends Abstra
         Iterable<Tree> children = tree.getChildren();
 
         Set<String> expectedPaths = new HashSet<String>();
-        Collections.addAll(expectedPaths, "x", "y", "z");
+        Collections.addAll(expectedPaths, "/x", "/y", "/z");
 
         for (Tree child : children) {
             assertTrue(expectedPaths.remove(child.getPath()));

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=1373877&r1=1373876&r2=1373877&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
Thu Aug 16 15:10:51 2012
@@ -30,7 +30,9 @@ import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.ItemNotFoundException;
 
-import org.apache.jackrabbit.JcrConstants;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -38,10 +40,6 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-
 /**
  * {@code NodeDelegate} serve as internal representations of {@code Node}s.
  * Most methods of this class throw an {@code InvalidItemStateException}
@@ -69,7 +67,7 @@ public class NodeDelegate extends ItemDe
 
     @Override
     public String getPath() throws InvalidItemStateException {
-        return '/' + getTree().getPath();
+        return getTree().getPath();
     }
 
     @Override



Mime
View raw message