jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1478402 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/api/ main/java/org/apache/jackrabbit/oak/core/ test/java/org/apache/jackrabbit/oak/core/
Date Thu, 02 May 2013 15:05:25 GMT
Author: mduerig
Date: Thu May  2 15:05:24 2013
New Revision: 1478402

URL: http://svn.apache.org/r1478402
Log:
OAK-798: Review / refactor TreeImpl and related classes
- Replace the various TreeLocation implementation with a consolidated one
- Remove unused methods from TreeLocation

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeLocations.java
  (with props)
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTreeLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/NullLocation.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.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/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java?rev=1478402&r1=1478401&r2=1478402&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
Thu May  2 15:05:24 2013
@@ -21,8 +21,6 @@ package org.apache.jackrabbit.oak.api;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.oak.api.Tree.Status;
-
 /**
  * A {@code TreeLocation} denotes a location inside a tree.
  * It can either refer to a inner node (that is a {@link org.apache.jackrabbit.oak.api.Tree}),
@@ -78,14 +76,6 @@ public interface TreeLocation {
     PropertyState getProperty();
 
     /**
-     * Get the {@link org.apache.jackrabbit.oak.api.Tree.Status} of the underlying item for
this
-     * {@code TreeLocation}.
-     * @return  underlying status or {@code null} if not available.
-     */
-    @CheckForNull
-    Status getStatus();
-
-    /**
      * The path of this location
      * @return  path
      */
@@ -98,13 +88,4 @@ public interface TreeLocation {
      * @return {@code true} if the item was removed, {@code false} otherwise.
      */
     boolean remove();
-
-    /**
-     * Set the underlying property of this {@code TreeLocation}. If the underlying item is
-     * not a property, this method return {@code false}.
-     * @param property The property to set
-     * @return {@code true} if the property state was set, {@code false} otherwise.
-     */
-    boolean set(PropertyState property);
-
 }

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=1478402&r1=1478401&r2=1478402&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 May  2 15:05:24 2013
@@ -149,7 +149,7 @@ public class ReadOnlyTree implements Tre
     @Override
     @Deprecated
     public TreeLocation getLocation() {
-        return new NodeLocation(this);
+        return TreeLocations.create(this);
     }
 
     @Override
@@ -258,72 +258,4 @@ public class ReadOnlyTree implements Tre
             return PathUtils.concat(parent.getIdentifier(), name);
         }
     }
-
-    //-------------------------------------------------------< TreeLocation >---
-
-    @Deprecated
-    private final class NodeLocation extends AbstractNodeLocation<ReadOnlyTree> {
-
-        private NodeLocation(ReadOnlyTree tree) {
-            super(tree);
-        }
-
-        @Override
-        protected TreeLocation createNodeLocation(ReadOnlyTree tree) {
-            return new NodeLocation(tree);
-        }
-
-        @Override
-        protected TreeLocation createPropertyLocation(AbstractNodeLocation<ReadOnlyTree>
parentLocation, String name) {
-            return new PropertyLocation(parentLocation, name);
-        }
-
-        @Override
-        protected ReadOnlyTree getParentTree() {
-            return tree.parent;
-        }
-
-        @Override
-        protected ReadOnlyTree getChildTree(String name) {
-            return tree.getChild(name);
-        }
-
-        @Override
-        protected PropertyState getPropertyState(String name) {
-            return tree.getProperty(name);
-        }
-
-        @Override
-        public Tree getTree() {
-            return tree;
-        }
-
-        @Override
-        public boolean remove() {
-            return false;
-        }
-    }
-
-    @Deprecated
-    private final class PropertyLocation extends AbstractPropertyLocation<ReadOnlyTree>
{
-
-        private PropertyLocation(AbstractNodeLocation<ReadOnlyTree> parentLocation,
String name) {
-            super(parentLocation, name);
-        }
-
-        @Override
-        public PropertyState getProperty() {
-            return parentLocation.tree.getProperty(name);
-        }
-
-        @Override
-        public boolean remove() {
-            return false;
-        }
-
-        @Override
-        public boolean set(PropertyState property) {
-            return false;
-        }
-    }
 }

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=1478402&r1=1478401&r2=1478402&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 May  2 15:05:24 2013
@@ -137,7 +137,7 @@ public class TreeImpl implements Tree {
     @Deprecated
     public TreeLocation getLocation() {
         enter();
-        return new NodeLocation(this);
+        return TreeLocations.create(this);
     }
 
     @Override
@@ -571,60 +571,6 @@ public class TreeImpl implements Tree {
         }
     }
 
-    //-------------------------------------------------------< TreeLocation >---
-
-    @Deprecated
-    private final class NodeLocation extends AbstractNodeLocation<TreeImpl> {
-
-        private NodeLocation(TreeImpl tree) {
-            super(tree);
-        }
-
-        @Override
-        protected NodeLocation createNodeLocation(TreeImpl tree) {
-            return new NodeLocation(tree);
-        }
-
-        @Override
-        protected TreeLocation createPropertyLocation(AbstractNodeLocation<TreeImpl>
parentLocation, String name) {
-            return new PropertyLocation(parentLocation, name);
-        }
-
-        @Override
-        protected TreeImpl getParentTree() {
-            return tree.parent;
-        }
-
-        @Override
-        protected TreeImpl getChildTree(String name) {
-            return new TreeImpl(tree.root, tree, name, tree.pendingMoves);
-        }
-
-        @Override
-        protected PropertyState getPropertyState(String name) {
-            return tree.getVisibleProperty(name);
-        }
-
-        @Override
-        protected boolean canRead(TreeImpl tree) {
-            return tree.nodeBuilder.exists();
-        }
-    }
-
-    @Deprecated
-    private static final class PropertyLocation extends AbstractPropertyLocation<TreeImpl>
{
-
-        private PropertyLocation(AbstractNodeLocation<TreeImpl> parentLocation, String
name) {
-            super(parentLocation, name);
-        }
-
-        @Override
-        protected boolean canRead(PropertyState property) {
-            return !isHidden(property.getName());
-        }
-
-    }
-
 }
 
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeLocations.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeLocations.java?rev=1478402&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeLocations.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeLocations.java
Thu May  2 15:05:24 2013
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.core;
+
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
+import static org.apache.jackrabbit.oak.commons.PathUtils.isAbsolute;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.TreeLocation;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+
+@Deprecated
+public abstract class TreeLocations implements TreeLocation {
+
+    /**
+     * Create a new {@code TreeLocation} instance for a {@code tree}
+     */
+    public static TreeLocation create(Tree tree) {
+        return new NodeLocation(tree);
+    }
+
+    /**
+     * Create a new {@code TreeLocation} instance for the item
+     * at the given {@code path} in {@code root}.
+     */
+    public static TreeLocation create(Root root, String path) {
+        checkArgument(isAbsolute(path));
+        TreeLocation location = create(root.getTree("/"));
+        for (String name : elements(path)) {
+            location = location.getChild(name);
+        }
+        return location;
+    }
+
+    /**
+     * Equivalent to {@code create(root, "/")}
+     */
+    public static TreeLocation create(Root root) {
+        return create(root, "/");
+    }
+
+    @Override
+    public TreeLocation getChild(String name) {
+        return new NullLocation(this, name);
+    }
+
+    /**
+     * @return {@code null}
+     */
+    @Override
+    public Tree getTree() {
+        return null;
+    }
+
+    /**
+     * @return {@code null}
+     */
+    @Override
+    public PropertyState getProperty() {
+        return null;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this).add("path", getPath()).toString();
+    }
+
+    /**
+     * This {@code TreeLocation} refers to child tree in a
+     * {@code Tree}.
+     */
+    private static class NodeLocation extends TreeLocations {
+        private final Tree tree;
+
+        public NodeLocation(Tree tree) {
+            this.tree = tree;
+        }
+
+        @Nonnull
+        @Override
+        public TreeLocation getParent() {
+            return tree.isRoot()
+                ? NullLocation.NULL
+                : new NodeLocation(tree.getParent());
+        }
+
+        @Nonnull
+        @Override
+        public TreeLocation getChild(String name) {
+            if (tree.hasProperty(name)) {
+                return new PropertyLocation(tree, name);
+            } else {
+                return new NodeLocation(tree.getChild(name));
+            }
+        }
+
+        @Override
+        public boolean exists() {
+            return tree.exists();
+        }
+
+        @Override
+        public Tree getTree() {
+            return exists() ? tree : null;
+        }
+
+        @Nonnull
+        @Override
+        public String getPath() {
+            return tree.getPath();
+        }
+
+        @Override
+        public boolean remove() {
+            return exists() && tree.remove();
+        }
+    }
+
+    /**
+     * This {@code TreeLocation} refers to property in a
+     * {@code Tree}.
+     */
+    private static class PropertyLocation extends TreeLocations {
+        private final Tree parent;
+        private final String name;
+
+        public PropertyLocation(Tree parent, String name) {
+            this.parent = parent;
+            this.name = name;
+        }
+
+        @Nonnull
+        @Override
+        public TreeLocation getParent() {
+            return new NodeLocation(parent);
+        }
+
+        @Override
+        public boolean exists() {
+            return parent.hasProperty(name);
+        }
+
+        @Override
+        public PropertyState getProperty() {
+            return parent.getProperty(name);
+        }
+
+        @Nonnull
+        @Override
+        public String getPath() {
+            return PathUtils.concat(parent.getPath(), name);
+        }
+
+        @Override
+        public boolean remove() {
+            parent.removeProperty(name);
+            return true;
+        }
+    }
+
+    /**
+     * This {@code TreeLocation} refers to an invalid location in a tree. That is
+     * to a location where no item resides.
+     */
+    private static final class NullLocation extends TreeLocations {
+        public static final NullLocation NULL = new NullLocation();
+
+        private final TreeLocation parent;
+        private final String name;
+
+        public NullLocation(TreeLocation parent, String name) {
+            this.parent = parent;
+            this.name = name;
+        }
+
+        private NullLocation() {
+            this.parent = this;
+            this.name = "";
+        }
+
+        @Override
+        public TreeLocation getParent() {
+            return parent;
+        }
+
+        /**
+         * @return {@code false}
+         */
+        @Override
+        public boolean exists() {
+            return false;
+        }
+
+        @Override
+        public String getPath() {
+            return parent == this ? "" : PathUtils.concat(parent.getPath(), name);
+        }
+
+        /**
+         * @return Always {@code false}.
+         */
+        @Override
+        public boolean remove() {
+            return false;
+        }
+
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeLocations.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeLocations.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java?rev=1478402&r1=1478401&r2=1478402&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java
Thu May  2 15:05:24 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.jackrabbit.oak.core;
 
-import static org.apache.jackrabbit.oak.core.NullLocation.NULL;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -37,6 +36,7 @@ import org.junit.Test;
 public class TreeLocationTest extends OakBaseTest {
 
     private Root root;
+    private TreeLocation nullLocation;
 
     @Before
     public void setUp() throws CommitFailedException {
@@ -52,6 +52,8 @@ public class TreeLocationTest extends Oa
         tree.addChild("y");
         tree.addChild("z").addChild("1").addChild("2").setProperty("p", "v");
         root.commit();
+
+        nullLocation = root.getLocation("/").getParent();
     }
 
     @After
@@ -61,17 +63,17 @@ public class TreeLocationTest extends Oa
 
     @Test
     public void testNullLocation() {
-        TreeLocation xyz = NULL.getChild("x").getChild("y").getChild("z");
+        TreeLocation xyz = nullLocation.getChild("x").getChild("y").getChild("z");
         Assert.assertEquals("x/y/z", xyz.getPath());
         assertEquals("x/y", xyz.getParent().getPath());
         assertEquals("x", xyz.getParent().getParent().getPath());
-        assertEquals(NULL, xyz.getParent().getParent().getParent());
+        assertEquals(nullLocation, xyz.getParent().getParent().getParent());
     }
 
     @Test
     public void testParentOfRoot() {
         TreeLocation rootLocation = root.getLocation("/");
-        assertEquals(NULL, rootLocation.getParent());
+        assertEquals(nullLocation, rootLocation.getParent());
     }
 
     @Test



Mime
View raw message