jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1330845 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core: RootImpl.java TreeImpl.java
Date Thu, 26 Apr 2012 13:35:13 GMT
Author: mduerig
Date: Thu Apr 26 13:35:13 2012
New Revision: 1330845

URL: http://svn.apache.org/viewvc?rev=1330845&view=rev
Log:
OAK-18: Define Oak API
javadoc, minor cleanup

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

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=1330845&r1=1330844&r2=1330845&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
Thu Apr 26 13:35:13 2012
@@ -37,25 +37,32 @@ import static org.apache.jackrabbit.mk.u
  * This {@code Root} implementation listens on the root of the underlying
  * {@link Tree} using a {@link Listener}. All changes are directly applied
  * to the {@link NodeStateBuilder} for the relevant sub-tree.
- *
- * TODO: Refactor tree to be based on the individual NodeStateBuilders instead of NodeStates
  */
 public class RootImpl implements Root {
 
+    /** The underlying store to which this root belongs */
     private final NodeStore store;
+
+    /** The name of the workspace we are operating on */
     private final String workspaceName;
 
+    /** Listener for changes on the content tree */
+    private TreeListener treeListener = new TreeListener();
+
     /** Base node state of this tree */
     private NodeState base;
 
+    /** The builder for this root */
+    private NodeStateBuilder nodeStateBuilder;
+
     /** Root state of this tree */
     private TreeImpl root;
 
-    /** Listener for changes on the content tree */
-    private TreeListener treeListener = new TreeListener();
-
-    private NodeStateBuilder nodeStateBuilder;
-
+    /**
+     * New instance bases on a given {@link NodeStore} and a workspace
+     * @param store  node store
+     * @param workspaceName  name of the workspace
+     */
     public RootImpl(NodeStore store, String workspaceName) {
         this.store = store;
         this.workspaceName = workspaceName;
@@ -103,9 +110,9 @@ public class RootImpl implements Root {
     @Override
     public void commit() throws CommitFailedException {
         store.apply(nodeStateBuilder);
+        treeListener = new TreeListener();
         base = store.getRoot().getChildNode(workspaceName);
         nodeStateBuilder = store.getBuilder(base);
-        treeListener = new TreeListener();
         root = new TreeImpl(store, nodeStateBuilder, treeListener);
     }
 

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=1330845&r1=1330844&r2=1330845&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 Apr 26 13:35:13 2012
@@ -35,8 +35,14 @@ import java.util.List;
 
 import static org.apache.jackrabbit.oak.util.Iterators.flatten;
 
+/**
+ * Implementation of tree based on {@link NodeStateBuilder}s. Each subtree
+ * has an associated node state builder which is used for building the new
+ * trees resulting from calling mutating methods.
+ */
 public class TreeImpl implements Tree {
 
+    /** Underlying store */
     private final NodeStore store;
 
     /**
@@ -66,7 +72,14 @@ public class TreeImpl implements Tree {
         this.name = name;
         this.parent = parent;
     }
-    
+
+    /**
+     * Create a new instance which represents the root of a tree.
+     * @param store  underlying store to the tree
+     * @param nodeStateBuilder  builder for the root
+     * @param listener  change listener for the tree. May be {@code null} if
+     *                  listening to changes is not needed.
+     */
     TreeImpl(NodeStore store, NodeStateBuilder nodeStateBuilder, Listener listener) {
         this(store, nodeStateBuilder.getNodeState(), nodeStateBuilder, null, "", listener);
     }
@@ -161,34 +174,45 @@ public class TreeImpl implements Tree {
     @Override
     public Status getPropertyStatus(String name) {
         if (baseState == null) {
+            // This instance is NEW...
             if (hasProperty(name)) {
+                // ...so all children are new
                 return Status.NEW;
             }
             else {
+                // ...unless they don't exist.
                 return null;
             }
         }
         else {
             if (hasProperty(name)) {
+                // We have the property...
                 if (baseState.getProperty(name) == null) {
+                    // ...but didn't have it before. So its NEW.
                     return Status.NEW;
                 }
                 else {
+                    // ... and did have it before. So...
                     PropertyState base = baseState.getProperty(name);
                     PropertyState head = getProperty(name);
                     if (base.equals(head)) {
+                        // ...it's EXISTING if it hasn't changed
                         return Status.EXISTING;
                     }
                     else {
+                        // ...and MODIFIED otherwise.
                         return Status.MODIFIED;
                     }
                 }
             }
             else {
+                // We don't have the property
                 if (baseState.getProperty(name) == null) {
+                    // ...and didn't have it before. So it doesn't exist.
                     return null;
                 }
                 else {
+                    // ...and didn't have it before. So it's REMOVED
                     return Status.REMOVED;
                 }
             }
@@ -225,32 +249,43 @@ public class TreeImpl implements Tree {
     @Override
     public Status getChildStatus(String name) {
         if (baseState == null) {
+            // This instance is NEW...
             if (hasChild(name)) {
+                // ...so all children are new
                 return Status.NEW;
             }
             else {
+                // ...unless they don't exist.
                 return null;
             }
         }
         else {
             if (hasChild(name)) {
+                // We have the child...
                 if (baseState.getChildNode(name) == null) {
+                    // ...but didn't have it before. So its NEW.
                     return Status.NEW;
                 }
                 else {
+                    // ... and did have it before. So...
                     if (isSame(baseState.getChildNode(name), getNodeState().getChildNode(name)))
{
+                        // ...it's EXISTING if it hasn't changed
                         return Status.EXISTING;
                     }
                     else {
+                        // ...and MODIFIED otherwise.
                         return Status.MODIFIED;
                     }
                 }
             }
             else {
+                // We don't have the child
                 if (baseState.getChildNode(name) == null) {
+                    // ...and didn't have it before. So it doesn't exist.
                     return null;
                 }
                 else {
+                    // ...and didn't have it before. So it's REMOVED
                     return Status.REMOVED;
                 }
             }



Mime
View raw message