jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1235368 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model: ChildNodeEntriesTree.java ChildNodeEntry.java
Date Tue, 24 Jan 2012 17:34:12 GMT
Author: stefan
Date: Tue Jan 24 17:34:11 2012
New Revision: 1235368

URL: http://svn.apache.org/viewvc?rev=1235368&view=rev
Log:
flat hierarchy support (WIP)

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntry.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java?rev=1235368&r1=1235367&r2=1235368&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
Tue Jan 24 17:34:11 2012
@@ -20,6 +20,7 @@ import org.apache.jackrabbit.mk.util.Abs
 import org.apache.jackrabbit.mk.util.EmptyIterator;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
 
 /**
@@ -31,6 +32,7 @@ public class ChildNodeEntriesTree implem
 
     protected int count;
 
+    // array of *immutable* IndexEntry objects
     protected IndexEntry[] index = new IndexEntry[1024];  // 2^10
 
     ChildNodeEntriesTree() {
@@ -40,8 +42,14 @@ public class ChildNodeEntriesTree implem
 
     @Override
     public boolean equals(Object obj) {
-        // todo implement
-        return super.equals(obj);
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof ChildNodeEntriesTree) {
+            ChildNodeEntriesTree other = (ChildNodeEntriesTree) obj;
+            return Arrays.equals(index, other.index);
+        }
+        return false;
     }
 
     @Override
@@ -52,7 +60,8 @@ public class ChildNodeEntriesTree implem
         } catch (CloneNotSupportedException e) {
             // can't possibly get here
         }
-        // todo properly initialize all fields
+        // shallow clone of array of immutable IndexEntry objects
+        clone.index = index.clone();
         return clone;
     }
 
@@ -159,24 +168,29 @@ public class ChildNodeEntriesTree implem
                 ChildNodeEntriesBucket bucket = new ChildNodeEntriesBucket();
                 bucket.add(existing);
                 bucket.add(entry);
-                BucketInfo bi = new BucketInfo();
-                bi.size = 2;
                 // todo store bucket and update index entry with new bucket id (content hash)
-                //bi.id = <content hash of bucket>;
-                index[idx] = bi;
+                //bucketId = <content hash of bucket>;
+                String bucketId = "";
+                index[idx] = new BucketInfo(bucketId, 2);
                 count++;
                 return null;
             }
         } else {
             BucketInfo bi = (BucketInfo) ie;
-            ChildNodeEntries entries = retrieveBucket(bi.id);
+            ChildNodeEntries entries = retrieveBucket(bi.getId());
             ChildNodeEntry existing = entries.add(entry);
+            if (entry.equals(existing)) {
+                // no-op
+                return existing;
+            }
+            // todo store bucket and update index entry with new bucket id (content hash)
+            //bucketId = <content hash of bucket>;
+            String bucketId = "";
             if (existing == null) {
+                // new entry
                 count++;
-                bi.size++;
+                index[idx] = new BucketInfo(bucketId, entries.getCount());;
             }
-            // todo store bucket and update index entry with new bucket id (content hash)
-            //bi.id = <content hash of bucket>;
             return existing;
         }
     }
@@ -198,17 +212,22 @@ public class ChildNodeEntriesTree implem
             }
         } else {
             BucketInfo bi = (BucketInfo) ie;
-            ChildNodeEntries entries = retrieveBucket(bi.id);
+            ChildNodeEntries entries = retrieveBucket(bi.getId());
             ChildNodeEntry existing = entries.remove(name);
             if (existing == null) {
                 return null;
             }
             if (entries.getCount() == 0) {
                 index[idx] = null;
+            } else if (entries.getCount() == 1) {
+                // inline single remaining entry
+                ChildNodeEntry remaining = entries.getEntries(0, 1).next();
+                index[idx] = new NodeInfo(remaining.getName(), remaining.getId());
             } else {
-                bi.size--;
                 // todo store bucket and update index entry with new bucket id (content hash)
-                //bi.id = <content hash of bucket>;
+                //bucketId = <content hash of bucket>;
+                String bucketId = "";
+                index[idx] = new BucketInfo(bucketId, entries.getCount());
             }
             count--;
             return existing;
@@ -287,15 +306,37 @@ public class ChildNodeEntriesTree implem
     }
 
     protected static class BucketInfo implements IndexEntry {
+
         // bucket id
-        String id;
+        private final String id;
 
         // number of bucket entries
-        int size;
+        private final int size;
+
+        protected BucketInfo(String id, int size) {
+            this.id = id;
+            this.size = size;
+        }
+
+        public String getId() {
+            return id;
+        }
 
         public int getSize() {
             return size;
         }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj instanceof BucketInfo) {
+                BucketInfo other = (BucketInfo) obj;
+                return (size == other.size && id == null ? other.id == null : id.equals(other.id));
+            }
+            return false;
+        }
     }
 
     protected static class NodeInfo extends ChildNodeEntry implements IndexEntry {
@@ -307,5 +348,10 @@ public class ChildNodeEntriesTree implem
         public int getSize() {
             return 1;
         }
+
+        @Override
+        public boolean equals(Object obj) {
+            return super.equals(obj);
+        }
     }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntry.java?rev=1235368&r1=1235367&r2=1235368&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntry.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntry.java
Tue Jan 24 17:34:11 2012
@@ -17,18 +17,18 @@
 package org.apache.jackrabbit.mk.model;
 
 /**
- * 
+ *
  */
 public class ChildNodeEntry {
-    
+
     private final String name;
     private final String id;
-    
+
     public ChildNodeEntry(String name, String id) {
         this.name = name;
         this.id = id;
     }
-    
+
     public String getName() {
         return name;
     }
@@ -36,4 +36,17 @@ public class ChildNodeEntry {
     public String getId() {
         return id;
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof ChildNodeEntry) {
+            ChildNodeEntry other = (ChildNodeEntry) obj;
+            return (name == null ? other.name == null : name.equals(other.name)
+                    && id == null ? other.id == null : id.equals(other.id));
+        }
+        return false;
+    }
 }



Mime
View raw message