jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1435263 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core: AbstractNodeLocation.java AbstractPropertyLocation.java ReadOnlyTree.java TreeImpl.java
Date Fri, 18 Jan 2013 17:36:58 GMT
Author: angela
Date: Fri Jan 18 17:36:58 2013
New Revision: 1435263

URL: http://svn.apache.org/viewvc?rev=1435263&view=rev
Log:
OAK-568 : Duplicated code in TreeLocation implementations

Added:
    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
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

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java?rev=1435263&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
Fri Jan 18 17:36:58 2013
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.TreeLocation;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * AbstractNodeLocation... TODO
+ */
+abstract class AbstractNodeLocation<T extends Tree> implements TreeLocation {
+
+    protected final T tree;
+
+    AbstractNodeLocation(T tree) {
+        this.tree = checkNotNull(tree);
+    }
+
+    @Override
+    public String getPath() {
+        return tree.getPath();
+    }
+
+    @Override
+    public PropertyState getProperty() {
+        return null;
+    }
+
+    @Override
+    public Tree.Status getStatus() {
+        return tree.getStatus();
+    }
+}
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java?rev=1435263&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
Fri Jan 18 17:36:58 2013
@@ -0,0 +1,57 @@
+/*
+ * 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 org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.TreeLocation;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * AbstractPropertyLocation... TODO
+ */
+abstract class AbstractPropertyLocation<L extends AbstractNodeLocation> implements
TreeLocation {
+
+    protected final L parentLocation;
+    protected final String name;
+
+    AbstractPropertyLocation(L parentLocation, String name) {
+        this.parentLocation = checkNotNull(parentLocation);
+        this.name = checkNotNull(name);
+    }
+
+    @Override
+    public L getParent() {
+        return parentLocation;
+    }
+
+    @Override
+    public TreeLocation getChild(String relPath) {
+        return TreeLocation.NULL;
+    }
+
+    @Override
+    public String getPath() {
+        return PathUtils.concat(parentLocation.getPath(), name);
+    }
+
+    @Override
+    public Tree getTree() {
+        return null;
+    }
+}
\ No newline at end of file

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=1435263&r1=1435262&r2=1435263&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
Fri Jan 18 17:36:58 2013
@@ -218,11 +218,10 @@ public class ReadOnlyTree implements Tre
 
     //-------------------------------------------------------< TreeLocation >---
 
-    private class NodeLocation implements TreeLocation {
-        private final ReadOnlyTree tree;
+    private class NodeLocation extends AbstractNodeLocation<ReadOnlyTree> {
 
         private NodeLocation(ReadOnlyTree tree) {
-            this.tree = checkNotNull(tree);
+            super(tree);
         }
 
         @Override
@@ -261,11 +260,6 @@ public class ReadOnlyTree implements Tre
         }
 
         @Override
-        public String getPath() {
-            return tree.getPath();
-        }
-
-        @Override
         public boolean remove() {
             return false;
         }
@@ -276,38 +270,15 @@ public class ReadOnlyTree implements Tre
         }
 
         @Override
-        public PropertyState getProperty() {
-            return null;
-        }
-
-        @Override
         public Status getStatus() {
             return tree.getStatus();
         }
     }
 
-    private class PropertyLocation implements TreeLocation {
-        private final NodeLocation parent;
-        private final String name;
-
-        private PropertyLocation(NodeLocation parent, String name) {
-            this.parent = checkNotNull(parent);
-            this.name = checkNotNull(name);
-        }
+    private class PropertyLocation extends AbstractPropertyLocation<NodeLocation> {
 
-        @Override
-        public TreeLocation getParent() {
-            return parent;
-        }
-
-        @Override
-        public TreeLocation getChild(String relPath) {
-            return TreeLocation.NULL;
-        }
-
-        @Override
-        public String getPath() {
-            return PathUtils.concat(parent.getPath(), name);
+        private PropertyLocation(NodeLocation parentLocation, String name) {
+            super(parentLocation, name);
         }
 
         @Override
@@ -316,13 +287,8 @@ public class ReadOnlyTree implements Tre
         }
 
         @Override
-        public Tree getTree() {
-            return null;
-        }
-
-        @Override
         public PropertyState getProperty() {
-            return parent.tree.getProperty(name);
+            return parentLocation.tree.getProperty(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=1435263&r1=1435262&r2=1435263&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
Fri Jan 18 17:36:58 2013
@@ -574,11 +574,10 @@ public class TreeImpl implements Tree {
 
     //-------------------------------------------------------< TreeLocation >---
 
-    public class NodeLocation implements TreeLocation {
-        private final TreeImpl tree;
+    public class NodeLocation extends AbstractNodeLocation<TreeImpl> {
 
         private NodeLocation(TreeImpl tree) {
-            this.tree = checkNotNull(tree);
+            super(tree);
         }
 
         @Override
@@ -618,11 +617,6 @@ public class TreeImpl implements Tree {
         }
 
         @Override
-        public String getPath() {
-            return tree.getPath();
-        }
-
-        @Override
         public boolean remove() {
             return tree.remove();
         }
@@ -631,50 +625,17 @@ public class TreeImpl implements Tree {
         public Tree getTree() {
             return canRead(tree) ? tree : null;
         }
-
-        @Override
-        public PropertyState getProperty() {
-            return null;
-        }
-
-        @Override
-        public Status getStatus() {
-            return tree.getStatus();
-        }
     }
 
-    public class PropertyLocation implements TreeLocation {
-        private final NodeLocation parent;
-        private final String name;
-
-        private PropertyLocation(NodeLocation parent, String name) {
-            this.parent = checkNotNull(parent);
-            this.name = checkNotNull(name);
-        }
+    public class PropertyLocation extends AbstractPropertyLocation<NodeLocation> {
 
-        @Override
-        public TreeLocation getParent() {
-            return parent;
-        }
-
-        @Override
-        public TreeLocation getChild(String relPath) {
-            return TreeLocation.NULL;
-        }
-
-        @Override
-        public String getPath() {
-            return PathUtils.concat(parent.getPath(), name);
-        }
-
-        @Override
-        public Tree getTree() {
-            return null;
+        private PropertyLocation(NodeLocation parentLocation, String name) {
+            super(parentLocation, name);
         }
 
         @Override
         public PropertyState getProperty() {
-            PropertyState property = parent.tree.internalGetProperty(name);
+            PropertyState property = parentLocation.tree.internalGetProperty(name);
             return canRead(property)
                 ? property
                 : null;
@@ -682,7 +643,7 @@ public class TreeImpl implements Tree {
 
         @Override
         public Status getStatus() {
-            return parent.tree.getPropertyStatus(name);
+            return parentLocation.tree.getPropertyStatus(name);
         }
 
         /**
@@ -690,7 +651,7 @@ public class TreeImpl implements Tree {
          * @param property The property to set
          */
         public <T> void set(PropertyState property) {
-            parent.tree.setProperty(property);
+            parentLocation.tree.setProperty(property);
         }
 
         /**
@@ -699,7 +660,7 @@ public class TreeImpl implements Tree {
          */
         @Override
         public boolean remove() {
-            parent.tree.removeProperty(name);
+            parentLocation.tree.removeProperty(name);
             return true;
         }
     }



Mime
View raw message